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.


-----Input-----

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.


-----Output-----

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.


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

Difficulty: competition

Starter code:

Solutions:
count = int(input())
array = list(map(int, input().split()))

diff = array[0] - array[1]
holds = True

for index in range(1, len(array)-1):
    if array[index] - array[index+1] != diff:
        holds = False

if holds:
    print(array[-1] - (array[-2] - array[-1]))
else:
    print(array[-1])

        


n = int(input())
l = [int(x) for x in input().split()]

d = l[1] - l[0]
for i in range(2, n):
	if l[i] != l[i - 1] + d:
		d = 0
print(l[-1] + d)

n = int(input())
a = list(map(int,input().split()))
s = a[1] - a[0]
f = 0
for i in range(len(a[:-1])):
    if a[i+1] - a[i] != s:
        f = 1
if f==1:
    print(a[-1])
else:
    print(a[-1] + a[-1] - a[-2])


n=int(input())
t=list(map(int,input().split(' ')))
s=set([])
for i in range(1,n):
    x=t[i]-t[i-1]
    s.add(x)
if len(s)==1:
    print(t[-1]+x)
else:
    print(t[-1])

import sys
n=int(input())
t=list(map(int,input().split()))
for i in range(1,len(t)-1):
    if t[i]-t[i-1]!=t[i+1]-t[i]:
        print(t[len(t)-1])
        return
print(t[len(t)-1]+(t[1]-t[0]))


n = int(input())
a = list(map(int, input().split()))
k = a[1] - a[0]
tr = True
for i in range(2,n):
    if k != a[i] - a[i-1]:
        tr = False
if tr:
    print(a[-1] + k)
else:
    print(a[-1])

n=int(input())
x=input().split()
if(x.count(x[0])==n):print(x[n-1])
else:
    y=[]
    d=int(x[1])-int(x[0])
    for i in range(n-1):
        y.append(int(x[i+1])-int(x[i]))
    if(y.count(d)==n-1):print(int(x[-1])+d)
    else:
        print(x[-1])

input()
a = list(map(int, input().split()))
diffs = [a[n] - a[n - 1] for n in range(1, len(a))]

print((a[-1] + diffs[0]) if len(set(diffs)) == 1 else a[-1])


n=int(input())
x=input().split()
if(x.count(x[0])==n):print(x[n-1])
else:
    y=[]
    d=int(x[1])-int(x[0])
    for i in range(n-1):
        y.append(int(x[i+1])-int(x[i]))
    if(y.count(d)==n-1):print(int(x[-1])+d)
    else:
        print(x[-1])

n = int(input())
u = 0
arr = list(map(int,input().split()))
d = arr[1] - arr[0]
for i in range(n-1):
    if arr[i] + d != arr[i+1]:
        print(arr[n-1])
        u+=1
        break
if u == 0: 
    print(arr[n-1]+d)


n = int(input())
a = list(map(int, input().split()))
d = a[1] - a[0]
t = 1

i = 2
while(i < len(a)):
    cur = a[i] - a[i - 1]
    if(cur != d):
        t = 0
        break
    i = i + 1

print(a[-1] + t * d)

n = int(input())

a = list(map(int,input().strip().split(' ')))

d = a[1] - a[0]
fl = True
for i in range(2,n):
	cd = a[i] - a[i-1]
	if d != cd:
		fl = False
		break
	
if fl:
	print(a[n-1] + d)
else:
	print(a[n-1])


n = int(input().strip())
vals = [int(x) for x in (input().strip().split())]
term = vals[1]
d = vals[1]-vals[0]
ap = True
for x in range(2,n):
	next_term = vals[x]
	if (next_term-term != d):
		ap = False
	term = next_term

if ap:
	print(term+d)
else:
	print(term)

n=int(input());
l=list(map(int,input().split()));
for i in range(1,n):
    if(not l[i]-l[i-1]==l[1]-l[0]):
        print((l[n-1]));
        break;
