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: EASY

Solutions:
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 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])


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


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])


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su
n = inin()
arr = inar()
prev = arr[0]
ss = set()
for i in arr[1:n]:
	ss.add(i - prev)
	prev = i
if len(ss) == 1:
	print(arr[n - 1] + list(ss)[0])
else:
	print(arr[-1])


n = int(input())
a = list(map(int, input().split()))
if n == 2:
	print(a[1] + a[1] - a[0])
else:
	c = a[1] - a[0]
	z = 0
	for i in range(1, n - 1):
		d = a[i + 1] - a[i]
		if d == c:
			continue
		else:
			z = 1
			break
	if z == 0:
		print(a[n - 1] + a[n - 2] - a[n - 3])
	else:
		print(a[n - 1])


n = int(input())
l = list(map(int, input().split()))
a = l[1] - l[0]
c = 0
for i in range(2, n):
	if l[i] - l[i - 1] != a:
		print(l[-1])
		c = c + 1
		break
if c == 0:
	print(l[-1] + a)


n = int(input())
l = list(map(int, input().split()))
d = l[1] - l[0]
i = 1
while i + 1 < n and l[i + 1] - l[i] == d:
	i += 1
if i + 1 != n:
	print(l[n - 1])
else:
	print(l[n - 1] + d)


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


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

def g(n, a):
	count = 0
	x = 0
	for i in range(n - 1):
		if i != 0 and a[i + 1] - a[i] != x:
			return a[-1]
		x = a[i + 1] - a[i]
	return a[-1] + x
print(g(n, a))


n = int(input())
s = [int(i) for i in input().split()]
c = True
cnt = s[1] - s[0]
for i in range(n - 1):
	if s[i + 1] - s[i] != cnt:
		c = False
		break
if c:
	print(s[-1] + cnt)
else:
	print(s[-1])


n = int(input())
T = list(map(int, input().split()))
print(T[-1] if len({T[i + 1] - T[i] for i in range(n - 1)}) > 1 else 2 * T[-1] - T[-2])


n = int(input())
w = [int(x) for x in input().split()]
p = 0
d = w[1] - w[0]
f = True
for i in range(n - 1):
	if w[i + 1] - w[i] != d:
		f = False
if f:
	p = w[n - 1] + d
else:
	p = w[n - 1]
print(p)


n = int(input())
t = list(map(int, input().split()))
last = 0
flag = False
for i in range(1, n):
	temp = t[i] - t[i - 1]
	if temp != last and i != 1:
		flag = True
	last = temp
if flag:
	print(t[-1])
else:
	print(t[-1] + last)


n = int(input())
a = list(map(int, input().split()))
diff = set()
pre = a[0]
for i in range(1, n):
	diff.add(a[i] - pre)
	pre = a[i]
if len(diff) == 1:
	q = diff.pop()
	print(a[-1] + q)
else:
	print(a[-1])


n = int(input())
k = list(map(int, input().split()))
flag = 1
if n == 1:
	print(k[0])
else:
	con = k[1] - k[0]
	for i in range(1, n):
		if k[i] - k[i - 1] != con:
			flag = 0
			break
	if flag == 1:
		print(k[-1] + con)
	else:
		print(k[-1])


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


def isAp(a):
	d = a[1] - a[0]
	for i in range(1, len(a) - 1):
		if d != a[i + 1] - a[i]:
			return 0
	return d
n = int(input())
a = [int(i) for i in input().split(' ')]
print(a[-1] + isAp(a))


n = int(input())
t = [int(i) for i in input().split()]
d = t[1] - t[0]
for i in range(n - 1):
	if d != t[i + 1] - t[i]:
		print(t[n - 1])
		break
	elif i == n - 2:
		print(t[n - 1] + d)


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


n = int(input())
a = [int(i) for i in input().split()]
k = a[1] - a[0]
if n == 2:
	print(a[1] + k)
else:
	flag = 0
	for i in range(2, n):
		if a[i] == a[i - 1] + k:
			flag = 0
		else:
			flag = 1
			break
	if flag == 0:
		print(a[n - 1] + k)
	else:
		print(a[n - 1])


import sys
import math
import bisect
import itertools
import random
import re

def is_arithmetic_progression(A):
	n = len(A)
	for i in range(2, n):
		if A[i] != 2 * A[i - 1] - A[i - 2]:
			return False
	return True

def main():
	n = int(input())
	A = list(map(int, input().split()))
	if is_arithmetic_progression(A):
		print(A[-1] * 2 - A[-2])
	else:
		print(A[-1])
main()


n = int(input())
llist = []
llist = list(map(int, input().split()))
c = 0
d = 0
dd = llist[1] - llist[0]
for i in range(n - 1):
	if llist[i + 1] - llist[i] == dd:
		c += 1
	if llist[i + 1] == llist[0]:
		d += 1
