Weather Tomorrow

题意翻译

`Vasya`想出了一个他自己的天气预报方法。他知道最近$n$天每天的平均气温。假设每天的平均气温是个整数。 `Vasya`相信这$n$天每天的平均气温构成一个等差数列,在这个数列中,第一项是第一天的平均气温,第二项是第二天的平均气温,以此类推。那么第$n+1$天(也就是明天)的平均气温将是这个数列的第$n+1$项。如果这个数列前$n$项并没有他所想的那样是个等差数列,那么按`Vasya`的算法,第$n+1$天的气温将等于第$n$天的气温。 你需要根据`Vasya`的算法求出明天的平均气温。 输入格式:第一行一个数$n$。第二行$n$个数$t_i$分别表示第$i$天的平均气温。 输出格式:一个数,你的答案。注意温度的绝对值可能超过$1000$。

题目描述

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

说明

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 $ .