标签:模拟,计算几何

Vasya cameup with his own weather forecasting method. He knows the information about theaverage air temperature for each of the last n days. Assume that the average air temperaturefor each day is integral.

Vasyabelieves that if the average temperatures over the last n days form an arithmetic progression, wherethe first term equals to the average temperature on the first day, the secondterm equals to the average temperature on the second day and so on, then theaverage temperature of the next (n + 1)-th daywill be equal to the next term of the arithmetic progression. Otherwise,according to Vasya's method, the temperature of the (n + 1)-th day will be equal to the temperature ofthe n-th day.

Your taskis to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.

Input

The firstline contains a single integer n (2 ≤ n ≤ 100) — the number ofdays for which the average air temperature is known.

The secondline contains a sequence of integers t1, t2, ..., tn ( - 1000 ≤ ti ≤ 1000) —where ti is theaverage temperature in the i-th day.

Output

Print theaverage air temperature in the (n + 1)-th day,which Vasya predicts according to his method. Note that the absolute value ofthe predicted temperature can exceed 1000.

Example

Input

5
10 5 0 -5 -10

Output

-15

Input

4
1 1 1 1

Output

1

Input

3
5 1 -5

Output

-5

Input

2
900 1000

Output

1100

Note

In thefirst example the sequence of the average temperatures is an arithmeticprogression where the first term is 10 and eachfollowing terms decreases by 5. So thepredicted average temperature for the sixth day is  - 10 - 5 =  - 15.

In thesecond example the sequence of the average temperatures is an arithmeticprogression where the first term is 1 and eachfollowing terms equals to the previous one. So the predicted averagetemperature in the fifth day is 1.

In thethird example the average temperatures do not form an arithmetic progression,so the average temperature of the fourth day equals to the temperature of thethird day and equals to  - 5.

In thefourth example the sequence of the average temperatures is an arithmeticprogression where the first term is 900 and eachthe following terms increase by100. Sopredicted average temperature in the third day is 1000 + 100 = 1100.

计算几何的入门题,初二数学的难度,判断这些点是否在同一条直线上

Code

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;int n,d,flag,a[305];int main()
{cin>>n;rep(i,1,n)scanf("%d",&a[i]);d=a[2]-a[1];rep(i,2,n-1)if(a[i+1]-a[i]!=d)flag=1;if(flag==0)cout<<a[n]+d;else cout<<a[n];return 0;
}

Codeforces847M Weather Tomorrow相关推荐

  1. weather_在Weather App中使用Android Location API –搜索城市

    weather 在这篇文章中,我想描述如何使用openweathermap搜索城市以获取天气状况. 我们可以通过两种方式查找城市: 使用名称模式 使用地理坐标(Android Location API ...

  2. Indicator Weather 13.06 发布 增加 Kelvin 支持

    Indicator Weather 是一个天气工具,可以在桌面上查看到天气信息.新版中增加了 Kelvin 温度单位.可以在 Indicator Weather appindicator-->P ...

  3. [Alfred]为Baidu Weather Workflow更新图标

    Alfred workflow:百度天气,修改更新图标显示: 下载:https://github.com/BobSte/weather-workflow 原始代码是php脚本,为其增加了一个取图片的函 ...

  4. wether.html5.qq.com,weather.html

    weather if(!location.search){location.search = '?province=重庆市&city=重庆市&county=渝北区';} functio ...

  5. 使用Google Weather API查询天气预报

    Google Weather API 只支持美国地区使用邮政编码进行查询,例如: http://www.google.com/ig/api?hl=zh-cn&weather=94043 (94 ...

  6. 234C. Weather

    C. Weather:题目 为什么直接交代码不行啊,非要加两句话,有没有大佬说说? #include <bits/stdc++.h> using namespace std; // typ ...

  7. php 抓取天气情况 www.weather.com.cn

    <?phpprint_r(getweather(101120501));/*** Server 天气情况获取函数* @param unknown $city*/ function getweat ...

  8. python 爬取http://www.weather.com.cn/中国主要城市周边城市的天气

    编程实现自动爬取中国气象网站 http://www.weather.com.cn/气象数据,将中国主要城市 (北京 .上海 .广州 .杭州 .武汉 .南京 .深圳 .苏州 .厦门 .合肥 和成都  ) ...

  9. Autonomous Driving in Adverse Weather Conditions: A Survey - 恶劣天气条件下的自动驾驶:一项调查 (arXiv 2021)

    Autonomous Driving in Adverse Weather Conditions: A Survey - 恶劣天气条件下的自动驾驶:一项调查(arXiv 2021) 摘要 1. 引言 ...

最新文章

  1. python 100题
  2. Java初学者入门经典:面向对象的思维方法(其实同样非常适合C#的初学者)……非原创,作者忘了,非常抱歉...
  3. 基于matlab的回波,基于MATLAB回波信号产生与消除.doc
  4. jetty之嵌入式运行jetty
  5. matplotlib.lines.Line2D
  6. GitHub 的 12 个实用技巧,你 get 了几个?
  7. php怎么写编辑页面,怎样编辑小程序页面内容?
  8. [未完成]scikit-learn一般实例之九:用于随机投影嵌入的Johnson–Lindenstrauss lemma边界...
  9. 手机闹钟软件测试用例,手机app测试用例.docx
  10. 算法复杂度分析中的符号(Θ、Ο、ο、Ω、ω)简介
  11. 笔记本电脑WIFI图标消失解决方案大全,无WIFI图标也能自由连WIFI上网。
  12. 16. Segmentation
  13. rbc系统基于通用服务器构建的,列控核心设 RBC系统介绍.doc
  14. C++使电脑强制关机
  15. 使用_findfirst和_findnext遍历目录
  16. 如何让SQL Server数据库自动备份并压缩
  17. 毕业三年,听到我的年薪只是表弟的月薪,我心态崩了。。。
  18. nginx上传图片大小限制
  19. 万年历C语言年,万年历C语言
  20. CentOS7.5LNMP-Nginx部署

热门文章

  1. 网购车平台易车与汽车之家
  2. android 响铃函数,android – 铃声一遍又一遍地播放(无限循环播放)
  3. matlab 解函数方程,MATLAB程序设计教程(7)—MATLAB解方程与函数极值
  4. 编译时多态、运行时多态
  5. OpenStreetMap初探(七)——渲染和地图瓦片之安装Mapnik
  6. Android注解之从入门到并没有放弃
  7. js复数类的学习和使用
  8. js 中从JSON中取出某个属性的值
  9. 最适合freshman的Java习题集(三)
  10. (译)对利物浦来说杰拉德仍适用吗? is Steven Gerrard good for Liverpool?