if d == n - 1:
	print(llist[0])
elif c == n - 1:
	print(llist[n - 1] + llist[1] - llist[0])
else:
	print(llist[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])


import math
n = int(input())
t = list(map(int, input().split()))
dt = t[1] - t[0]
flag = True
for i in range(2, n):
	if t[i] - t[i - 1] != dt:
		flag = False
		break
if flag:
	print(t[-1] + dt)
else:
	print(t[-1])


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)


n = int(input())
l = list(map(int, input().split()))
t = []
for i in range(1, n):
	t += [l[i] - l[i - 1]]
if len(set(t)) == 1:
	print(l[n - 1] + (l[1] - l[0]))
else:
	print(l[-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())
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])


n = int(input())
days = list(map(int, input().split()))
offset = days[1] - days[0]
last_day = days[n - 1]
for i in range(1, n - 1):
	if offset != days[i + 1] - days[i]:
		break
else:
	last_day += offset
print(last_day)


def weather(a, n):
	d = a[1] - a[0]
	t = 1
	if n == 2:
		return a[1] + d
	else:
		for i in range(1, n - 1):
			if a[i + 1] - a[i] == d:
				continue
			else:
				t = 0
				break
		if t == 0:
			return a[-1]
		else:
			return a[-1] + d
n = int(input())
a = list(map(int, input().split()))
print(weather(a, n))


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


import sys
n = int(input())
arr = list(input().split())
temp = int(arr[0]) - int(arr[1])
for i in range(1, n - 1):
	if int(arr[i]) - int(arr[i + 1]) != temp:
		print(arr[n - 1])
		sys.exit()
print(int(arr[n - 1]) - temp)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_days = int(input())
temps = read_ints()
avg_days = [b - a for (a, b) in zip(temps, temps[1:])]
if len(set(avg_days)) == 1:
	print(temps[-1] + avg_days[0])
else:
	print(temps[-1])


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


n = int(input())
arr = list(map(int, input().split()))
d = arr[1] - arr[0]
i = 1
while i < len(arr):
	if arr[i] - arr[i - 1] != d:
		print(arr.pop())
		break
	i += 1
else:
	print(arr.pop() + d)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = inp()
l = li()
diff = l[1] - l[0]
f = 1
for i in range(2, n):
	if l[i] - l[i - 1] != diff:
		f = 0
		break
if f:
	pr(l[-1] + diff)
else:
	pr(l[-1])


n = int(input())
arr = [int(x) for x in input().split()]
d = arr[0] - arr[1]
ans = arr[-1]
for i in range(2, n):
	diff = arr[i - 1] - arr[i]
	if diff != d:
		break
else:
	ans = arr[-1] - d
print(ans)


n = int(input())
temp = list(map(int, input().split()))
i = 1
d = temp[1] - temp[0]
ap = 0
while i < len(temp) - 1:
	if temp[i + 1] - temp[i] != d:
		ap = 1
		break
	i = i + 1
if ap == 1:
	print(temp[-1])
else:
	print(temp[-1] + d)


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())
sp = list(map(int, input().split()))
d = sp[1] - sp[0]
for i in range(n - 1):
	if d != sp[i + 1] - sp[i]:
		print(sp[n - 1])
		break
else:
	print(sp[n - 1] + d)


n = int(input())
weather = input().split()
for i in range(n):
	weather[i] = int(weather[i])

def arithmetic(sequence):
	a = sequence[1] - sequence[0]
	sequence.append('e')
	for i in range(len(sequence)):
		if sequence[i + 1] - sequence[i] == a:
			if sequence[i + 2] == 'e':
				return sequence[i + 1] + a
		else:
			return sequence[len(sequence) - 2]
print(arithmetic(weather))


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


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().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())
nums = [int(j) for j in input().split()]
diff = nums[1] - nums[0]
check = True
for j in range(2, n):
	if nums[j] - nums[j - 1] != diff:
		check = False
		break
if check:
	print(nums[n - 1] + diff)
else:
	print(nums[n - 1])


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])


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
d = a[1] - a[0]
check = 1
for i in range(2, n):
	if a[i] - a[i - 1] != d:
		check = 0
		break
if check == 1:
	print(a[n - 1] + d)
else:
	print(a[n - 1])


input()
(*a,) = map(int, input().split())
(b, c) = a[-2:]
print((2 * c - b, c)[any((i - j != b - c for (i, j) in zip(a, a[1:])))])


n = int(input())
x = list(map(int, input().split(' ')))
sum = x[1] - x[0]
for i in range(2, n):
	if x[i] - x[i - 1] == sum:
		continue
	else:
		print(x[n - 1])
		exit()
