Codeforces847M Weather Tomorrow

45 篇文章 0 订阅
40 篇文章 0 订阅

标签:模拟,计算几何

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;
}


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值