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.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
def solve(n, t):
	d = t[1] - t[0]
	for i in range(2, n):
		if t[i - 1] + d != t[i]:
			return t[-1]
	return t[-1] + d
n = int(input())
t = list(map(int, input().split()))
print(solve(n, t))


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)


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
difs = []
for i in range(1, n):
	difs.append(arr[i] - arr[i - 1])
dif_s = set(difs)
if len(dif_s) == 1:
	dif = dif_s.pop()
	print(arr[-1] + dif)
else:
	print(arr[-1])


n = int(input())
ls = list(map(int, input().split()))
diff = ls[1] - ls[0]
flag = False
for z in range(n - 1):
	if ls[z + 1] - ls[z] == diff:
		continue
	else:
		flag = True
if flag:
	print(ls[-1])
else:
	print(ls[-1] + diff)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scanner()
	t = get_list()
	d = t[1] - t[0]
	for i in range(1, n):
		if t[i] - t[i - 1] != d:
			print(t[n - 1])
			return
	print(t[n - 1] + d)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


n = int(input())
nd = list(map(int, input().split()))
dis = False
temp = False
chuoi = True
for i in nd:
	if not dis and (not temp):
		temp = i
	elif not dis:
		dis = i - temp
		temp = i
	elif i - temp != dis:
		chuoi = False
		break
	else:
		temp = i
if chuoi:
	print(nd[len(nd) - 1] + dis)
else:
	print(nd[len(nd) - 1])


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


x = input()
x = int(x)
re_temp = input()
re_temp = re_temp.split(' ')
temp = []
for i in range(0, len(re_temp)):
	temp.append(int(re_temp[i]))
check = temp[1] - temp[0]
conunter = 0
for i in range(1, len(temp) - 1):
	if temp[i + 1] - temp[i] == check:
		conunter = conunter + 1
if conunter == len(temp) - 2:
	print(temp[len(temp) - 1] + check)
else:
	print(temp[len(temp) - 1])


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


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

def f(n, l):
	a = l[0]
	d = l[1] - l[0]
	for i in range(n):
		an = a + i * d
		if l[i] != an:
			return l[-1]
	return a + n * d
print(f(n, l))


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


n = int(input())
a = [*map(int, input().split())]
r = a[1] - a[0]
print(a[-1] + r * all((y - x == r for (x, y) in zip(a, a[1:]))))


n = int(input())
a = list(map(int, input().split()))
ans = a[0] + n * (a[1] - a[0])
t = [0] * (n - 1)
u = 0
for i in range(len(a) - 1):
	t[i] = a[i + 1] - a[i]
val = t[0]
for j in t:
	if j == val:
		continue
	else:
		u = 1
if u == 0:
	print(ans)
else:
	print(a.pop())


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


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


def delta(xs):
	res = xs[1] - xs[0]
	for i in range(2, len(xs)):
		if xs[i] - xs[i - 1] != res:
			return None
	return res
n = int(input())
xs = [int(r) for r in input().split()]
d = delta(xs)
print(xs[-1] if d is None else xs[-1] + d)


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


def pogoda(lst):
	(d, flag) = (lst[1] - lst[0], 1)
	for i in range(len(lst)):
		if i + 1 < len(lst) and lst[i + 1] - lst[i] != d:
			flag = 0
	if flag == 1:
		return d + lst[len(lst) - 1]
	return lst[len(lst) - 1]
n = int(input())
b = [int(j) for j in input().split()]
print(pogoda(b))


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


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


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


import math
n = int(input())
a = [int(i) for i in input().split()]
l = []
for i in range(1, len(a)):
	l.append(abs(a[i - 1] - a[i]))
if len(set(l)) == 1:
	if a[1] >= a[0]:
		print(a[len(a) - 1] + l[0])
	else:
		print(a[len(a) - 1] - l[0])
else:
	print(a[len(a) - 1])


n = int(input())
a = list(map(int, input().split()))
a1 = a[0]
a2 = a[1]
d = a2 - a1
i = 0
ans = 1
while i < n and ans != 0:
	if a1 + i * d == a[i]:
		pass
	else:
		ans = 0
	i += 1
if ans == 0:
	print(a[n - 1])
else:
	print(a[n - 1] + d)


def main_function():
	n = int(input())
	is_arithmetic_progression = True
	a = [int(i) for i in input().split(' ')]
	d = a[1] - a[0]
	for i in range(1, len(a)):
		if a[i] - a[i - 1] != d:
			is_arithmetic_progression = False
			break
	if is_arithmetic_progression:
		print(a[-1] + d)
	else:
		print(a[-1])
main_function()


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


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


def is_ap(l):
	d = l[1] - l[0]
	for i in range(len(l) - 1):
		if l[i + 1] - l[i] != d:
			return False
	return True
n = int(input())
t = list(map(int, input().split(' ')))
flag = 0
d = t[1] - t[0]
if is_ap(t):
	flag = 1
print(t[0] + n * d if flag == 1 else t[n - 1])


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


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))

def take():
	input = open('input.txt', 'r')
	stdout = open('output.txt', 'w')
n = int(z())
arr = zzz()
r = arr[1] - arr[0]
print(arr[-1] + r * all((y - x == r for (x, y) in zip(arr, arr[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())
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())
t = list(map(int, input().strip().split()))
is_arifm = True
d = t[1] - t[0]
for i in range(2, n):
	if t[i] - t[i - 1] != d:
		is_arifm = False
		break
if is_arifm:
	print(t[n - 1] + d)
else:
	print(t[n - 1])


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


a = int(input())
p = [int(i) for i in input().split()]
t = p[1] - p[0]
f = 'YES'
if a == 2:
	print(p[1] + t)
else:
	for i in range(2, a):
		z = p[i] - p[i - 1]
		if z != t:
			f = 'NO'
	if f == 'NO':
		print(p[-1])
	else:
		print(p[-1] + t)


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


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


input()
X = list(map(int, input().split()))
Arith = [X[i] - X[i + 1] for i in range(len(X) - 1)]
print(X[-1] - Arith[0] if Arith.count(Arith[0]) == len(Arith) else X[-1])


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import re

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

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

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

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
n = I()
ls = lint()
f = True
a = ls[0]
b = ls[1]
d = b - a
for i in range(2, n):
	if ls[i] == a + i * d:
		pass
	else:
		f = False
		break
if f == True:
	print(a + n * d)
else:
	print(ls[n - 1])


_ = input()
temperature = list(map(int, input().split()))
differences = list(map(lambda x, y: x - y, temperature[:-1], temperature[1:]))
if len(set(differences)) == 1:
	print(temperature[-1] - differences[0])
else:
	print(temperature[-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))