print(x[n - 1] + sum)


(f, n, l) = (0, int(input()), list(map(int, input().split())))
d = l[1] - l[0]
for x in range(1, n - 1):
	if l[x + 1] - l[x] != d:
		f = 1
print([l[-1] + d, l[-1]][f == 1])


n = int(input())
args = input().split(' ')
targs = []
s2 = 0
for arg in args:
	targs.append(int(arg))
	s2 = s2 + int(arg)
s1 = (targs[0] + targs[n - 1]) * n / 2
d = targs[1] - targs[0]
k = 0
for i in range(0, len(targs) - 1):
	if targs[i] + d != targs[i + 1]:
		k = k + 1
if s1 == s2 and k == 0:
	d = targs[1] - targs[0]
	print(targs[n - 1] + d)
else:
	print(targs[n - 1])


def main():
	n = int(input())
	temps = [int(_) for _ in input().split()]
	is_arithmetic_progression = True
	first_distance = temps[1] - temps[0]
	for i in range(1, n - 1):
		if temps[i + 1] - temps[i] != first_distance:
			is_arithmetic_progression = False
			break
	result = temps[n - 1] + first_distance if is_arithmetic_progression else temps[n - 1]
	print(result)
main()


def solve():
	dias = int(input())
	numbers = list([int(x) for x in input().split(' ')])
	diferencia = numbers[1] - numbers[0]
	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


n = int(input())
t = [int(i) for i in input().split(' ')]
diff = t[1] - t[0]
alert = 0
for i in range(len(t) - 1):
	if t[i + 1] - t[i] != diff:
		alert = 1
		break
if alert == 0:
	print(t[-1] + diff)
else:
	print(t[-1])


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())
l = list(map(int, input().split()))
d = []
for i in range(1, n):
	d.append(l[i] - l[i - 1])
s = len(set(d))
if s == 1:
	print(l[n - 1] + d[0])
else:
	print(l[n - 1])


from collections import Counter
n = int(input())
arr = list(map(lambda x: int(x), input().split()))
(flag, index, in_flag) = (0, 0, 0)
if len(arr) == 1:
	res = arr[-1]
elif len(arr) == 2:
	res = arr[1] + arr[1] - arr[0]
else:
	in_flag = 1
	for (ind, val) in enumerate(arr):
		if ind == len(arr) - 1:
			break
		if ind == 0:
			d = arr[ind + 1] - val
		elif arr[ind + 1] - arr[ind] != d:
			flag = 1
			break
if in_flag:
	if flag:
		res = arr[-1]
	else:
		res = d + arr[-1]
print(res)


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


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()))
if n == 1:
	print(a[0])
elif n == 2:
	print(a[1] + (a[1] - a[0]))
else:
	f = True
	d = a[1] - a[0]
	for i in range(1, n):
		if a[i] - a[i - 1] != d:
			f = False
	if f:
		print(a[-1] + d)
	else:
		print(a[-1])


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])
		exit(0)
print(ar[len(ar) - 1] + kek)


def WeatherTomorrow(n, seq):
	i = 1
	firstDiff = seq[1] - seq[0]
	while i < n - 1:
		diff = seq[i + 1] - seq[i]
		if diff != firstDiff:
			return seq[n - 1]
		i += 1
	return seq[n - 1] + firstDiff
n = int(input())
seq = [int(x) for x in input().split()]
print(WeatherTomorrow(n, seq))


n = int(input())
l = list(map(int, input().split()))
p = []
if n == 2:
	print(l[1] + (l[1] - l[0]))
else:
	for i in range(1, len(l)):
		p.append(l[i] - l[i - 1])
	setp = set(p)
	lsetp = list(setp)
	if len(setp) == 1:
		print(l[-1] + lsetp[0])
	else:
		print(l[-1])


import math
I = lambda : int(input())
tup = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))

def solve():
	n = I()
	arr = lst()
	d = arr[1] - arr[0]
	flag = True
	for i in range(n - 1):
		if arr[i + 1] - arr[i] == d:
			pass
		else:
			flag = False
			break
	if flag:
		print(arr[n - 1] + d)
	else:
		print(arr[n - 1])
t = 1
while t:
	solve()
	t -= 1


import math
n = int(input())
a = list(map(int, input().split()))
d = a[1] - a[0]
for i in range(1, n):
	if a[i] - a[i - 1] != d:
		d = 0
		break
print(a[n - 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())
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())
t = list(map(int, input().split()))
d = t[1] - t[0]
for i in range(2, n):
	if t[i] - t[i - 1] != d:
		print(t[-1])
		exit()
print(t[-1] + d)


def checkAP(s):
	d = s[1] - s[0]
	for i in range(len(s) - 1):
		if s[i + 1] - s[i] != d:
			return False
			break
	return True