else:
        print((l[n-1]+l[1]-l[0]));

              
    


n = int(input());
A = list(map(int, input().split()));
w = 1;
res = 0;
f = 0;
for q in range(0, n - 1):
    if f != 0 and A[q + 1] - A[q] != res:
        w = 0;
        break;
    elif f == 0:
        res = A[q + 1] - A[q];
        f = 1;
if w == 0:
    print(A[len(A) - 1]);
else:
    print(A[len(A) - 1] + res);

def weatom(s=[]):
    n=len(s)
    if(n==1):
        return s[0]
    elif(n==2):
        return (s[1] + (s[1]-s[0]))
    else:
        d=s[1]-s[0]
        for i in range(2,n):
            if((s[i]-s[i-1])==d):
                if(i==n-1):
                    return (s[i] + d)
            else:
                return s[n-1]
           

def main():
    t=input()
    t=int(t)
    s=[int(x) for x in input().strip().split()]
    print(weatom(s))
    
def __starting_point():
    main()
__starting_point()

n = int(input())
arr =list(map(int,input().split()))

m = arr[0]-arr[1]
x = True
for i in range(1,n):
    if (arr[i-1]-arr[i]==m):
        continue
    else :
        x = False
if x == True: print(arr[n-1]-m)
else : print(arr[n-1])

a=int(input())
b=list(map(int,input().split()))
n=0
x=0
if b[0]>b[1]:
	x=b[0]-b[1]
	for i in range(len(b)-1):
		if b[i]-b[i+1]!=x:
			n=1
	if n==0:
		print(b[-1]-x)
	else:
		print(b[-1])
else:
	x=b[1]-b[0]
	for i in range(len(b)-1):
		if b[i+1]-b[i]!=x:
			n=1
	if n==0:
		print(b[-1]+x)
	else:
		print(b[-1])


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())

l = list(map(int, input().split()))
d = l[1] - l[0]
arth = True
for i in range(n - 1):
    if l[i + 1] - l[i] != d:
        arth = False

if arth == True:
    print(l[n - 1] + d)
else:
    print(l[n - 1])


import math

n = int(input())
a = list(map(int, input().split()))
d = a[1] - a[0]
ok = True
for i in range(1, n):
	ok &= d == a[i] - a[i-1]
print(a[n-1]+d if ok else a[n-1])






n=int(input())
t=list(map(int,input().split(' ')))
s=set([])
for i in range(1,n):
    x=t[i]-t[i-1]
    s.add(x)
if len(s)==1:
    print(t[-1]+x)
else:
    print(t[-1])

n = int(input())
a = list(map(int, input().split()))
diff = abs(a[0]-a[1])
flag = True
for i in range(2, n):
    if abs(a[i]-a[i-1]) != diff:
        flag = False
        break
if flag:
    if a[n-2] >= a[n-1]:
        print(a[n-1] - diff)
    else:
        print(a[n-1] + diff)
else:
    print(a[n-1])



n = int(input())
arr = list(map(int, input().split()))
if (len({arr[i + 1] - arr[i] for i in range(n - 1)}) == 1):
    print(arr[-1] + (arr[1] - arr[0]))
else:
    print(arr[-1])

def solve():
	dias = int(input())
	numbers = list([int(x) for x in input().split(' ')])
	diferencia = numbers[1] - numbers[0]
#	print('diferencia', diferencia)
	for i in range(len(numbers) - 1 ):
		if numbers[i+1]-numbers[i] == diferencia:
			continue
		else:
			print(numbers[len(numbers)-1])
			return
	print(numbers[len(numbers)-1] + diferencia)




while True:
	try:
		solve()
	except:
		break


def ria():
  return [int(i) for i in input().split()]
ar=ria()
ar=ria()
kek=(ar[1]-ar[0])

for i in range(1,len(ar)):
  if ar[i]-ar[i-1]!=(ar[1]-ar[0]):
    print(ar[len(ar)-1])
    return

print(ar[len(ar)-1]+kek)