题库练习 Weather Tomorrow
← 上一题 下一题 →

A11087 | Weather Tomorrow

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 $t_{1},t_{2},...,t_{n}$ $(-1000<=t_{i}<=1000)$ — where $t_{i}$ 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
C++ 编辑器
输入
输出