a = int(input())
s = list(map(int, input().strip().split()))
if a == 1:
	print(s[0])
elif a == 2:
	print(s[1] + s[1] - s[0])
elif checkAP(s) == True:
	print(s[0] + a * (s[1] - s[0]))
else:
	print(s[a - 1])


n = int(input())
a = []
str = input()
a = str.split(' ')
for i in range(0, n):
	a[i] = int(a[i])
ch = True
raz = a[1] - a[0]
for i in range(0, n - 1):
	if a[i] + raz != a[i + 1]:
		ch = False
	if not ch:
		break
res = ''
if ch:
	res = a[n - 1] + raz
else:
	res = a[n - 1]
print(res)


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


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a) - 1):
	t = a[i + 1] - a[i]
	b.append(t)
b1 = set(b)
if len(b1) == 1:
	ans = a[0] + n * b[0]
	print(ans)
else:
	print(a[n - 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())
l = list(map(int, input().split()))
diff = l[1] - l[0]
flag = 0
for i in range(2, n):
	if l[i] - l[i - 1] == diff:
		pass
	else:
		flag = 1
		break
if flag == 0:
	print(l[-1] + diff)
else:
	print(l[-1])


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


def checkArithmetic(seq, diff, length):
	isSeq = True
	i = 1
	while i + 1 < length:
		r = seq[i + 1] - seq[i]
		if r != diff:
			isSeq = False
			break
		i += 1
	return isSeq
size = int(input())
sequence = list(map(int, input().split()))
currDiff = sequence[1] - sequence[0]
print(currDiff + sequence[-1] if checkArithmetic(sequence, currDiff, size) else sequence[-1])


n = int(input())
a = list(map(int, input().split()))
rs = a[1] - a[0]
for i in range(n - 1):
	if a[i + 1] - a[i] != rs:
		print(a[n - 1])
		exit()
print(a[n - 1] + rs)


Input = lambda : map(int, input().split())
n = int(input())
Weather = list(Input())
Progression = Weather[0] - Weather[1]
for i in range(2, n):
	if Weather[i - 1] - Weather[i] != Progression:
		Progression = None
		break
if Progression == None:
	print(Weather[-1])
else:
	print(Weather[-1] - Progression)


def checkAP(numList):
	d = numList[1] - numList[0]
	for i in range(1, len(numList)):
		if numList[i] - numList[i - 1] != d:
			return False
	return True
while True:
	try:
		n = input()
		numList = input()
		numList = numList.split()
		numList = [int(x) for x in numList]
		if checkAP(numList):
			print(2 * numList[-1] - numList[-2])
		else:
			print(numList[-1])
	except EOFError:
		break


n = int(input())
ai = list(map(int, input().split()))
lst = []
for (x, y) in zip(ai[0:], ai[1:]):
	lst.append(y - x)
if len(set(lst)) == 1:
	print(ai[-1] + lst[0])
else:
	print(ai[-1])


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
n = get_int()
lst = get_int_list()
d = lst[1] - lst[0]
flag = True
for i in range(1, n):
	if lst[i] - lst[i - 1] != d:
		flag = False
		break
if flag:
	print(lst[-1] + d)
else:
	print(lst[-1])


n = int(input())
li = list(map(int, input().split()))
if n > 2:
	for i in range(2, n):
		if li[i] - li[i - 1] != li[i - 1] - li[i - 2]:
			ans = li[-1]
			break
		else:
			ans = 2 * li[-1] - li[-2]
else:
	ans = 2 * li[1] - li[0]
print(ans)


days = int(input())
T = list(map(int, input().split()))
if days == 1:
	print(T[-1])
else:
	gaps = T[1] - T[0]
	for i in range(1, days):
		if T[i] - T[i - 1] != gaps:
			gaps = 0
			break
	print(T[-1] + gaps)


input()
t = list(map(int, input().split()))
d = t[1] - t[0]
print(t[-1] + d * all((u - v == d for (u, v) in zip(t[1:], t))))


a = int(input())
t = list(map(int, input().split()))
f = []
for k in range(1, a):
	f.append(t[k] - t[k - 1])
if len(set(f)) == 1:
	print(t[-1] + f[0])
else:
	print(t[-1])


cnt = lambda s, i: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
n = ii()
l = il()
d = l[1] - l[0]
for i in range(1, n):
	if l[i] - l[i - 1] != d:
		exit(print(l[-1]))
print(l[-1] + d)


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


def f(l):
	n = len(l)
	dl = [l[i + 1] - l[i] for i in range(n - 1)]
	dl.sort()
	return l[-1] if dl[0] != dl[-1] else l[-1] + dl[0]
_ = input()
l = list(map(int, input().split()))
print(f(l))