CF847M.Weather Tomorrow
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n+1) -th day will 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 of the n -th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n+1) -th day.
输入格式
The first line contains a single integer n ( 2<=n<=100 ) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers t1,t2,...,tn (−1000<=ti<=1000) — where ti is the average temperature in the i -th day.
输出格式
Print the average air temperature in the (n+1) -th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000 .
输入输出样例
输入#1
5 10 5 0 -5 -10
输出#1
-15
输入#2
4 1 1 1 1
输出#2
1
输入#3
3 5 1 -5
输出#3
-5
输入#4
2 900 1000
输出#4
1100
说明/提示
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5 . So the predicted average temperature for the sixth day is −10−5=−15 .
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1 .
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to −5 .
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100 . So predicted average temperature in the third day is 1000+100=1100 .