You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers.

You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can:

  add $D$ (only once), i. e. perform $a_i := a_i + D$, or  subtract $D$ (only once), i. e. perform $a_i := a_i - D$, or  leave the value of $a_i$ unchanged. 

It is possible that after an operation the value $a_i$ becomes negative.

Your goal is to choose such minimum non-negative integer $D$ and perform changes in such a way, that all $a_i$ are equal (i.e. $a_1=a_2=\dots=a_n$).

Print the required $D$ or, if it is impossible to choose such value $D$, print -1.

For example, for array $[2, 8]$ the value $D=3$ is minimum possible because you can obtain the array $[5, 5]$ if you will add $D$ to $2$ and subtract $D$ from $8$. And for array $[1, 4, 7, 7]$ the value $D=3$ is also minimum possible. You can add it to $1$ and subtract it from $7$ and obtain the array $[4, 4, 4, 4]$.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of elements in $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — the sequence $a$.


-----Output-----

Print one integer — the minimum non-negative integer value $D$ such that if you add this value to some $a_i$, subtract this value from some $a_i$ and leave some $a_i$ without changes, all obtained values become equal.

If it is impossible to choose such value $D$, print -1.


-----Examples-----
Input
6
1 4 4 7 4 1

Output
3

Input
5
2 2 5 2 5

Output
3

Input
4
1 3 3 7

Output
-1

Input
2
2 8

Output
3

Source: codeforces | Difficulty: EASY
Tags: Mathematics


Solutions:
input()
a = sorted(list(set([int(x) for x in input().split()])))
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(a[1] - a[0])
elif len(a) > 3:
	print(-1)
elif a[2] - a[1] == a[1] - a[0]:
	print(a[2] - a[1])
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
l = list(set(l))
le = len(l)
if le > 3:
	print(-1)
elif le == 3:
	l.sort()
	if l[2] - l[1] == l[1] - l[0]:
		print(l[1] - l[0])
	else:
		print(-1)
elif le == 2:
	if abs(l[-1] - l[0]) % 2 == 0:
		print(abs(l[-1] - l[0]) // 2)
	else:
		print(abs(l[-1] - l[0]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
res = []
for i in range(n - 1):
	res.append(abs(l[i] - l[i + 1]))
temp = list(set(res))
if len(l) == 1:
	print(0)
elif len(l) == 2:
	if abs(l[0] - l[1]) % 2 == 0:
		print(abs(l[0] - l[1]) // 2)
	else:
		print(abs(l[0] - l[1]))
elif len(set(l)) == 1:
	print(0)
elif len(set(l)) == 2:
	temp = list(set(l))
	if abs(temp[0] - temp[1]) % 2 == 0:
		print(abs(temp[0] - temp[1]) // 2)
	else:
		print(abs(temp[0] - temp[1]))
elif len(set(l)) == 3:
	temp = list(set(l))
	temp.sort()
	if temp[0] - temp[1] == temp[1] - temp[2]:
		print(abs(temp[0] - temp[1]))
	else:
		print(-1)
else:
	print(-1)


a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
	c.setdefault(i, 0)
if len(c) == 1:
	print(0)
elif len(c) == 2:
	if abs(list(c.keys())[1] - list(c.keys())[0]) % 2 == 0:
		print(abs(list(c.keys())[1] - list(c.keys())[0]) // 2)
	else:
		print(abs(list(c.keys())[1] - list(c.keys())[0]))
elif len(c) == 3:
	d = list(c.keys())
	d.sort()
	if (d[2] + d[0]) % 2 == 0 and (d[2] + d[0]) // 2 == d[1]:
		print((d[2] - d[0]) // 2)
	else:
		print(-1)
else:
	print(-1)


import sys
n = int(input())
arr = list(map(int, input().split()))
counter = {}
for num in arr:
	counter[num] = 1
keys = sorted(counter.keys())
if len(keys) > 3:
	print(-1)
elif len(keys) == 3:
	if keys[1] - keys[0] == keys[2] - keys[1]:
		print(keys[1] - keys[0])
	else:
		print(-1)
elif len(keys) == 2:
	if (keys[1] - keys[0]) % 2 == 0:
		print(int((keys[1] - keys[0]) // 2))
	else:
		print(keys[1] - keys[0])
else:
	print(0)


n = int(input())
l = [*map(int, input().split())]

def check(x):
	return [abs(e - x) for e in l if e != x]
res = float('inf')
for x in range(1, 101):
	c = check(x)
	if len(set(c)) == 1:
		res = min(res, c[0])
	elif not c:
		res = 0
		break
if res > 100:
	print(-1)
else:
	print(res)


input()
s = set(map(int, input().split()))

def no():
	print(-1)
	exit(0)
n = len(s)
if n > 3:
	no()
elif n == 1:
	print(0)
else:
	a = sorted([x for x in s])
	if n == 2:
		m = a[1] - a[0]
		if m % 2 == 0:
			print(m // 2)
		else:
			print(m)
	elif a[0] + a[2] != a[1] + a[1]:
		no()
	else:
		print(a[1] - a[0])


x = int(input())
y = [int(n) for n in input().split()]
a = min(y)
b = max(y)
if x > 2:
	s = []
	for k in range(x):
		if y[k] != a and y[k] != b:
			s.append(y[k])
	if len(s) != 0:
		if s.count(s[0]) == len(s):
			if a + (b - a) / 2 == s[0]:
				print(int((b - a) / 2))
			else:
				print(-1)
		else:
			print(-1)
	elif (b - a) % 2 == 0:
		print(int((b - a) / 2))
	else:
		print(b - a)
elif x == 2:
	if (b - a) % 2 == 0:
		print(int((b - a) / 2))
	else:
		print(b - a)
else:
	print(0)


n = int(input())
li = set(map(int, input().strip().split()))
nos = list(li)
nos.sort()
if len(nos) > 3:
	print(-1)
elif len(nos) == 1:
	print(0)
elif len(nos) == 2:
	if (nos[1] - nos[0]) % 2 == 0:
		print((nos[1] - nos[0]) // 2)
	else:
		print(nos[1] - nos[0])
else:
	diff_1 = nos[1] - nos[0]
	diff_2 = nos[2] - nos[1]
	if diff_1 == diff_2:
		print(diff_1)
	else:
		print(-1)


n = int(input())
data = [int(x) for x in input().split()]
temp = []
for i in range(n):
	if data[i] not in temp:
		temp.append(data[i])
temp.sort()
if len(temp) == 1:
	print('0')
elif len(temp) == 2:
	if (temp[-1] - temp[0]) % 2 == 0:
		if int((temp[-1] - temp[0]) / 2) > temp[-1] - temp[0]:
			print(temp[-1] - temp[0])
		else:
			print(int((temp[-1] - temp[0]) / 2))
	else:
		print(temp[-1] - temp[0])
elif len(temp) == 3:
	if temp[0] + int(temp[2] - temp[0]) / 2 == temp[1]:
		print(temp[1] - temp[0])
	else:
		print('-1')
else:
	print('-1')


n = int(input())
m = list(map(int, input().split()))
s = set(m)
l = len(s)
if l > 3:
	print(-1)
elif l == 1:
	print(0)
elif l == 2:
	t = max(s) - min(s)
	if t % 2 == 0:
		print(t // 2)
	else:
		print(t)
else:
	c = sum(s)
	a = min(s)
	b = max(s)
	c = c - a - b
	if b - c == c - a:
		print(c - a)
	else:
		print(-1)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
if len(b) == 3:
	b.sort()
	if b[1] - b[0] == b[2] - b[1]:
		print(b[2] - b[1])
		quit()
	print(-1)
if len(b) > 3:
	print(-1)
if len(b) == 1:
	print(0)
if len(b) == 2:
	b.sort()
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])


n = int(input())
arr = [int(i) for i in input().split(' ')]
min = min(arr)
max = max(arr)
if len(set(arr)) == 2:
	if (max - min) % 2 == 0:
		print(int((max - min) / 2))
	else:
		print(max - min)
elif len(set(arr)) == 1:
	print(0)
else:
	d = -1
	if (max - min) % 2 == 0:
		d = int((max - min) / 2)
		for i in range(n):
			if not (arr[i] == min or arr[i] == min + d or arr[i] == max):
				d = -1
				break
	print(d)


n = int(input())
A = list(map(int, input().split()))
A = set(A)
A = list(A)
A.sort()
if len(A) == 1:
	print('0')
elif len(A) == 2:
	if (A[1] - A[0]) % 2 == 0:
		print((A[1] - A[0]) // 2)
	else:
		print(A[1] - A[0])
elif len(A) == 3:
	if A[2] - A[1] == A[1] - A[0]:
		print(A[1] - A[0])
	else:
		print('-1')
else:
	print('-1')


n = int(input())
li = sorted(list(set([int(i) for i in input().split()])))
if len(li) == 1:
	print(0)
elif len(li) == 2:
	a = li[1] - li[0]
	if a % 2 == 0:
		print(a // 2)
	else:
		print(a)
elif len(li) == 3:
	if li[2] - li[1] == li[1] - li[0]:
		print(li[1] - li[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
s = set(map(int, input().split()))
if len(s) > 3:
	print(-1)
elif len(s) == 1:
	print(0)
elif len(s) == 2:
	(a, b) = s
	if abs(a - b) % 2 == 0:
		print(abs(a - b) // 2)
	else:
		print(abs(a - b))
else:
	(a, b, c) = sorted(s)
	if b - a == c - b:
		print(b - a)
	else:
		print(-1)


sizes = int(input())
number = list(map(int, list(input().split())))
l = []
for i in range(sizes):
	l.append(number[i])
li = sorted(list(set(l)))
ma = max(li)
mi = min(li)
diff = int((ma - mi) / 2)
if len(li) == 1:
	print(0)
elif len(li) == 2 and (ma - mi) % 2 != 0:
	print(ma - mi)
elif len(li) == 2 and (ma - mi) % 2 == 0:
	print(diff)
elif len(li) == 3 and ma - diff == mi + diff == li[1]:
	print(diff)
else:
	print(-1)


n = int(input())
s = sorted(list(set(list(map(int, input().split())))))
if len(s) > 3:
	print(-1)
elif len(s) == 3:
	if s[2] - s[1] == s[1] - s[0]:
		print(s[2] - s[1])
	else:
		print(-1)
elif len(s) == 2:
	if (s[1] - s[0]) % 2 == 0:
		print(int((s[1] - s[0]) / 2))
	else:
		print(s[1] - s[0])
else:
	print(0)


woice = int(input())
stats = list(map(int, input().split()))
stats = list(set(stats))
stats.sort()
if len(stats) == 1:
	print(0)
elif len(stats) > 3:
	print(int(-1))
elif len(stats) == 3:
	if stats[2] - stats[1] == stats[1] - stats[0]:
		print(stats[1] - stats[0])
	else:
		print(int(-1))
elif len(stats) == 2:
	if (stats[1] - stats[0]) % 2 == 0:
		print((stats[1] - stats[0]) // 2)
	else:
		print(stats[1] - stats[0])


blank = input()
List = list(set(map(int, input().split())))
List.sort()
if len(List) == 1:
	print(int(0))
elif len(List) > 3:
	print(int(-1))
else:
	An = list(set((abs(j - i) for (i, j) in zip(List[:-1], List[1:]))))
	if len(List) == 2:
		if An[0] % 2 == 0:
			print(int(An[0] / 2))
		else:
			print(int(An[0]))
	elif len(An) != 1:
		print('-1')
	else:
		print(int(An[0]))


num = int(input())
a = list(map(int, input().split()))
a.sort()
flag = 0
for i in range(0, 1001):
	val = a[0] + i
	flag = 0
	for j in range(1, num):
		if a[j] + i == val or a[j] == val or a[j] - i == val:
			continue
		flag = 1
		break
	if flag == 0:
		print(i)
		break
if flag == 1:
	print(-1)


n = int(input())
L = [int(x) for x in input().split()]
D = {}
for i in L:
	if i not in D:
		D[i] = 0
if len(D) == 1:
	print(0)
elif len(D) == 2:
	(a, b) = sorted(D.keys())
	if (b - a) % 2 == 0:
		print((b - a) // 2)
	else:
		print(b - a)
elif len(D) == 3:
	(a, b, c) = sorted(D.keys())
	if c - b == b - a:
		print(c - b)
	else:
		print(-1)
else:
	print(-1)


num = int(input())
arr = [int(x) for x in input().split()]
mset = set()
for ele in arr:
	mset.add(ele)
l = len(mset)
if l == 1:
	print(0)
elif l > 3:
	print(-1)
elif l == 2:
	mini = min(arr)
	maxi = max(arr)
	print((maxi - mini) // 2 if (maxi - mini) % 2 == 0 else maxi - mini)
elif l == 3:
	temp = []
	for ele in mset:
		temp.append(ele)
	temp.sort()
	if temp[2] - temp[1] == temp[1] - temp[0]:
		print(temp[2] - temp[1])
	else:
		print(-1)


q = int(input())
a = sorted(list(set(map(int, input().split()))))
from math import *
import sys
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(int(fabs(a[0] - a[1])))
elif len(a) == 3:
	if a[1] == (a[0] + a[2]) / 2:
		print(a[2] - a[1])
	else:
		print(-1)
		sys.exit()
elif len(a) > 3:
	print(-1)


a = int(input())
b = list(map(int, input().split()))
b = list(set(b))
b.sort()
if len(b) > 3:
	print(-1)
elif len(b) == 2 and (b[1] - b[0]) % 2 == 0:
	print(int((b[1] - b[0]) / 2))
elif len(b) == 2:
	print(b[1] - b[0])
elif len(b) == 1:
	print(0)
elif b[0] + b[2] == b[1] * 2:
	print(b[1] - b[0])
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
s = sorted(list(set(a)))
el = len(s)
if el >= 4:
	print(-1)
	exit()
if len(s) == 1:
	print(0)
elif len(s) == 2:
	dif = s[1] - s[0]
	if dif % 2 == 0:
		print(dif // 2)
	else:
		print(dif)
else:
	(x, y, z) = s
	if y - x == z - y:
		print(y - x)
	else:
		print(-1)


n = int(input())
num = list(map(int, input().split()))
diff = []
for elem in num:
	if not elem in diff:
		diff.append(elem)
x = len(diff)
if x > 3:
	print(-1)
elif x == 3:
	diff.sort()
	if diff[0] + diff[2] != 2 * diff[1]:
		print(-1)
	else:
		print(diff[1] - diff[0])
elif x == 2:
	diff.sort()
	if (diff[1] - diff[0]) % 2 == 1:
		print(diff[1] - diff[0])
	else:
		print((diff[1] - diff[0]) // 2)
elif x == 1:
	print(0)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
b = list(set(a))
b.sort()
if len(b) == 3 and 2 * b[1] == b[0] + b[2]:
	print(b[2] - b[1])
elif len(b) == 1:
	print(0)
elif len(b) == 2:
	if (b[0] + b[1]) % 2 == 0:
		print(b[1] - (b[0] + b[1]) // 2)
	else:
		print(b[1] - b[0])
else:
	print(-1)


n = int(input())
import math
ar = list(map(int, input().split()))
set1 = set(ar)
e = list(set1)
if len(set1) == 1:
	print(0)
elif len(set1) == 2 and math.floor((e[0] + e[1]) / 2) == math.ceil((e[0] + e[1]) / 2):
	arr = list(set1)
	print(abs((arr[0] + arr[1]) // 2 - arr[0]))
else:
	arr = list(set1)
	arr.sort()
	flag = 0
	for i in range(len(arr)):
		d = []
		for j in range(len(arr)):
			d.append(abs(arr[j] - arr[i]))
		d.remove(0)
		if len(set(d)) == 1:
			flag = 1
			break
		else:
			flag = 0
			continue
	if flag == 1:
		if i == len(arr) - 1:
			print(arr[i] - arr[i - 1])
		elif i == 0:
			print(arr[i + 1] - arr[i])
		else:
			print(arr[i + 1] - arr[i])
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
if len(a) > 3:
	print(-1)
	exit(0)
if len(a) == 1:
	print(0)
if len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(a[1] - a[0])
if len(a) == 3:
	if a[1] - a[0] == a[2] - a[1]:
		print(a[1] - a[0])
	else:
		print(-1)


n = int(input())
lst = list(map(int, input().split()))
sett = set(lst)
if len(sett) == 1:
	print(0)
elif len(sett) == 2:
	delta = max(lst) - min(lst)
	if delta % 2 == 0:
		median = delta / 2
		print(int(median))
	else:
		print(delta)
elif len(sett) == 3:
	maxx = max(lst)
	minn = min(lst)
	delta = maxx - minn
	median = delta / 2
	point = minn + median
	if point not in lst:
		print(-1)
	else:
		print(int(median))
else:
	print(-1)


int(input())
c = list(map(int, input().split()))
d = sorted(c)
b = list(set(d))
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	if b[2] - b[1] == b[1] - b[0]:
		print(b[2] - b[1])
	else:
		print(-1)
elif len(b) == 2:
	if (b[1] - b[0]) % 2 == 0:
		print(int((b[1] - b[0]) / 2))
	else:
		print(b[1] - b[0])
else:
	print(0)


n = int(input())
a = [int(i) for i in input().split()]
dic = dict()
good = -1
for d in range(0, 101):
	r1 = a[0] - d
	r2 = a[0] + d
	r3 = a[0]
	cnt = 1
	for i in range(1, len(a)):
		if a[i] - d == r1 or a[i] + d == r1 or a[i] == r1:
			cnt += 1
	if cnt == n:
		good = d
		break
	cnt = 1
	for i in range(1, len(a)):
		if a[i] - d == r2 or a[i] + d == r2 or a[i] == r2:
			cnt += 1
	if cnt == n:
		good = d
		break
	cnt = 1
	for i in range(1, len(a)):
		if a[i] - d == r3 or a[i] + d == r3 or a[i] == r3:
			cnt += 1
	if cnt == n:
		good = d
		break
print(good)


n = int(input())
l = list(map(int, input().split()))
s = list(set(l))
x = len(s)
if x <= 3:
	s.sort()
	if x == 1:
		print(0)
	elif x == 2:
		if (s[1] - s[0]) % 2 == 0:
			print((s[1] - s[0]) // 2)
		else:
			print(s[1] - s[0])
	elif x == 3 and (s[2] - s[0]) % 2 == 0 and (s[0] + (s[2] - s[0]) // 2 == s[1]):
		print((s[2] - s[0]) // 2)
	else:
		print(-1)
else:
	print(-1)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a = list(set(a))
	a.sort()
	m = len(a)
	res = 0
	if len(a) == 1:
		print('0')
		return
	if len(a) > 2:
		if (a[0] + a[m - 1]) % 2 == 1:
			print('-1')
			return
		else:
			res = (a[0] + a[m - 1]) / 2
			for i in range(1, m - 1):
				if a[i] != res:
					print('-1')
					return
		print(int(res) - a[0])
	if len(a) == 2:
		if sum(a) % 2 == 1:
			res = a[m - 1] - a[0]
		else:
			res = sum(a) / 2 - a[0]
		print(int(res))
solve()


n = input()
nums = list(map(int, input().split()))
nums = list(set(nums))
nums.sort()
len_nums = len(nums)
if len_nums > 3:
	print(-1)
elif len_nums == 3:
	if nums[2] - nums[1] == nums[1] - nums[0]:
		print(nums[2] - nums[1])
	else:
		print(-1)
elif len_nums == 2:
	diff = nums[1] - nums[0]
	if diff % 2 == 0:
		print(diff // 2)
	else:
		print(diff)
elif len_nums == 1:
	print(0)
else:
	print(-1)


def solve(s):
	allSet = set()
	for i in s:
		if i in allSet:
			continue
		else:
			allSet.add(i)
		if len(allSet) > 3:
			return -1
	allValue = []
	for i in allSet:
		allValue.append(i)
	allValue.sort()
	if len(allValue) == 1:
		return 0
	elif len(allValue) == 2:
		diff = int(allValue[-1] - allValue[0])
		if diff % 2 == 1:
			return int(diff)
		else:
			return int(diff / 2)
	else:
		diff = int(allValue[-1] - allValue[1])
		if (allValue[0] + allValue[-1]) / 2 == allValue[1]:
			return int(diff)
		else:
			return -1
total = int(input())
a = [int(s) for s in input().split()]
print(solve(a))


n = int(input())
arr = [int(i) for i in input().split()]
dist = sorted(set(arr))
if len(dist) == 1:
	print(0)
elif len(dist) == 2:
	if (dist[1] + dist[0]) % 2 == 1:
		print(dist[1] - dist[0])
	else:
		print(int((dist[1] + dist[0]) / 2) - dist[0])
elif len(dist) == 3:
	if dist[1] - dist[0] == dist[2] - dist[1]:
		print(dist[1] - dist[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a = sorted(list(set(a)))
l = len(a)
if l > 3:
	print('-1')
elif l == 1:
	print('0')
elif l == 2:
	d = a[1] - a[0]
	if not d % 2:
		d //= 2
	print(d)
elif a[1] - a[0] == a[2] - a[1]:
	print(a[2] - a[1])
else:
	print('-1')


n = input()
L = input()
L = [int(item) for item in L.split(' ')]
if L:
	L = list(set(L))
if len(L) > 3:
	print(-1)
elif len(L) == 3 or not L:
	L = sorted(L)
	if L[1] != (L[0] + L[2]) / 2:
		print(-1)
	else:
		print(L[1] - L[0])
elif len(L) == 2:
	if int(abs(L[1] - L[0]) / 2) == abs(L[1] - L[0]) / 2:
		print(int(abs(L[1] - L[0]) / 2))
	else:
		print(abs(L[0] - L[1]))
elif len(L) == 1:
	print(0)


import sys
import copy
sys.setrecursionlimit(1000000)
n = int(input())
a = [int(x) for x in input().split()]
st = set(a)
a = list(sorted(st))
if len(st) == 1:
	print(0)
	exit()
if len(st) == 2:
	if abs(a[0] - a[1]) % 2 == 0:
		print(abs(a[0] - a[1]) // 2)
		exit()
	else:
		print(abs(a[0] - a[1]))
		exit()
if len(st) == 3:
	if abs(a[0] - a[1]) == abs(a[1] - a[2]):
		print(abs(a[0] - a[1]))
		exit()
	else:
		print(-1)
		exit()
print(-1)


n = int(input())
a = list(map(int, input().split()))
uniq = set(a)
mi = min(uniq)
ma = max(uniq)
if 2 < len(uniq) <= 3:
	if (mi + ma) % 2 == 0 and (mi + ma) // 2 == sum(uniq - {mi, ma}):
		print(ma - sum(uniq - {mi, ma}))
	else:
		print(-1)
elif len(uniq) == 2:
	if mi % 2 == ma % 2:
		print((ma - mi) // 2)
	else:
		print(ma - mi)
elif len(uniq) == 1:
	print(0)
else:
	print(-1)


n = input()
a = [int(i) for i in input().split()]
b = sorted(list(set(a)))
if len(b) > 3 or (len(b) == 3 and b[0] - b[1] != b[1] - b[2]):
	print(-1)
elif len(b) == 3:
	print(b[1] - b[0])
elif len(b) == 2:
	print(b[1] - b[0] if (b[1] - b[0]) % 2 == 1 else (b[1] - b[0]) // 2)
else:
	print(0)


n = int(input())
a = [int(i) for i in input().split()]
c = sorted(set(a))
if len(c) == 1:
	print(0)
elif len(c) == 2:
	if abs(c[1] - c[0]) % 2 == 0:
		print(abs(c[1] - c[0]) // 2)
	else:
		print(abs(c[1] - c[0]))
elif len(c) == 3:
	if abs(c[2] - c[1]) == abs(c[1] - c[0]):
		print(abs(c[2] - c[1]))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
k = []
k = list(map(int, input().split()))
se = set(k)
li = sorted(list(se))
if len(li) > 3:
	print(-1)
elif len(li) == 1:
	print(0)
elif len(li) == 2:
	if (li[1] - li[0]) % 2 == 0:
		print((li[1] - li[0]) // 2)
	else:
		print(li[1] - li[0])
elif li[1] - li[0] == li[2] - li[1]:
	print(li[1] - li[0])
else:
	print(-1)


a = int(input())
z = list(map(int, input().split()))
z = list(set(z))
z.sort()
if len(z) > 3:
	print(-1)
elif len(z) == 1:
	print(0)
elif len(z) == 2:
	if (z[0] + z[1]) % 2 == 1:
		print(z[1] - z[0])
	else:
		t = (z[1] + z[0]) // 2
		print(t - z[0])
elif z[1] - z[0] == z[2] - z[1]:
	print(z[1] - z[0])
else:
	print(-1)


n = map(int, input())
nums = list(set(map(int, input().strip().split())))
min_ = min(nums)
max_ = max(nums)
(d, m) = divmod(max_ - min_, 2)
if m != 0:
	if len(nums) == 2:
		print(max_ - min_)
		exit(0)
	else:
		print(-1)
		exit(0)
else:
	center = int(min_ + (max_ - min_) / 2)
	D = int(center - min_)
	for num in nums:
		if num == min_ or num == max_:
			continue
		if num == center or num + D == center or num - D == center:
			continue
		else:
			print(-1)
			exit(0)
	print(D)


m = int(input())
l = set(map(int, input().split()))
l.difference_update()
n = list(l)
n.sort()
if len(n) > 3 or len(n) < 1:
	print(-1)
	exit(0)
elif len(n) == 2:
	k = n[1] - n[0]
	if k % 2 != 0:
		print(k)
	else:
		print(k // 2)
	exit(0)
elif len(n) == 1:
	print(0)
	exit(0)
elif n[2] - n[1] == n[1] - n[0]:
	print(n[1] - n[0])
else:
	print(-1)
	exit(0)


n = int(input())
a = list(map(int, input().split()))
d = 100001
f = 0
for k in range(1, 101):
	l = [k] * n
	s = set()
	for i in range(n):
		s.add(abs(a[i] - l[i]))
	if len(s) <= 2:
		if 0 in s:
			s.remove(0)
		x = 0
		if len(s) == 1:
			f = 1
			for i in s:
				x = i
				break
			d = min(d, x)
		elif len(s) == 0:
			f = 1
			d = 0
if f == 1:
	print(d)
else:
	print('-1')


__version__ = '0.1'
__date__ = '2019-04-16'
import sys

def find_D(numbers):
	diff = max(numbers) - min(numbers)
	largest = max(numbers)
	D = diff
	if diff % 2 == 0:
		D = diff // 2
	for a in numbers:
		if largest - a != D and largest - a != D * 2 and (a != largest):
			return -1
	return D

def main(argv=None):
	n = int(input())
	numbers = list(map(int, input().split()))
	print(find_D(numbers))
	return 0
STATUS = main()
sys.exit(STATUS)


n = int(input())
a = [0 for i in range(n)]
a[0:n] = map(int, input().split())
mi = min(a)
ma = max(a)
mm = (ma + mi) / 2
if mm == int(mm):
	d = mm - mi
	for number in a:
		if number != mi and number != ma and (number != mm):
			d = -1
			break
else:
	d = ma - mi
	for number in a:
		if number != mi and number != ma:
			d = -1
			break
print(int(d))


R = lambda : map(int, input().split())
input()
a = sorted(list(set(R())))
if len(a) > 3:
	d = -1
elif len(a) == 3:
	d = a[1] - a[0] if a[1] - a[0] == a[2] - a[1] else -1
elif len(a) == 2:
	d = a[1] - a[0] if (a[1] - a[0]) % 2 else (a[1] - a[0]) // 2
else:
	d = 0
print(d)


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

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = list(set(zzz()))
if len(l) == 1:
	print(0)
	exit()
if len(l) > 3:
	print(-1)
	exit()
if len(l) == 2:
	t = abs(l[-1] - l[0])
	if t % 2 == 0:
		print(t // 2)
	else:
		print(t)
	exit()
(a, b, c) = sorted(l)
t1 = b - a
t2 = c - b
if t1 == t2:
	print(t1)
else:
	print(-1)


from math import *
n = int(input())
l = list(map(int, input().split()))
l = set(l)
l = list(l)
l.sort()
if len(l) > 3:
	print('-1')
elif len(l) == 3:
	if l[1] - l[0] == l[2] - l[1]:
		print(l[1] - l[0])
	else:
		print('-1')
elif len(l) == 2:
	if floor((l[1] - l[0]) / 2) == ceil((l[1] - l[0]) / 2):
		print((l[1] - l[0]) // 2)
	else:
		print(l[1] - l[0])
else:
	print('0')


n = int(input())
a = list(map(int, input().split()))
maxi = max(a)
mini = min(a)
flag = 0
if (maxi + mini) % 2 == 0:
	for item in a:
		if not (item == maxi or item == mini or item == (maxi + mini) // 2):
			flag = 1
			break
	if flag == 1:
		print('-1')
	else:
		print((maxi - mini) // 2)
else:
	for item in a:
		if not (item == maxi or item == mini):
			flag = 1
			break
	if flag == 1:
		print('-1')
	else:
		print(maxi - mini)


n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)))
t = len(b)
if t == 1:
	print(0)
elif t == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
elif t == 3:
	if (b[2] - b[0]) % 2:
		print(-1)
	elif b[1] == b[0] + (b[2] - b[0]) // 2:
		print((b[2] - b[0]) // 2)
	else:
		print(-1)
else:
	print(-1)


input()
l = sorted(set([*map(int, input().split())]))
le = len(l)
if le == 1:
	print(0)
elif le == 2:
	if sum(l) & 1:
		print(l[1] - l[0])
	else:
		print(sum(l) // 2 - min(l))
elif le == 3:
	if l[0] + l[-1] == 2 * l[1]:
		print(l[1] - l[0])
	else:
		print(-1)
else:
	print(-1)


IN = input
rint = lambda : int(IN())
rmint = lambda : map(int, IN().split())
rlist = lambda : list(rmint())
n = rint()
a = rlist()
b = list(set(a))
b.sort()
if len(b) > 3:
	print(-1)
elif len(b) == 1:
	print(0)
elif len(b) == 2:
	p = b[1] - b[0]
	if p & 1:
		print(p)
	else:
		print(p // 2)
elif b[1] - b[0] == b[-1] - b[1]:
	print(b[1] - b[0])
else:
	print(-1)


x = int(input())
l = list(map(int, input().split()))
l = list(set(l))
if len(l) == 1:
	print(0)
elif len(l) == 2:
	ans = abs(l[0] - l[1])
	if ans % 2 == 0:
		print(ans // 2)
	else:
		print(ans)
elif len(l) == 3:
	su = 0
	for i in range(len(l)):
		su += l[i]
	su //= len(l)
	a1 = su - min(l)
	a2 = max(l) - su
	if a1 == a2:
		print(a1)
	else:
		print(-1)
else:
	print(-1)


def f(l):
	if len(l) > 3:
		return -1
	if len(l) == 2:
		d = l[1] - l[0]
		if d % 2 == 1:
			return d
		else:
			return int(d / 2)
	if len(l) == 1:
		return 0
	if l[0] + l[2] == 2 * l[1]:
		return l[1] - l[0]
	else:
		return -1
n = int(input())
l = list(map(int, input().strip().split()))
l = sorted(set(l))
print(f(l))


def solve():
	n = int(input())
	A = set([int(k) for k in input().split()])
	A = sorted(A)
	if len(A) == 1:
		print(0)
		return
	if len(A) > 3:
		print(-1)
		return
	diff = A[1] - A[0]
	if len(A) == 2:
		print(diff if diff % 2 else diff // 2)
		return
	if A[2] - A[1] != diff:
		print(-1)
		return
	print(diff)
solve()


n = int(input())
sa = set(map(int, input().split()))
if len(sa) > 3:
	print(-1)
elif len(sa) == 1:
	print(0)
else:
	sa = sorted(sa)
	if len(sa) == 2:
		diff = sa[1] - sa[0]
		if diff % 2 == 0:
			print(diff // 2)
		else:
			print(diff)
	elif sa[1] - sa[0] == sa[2] - sa[1]:
		print(sa[1] - sa[0])
	else:
		print(-1)


n = int(input())
import sys
l = list(map(int, input().split()))
zaj = [0] * 1000
for i in range(n):
	for j in range(n):
		zaj[abs(l[i] - l[j])] = 1
j = 0
if sum(zaj) > 3:
	print(-1)
else:
	chuj = []
	for i in range(1, 1000):
		if zaj[i] == 1:
			chuj.append(i)
	if len(chuj) == 0:
		print(0)
		sys.exit(0)
	if len(chuj) == 1:
		if chuj[0] % 2 == 1:
			print(chuj[0])
			sys.exit(0)
		else:
			print(chuj[0] // 2)
			sys.exit(0)
	elif chuj[1] == 2 * chuj[0]:
		print(chuj[0])
		sys.exit(0)
	else:
		print(-1)


n = int(input())
a = list(set([int(num) for num in input().split()]))
a.sort()

def equal(b):
	diffArray = []
	for j in range(0, len(b) - 1):
		diff = b[j + 1] - b[j]
		if diff != 0:
			diffArray.append(diff)
		j += 1
	valArray = []
	for k in range(0, len(diffArray) - 1):
		if diffArray[k + 1] == diffArray[k]:
			valArray.append(True)
		elif diffArray[k + 1] != diffArray[k]:
			valArray.append(False)
		k += 1
	if all(valArray) == True:
		return diffArray[0]
	elif all(valArray) == False:
		return '-1'
if len(a) > 3:
	print('-1')
elif len(a) == 1:
	print(0)
elif len(a) == 3:
	c = equal(a)
	print(c)
else:
	diff = a[1] - a[0]
	if diff % 2:
		print(diff)
	else:
		print(int(diff / 2))


n = int(input())
s = []
ans1 = []
s = input().split()
for i in range(n):
	s[i] = int(s[i])
s1 = set(s)
s2 = list(s1)
s2.sort()
if len(s2) > 3:
	print('-1')
elif len(s2) == 3:
	if s2[2] - s2[1] != s2[1] - s2[0]:
		print('-1')
	else:
		print(s2[1] - s2[0])
elif len(s2) == 2:
	if (s2[1] - s2[0]) % 2 == 0:
		print(int((s2[1] - s2[0]) / 2))
	else:
		print(s2[1] - s2[0])
else:
	print('0')


def getvariants(variants, x):
	left = []
	for (point, diff) in variants:
		if x - diff == point or x + diff == point or x == point:
			left += [(point, diff)]
	return left
n = int(input('').strip())
A = [int(i) for i in input('').strip().split(' ')]
a = A[0]
variants = None
i = 1
while i < len(A):
	if A[i] != a:
		b = A[i]
		variants = [(a, abs(a - b)), (b, abs(a - b))]
		(diff, remainder) = divmod(max(a, b) - min(a, b), 2)
		if remainder == 0:
			variants += [(min(a, b) + diff, diff)]
		break
	i += 1
if not variants:
	print(0)
	exit()
else:
	for x in A[i + 1:]:
		variants = getvariants(variants, x)
		if not variants:
			break
	if not variants:
		print(-1)
	else:
		print(min((diff for (point, diff) in variants)))


x = int(input())
y = input().split()
k = 1000
for i in y:
	if int(i) < k:
		k = int(i)
b = 0
for i in y:
	if int(i) > b:
		b = int(i)
if b % 2 == k % 2:
	kh = b - (b + k) / 2
	mos = (b + k) / 2
else:
	kh = b - k
	mos = b
for i in y:
	if int(i) != b and int(i) != k and (int(i) != mos):
		if int(i) + kh != mos and int(i) - kh != mos:
			kh = -1
print(int(kh))


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print(0)
	exit(0)
a.sort()
for x in range(0, 101):
	g = abs(a[0] - x)
	fl = True
	for i in range(1, len(a)):
		if not (abs(a[i] - x) == g or a[i] == x):
			fl = False
	if fl:
		print(g)
		exit(0)
print(-1)


n = int(input())
numbers = [int(x) for x in input().split()]
numbers.sort()
minimum = min(numbers)
maximum = max(numbers)
delta = maximum - minimum
average = maximum - minimum
countmin = numbers.count(minimum)
countmax = numbers.count(maximum)
if delta % 2 == 0:
	delta = int(delta / 2)
if countmin + countmax == n:
	if average % 2 == 0:
		for i in range(len(numbers)):
			if numbers[i] != maximum:
				numbers[i] += delta
			elif numbers[i] != minimum:
				numbers[i] -= delta
	else:
		for i in range(len(numbers)):
			if numbers[i] == minimum:
				numbers[i] += delta
else:
	for j in range(len(numbers)):
		if numbers[j] == maximum:
			numbers[j] -= delta
		elif numbers[j] == minimum:
			numbers[j] += delta
count = numbers.count(numbers[0])
if count != n:
	print('-1')
else:
	print(delta)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s.sort()
st = set(s)
if len(st) == 1:
	print(0)
	exit(0)
elif len(st) == 2:
	x = s[-1] - s[0]
	if x % 2 == 0:
		print(x // 2)
	else:
		print(x)
	exit(0)
elif len(st) == 3:
	x = (s[-1] - s[0]) // 2
	if s[0] + x in s and s[0] + 2 * x in s:
		print(x)
		exit(0)
print(-1)


n = int(input())
arr = list(map(int, input().split()))
new_list = set(arr)
if len(new_list) > 3:
	print('-1')
elif len(new_list) == 2:
	p = list(new_list)
	p.sort()
	su = sum(p)
	if su % 2 == 0:
		print(su // 2 - p[0])
	else:
		print(p[1] - p[0])
elif len(new_list) == 1:
	print(0)
else:
	p = list(new_list)
	p.sort()
	su = sum(p)
	m = len(p)
	if su / m != p[m // 2]:
		print('-1')
	elif su // m == p[m // 2]:
		print(su // m - p[0])


n = int(input())
g = list(map(int, input().split()))
l = set(g)
l1 = [ele for ele in l]
l1.sort()
if len(g) == 1:
	print(0)
elif len(l) > 3:
	print(-1)
elif len(l) == 1:
	print(0)
elif len(l) == 2:
	if (max(l) - min(l)) % 2 == 0:
		print(int((max(l) - min(l)) / 2))
	else:
		print(max(l) - min(l))
elif len(l) == 3:
	if (max(l) - min(l)) / 2 == int((max(l) - min(l)) / 2) and int((max(l) - min(l)) / 2) + min(l) == l1[1]:
		print(int((max(l) - min(l)) / 2))
	else:
		print(-1)


n = int(input())
a = [int(elem) for elem in input().split()]
a.sort()
a_mi = a[0]
a_ma = a[n - 1]
flag_all = True
for i in range(n):
	if a[i] != a_mi and a[i] != a_ma:
		flag_all = False
ans_min = 101
if flag_all:
	ans_min = a_ma - a_mi
if (a_ma - a_mi) % 2 == 0:
	d = (a_ma - a_mi) // 2
	flag = True
	for i in range(n):
		if not (a[i] == a_mi or a[i] == a_ma or a[i] == (a_ma + a_mi) // 2):
			flag = False
	if flag:
		ans_min = min(ans_min, d)
if ans_min == 101:
	print(-1)
else:
	print(ans_min)


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

def rdi():
	return int(input())
n = rdi()
line = sorted(list(set(rlist())))
if len(line) >= 4:
	print(-1)
elif len(line) == 3:
	if line[1] - line[0] == line[2] - line[1]:
		print(line[1] - line[0])
	else:
		print(-1)
elif len(line) == 2:
	if (line[1] - line[0]) % 2 == 0:
		print((line[1] - line[0]) // 2)
	else:
		print(line[1] - line[0])
else:
	print(0)


T = input()
t = int(T)
n = input()
sk = n.split()
st = set()
for a in sk:
	st.add(int(a))
if len(st) > 3:
	print(-1)
elif len(st) == 1:
	print(0)
elif len(st) == 2:
	ls = list()
	for a in st:
		ls.append(a)
	if abs(ls[0] - ls[1]) % 2:
		print(abs(ls[0] - ls[1]))
	else:
		print(int(abs(ls[0] - ls[1]) / 2))
else:
	ls = list()
	for a in st:
		ls.append(a)
	ls.sort()
	if ls[1] - ls[0] != ls[2] - ls[1]:
		print(-1)
	else:
		print(ls[1] - ls[0])


def canEqualise(array):
	unik = sorted(set(array))
	if len(unik) == 1:
		return 0
	elif len(unik) == 2:
		if (unik[1] - unik[0]) % 2 == 0:
			return (unik[1] - unik[0]) // 2
		else:
			return unik[1] - unik[0]
	elif len(unik) == 3:
		if unik[2] - unik[1] == unik[1] - unik[0]:
			x = unik[2] - unik[1]
			return x
		else:
			return -1
	return -1
n = int(input())
inp = list(map(int, input().split()))
print(canEqualise(inp))


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
if len(a) > 3:
	print(-1)
elif len(a) == 2:
	Dx2 = a[1] - a[0]
	if Dx2 % 2 != 0:
		print(a[1] - a[0])
	else:
		print(Dx2 // 2)
elif len(a) == 1:
	print(0)
else:
	Dx2 = a[2] - a[0]
	if Dx2 % 2 != 0:
		print(-1)
	else:
		D = Dx2 // 2
		if a[1] != a[2] - D:
			print(-1)
		else:
			print(D)


n = int(input())
a = [int(i) for i in input().split()]
k = abs(max(a) - min(a)) / 2
if k == int(k) and len(set(a)) <= 2:
	print(int(k))
elif k == int(k) and len(set(a)) == 3 and (max(a) - k in a):
	print(int(k))
elif k != int(k) and len(set(a)) <= 2:
	print(max(a) - min(a))
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
mina = min(arr)
maxa = max(arr)
flag = 0
for i in range(101):
	count = 0
	x = mina + i
	for j in range(n):
		a = arr[j] + i
		b = arr[j] - i
		c = arr[j]
		if a == x or b == x or c == x:
			count += 1
	if count == n:
		print(i)
		flag = 1
		break
if flag == 0:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in a:
	if i in d.keys():
		d[i] += 1
	else:
		d[i] = 1
if len(d) == 1:
	print(0)
elif len(d) == 2:
	k = list(d.keys())
	if k[0] % 2 != k[1] % 2:
		print(abs(k[0] - k[1]))
	else:
		print(abs(k[0] - k[1]) // 2)
elif len(d) == 3:
	k = list(d.keys())
	k.sort()
	if k[1] - k[0] != k[2] - k[1]:
		print(-1)
	else:
		print(k[1] - k[0])
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
final = []
for i in l:
	if i not in final:
		final += [i]
if len(final) == 1:
	print(0)
elif len(final) == 2:
	if (final[1] - final[0]) % 2 == 0:
		print((final[1] - final[0]) // 2)
	else:
		print(final[1] - final[0])
elif len(final) == 3:
	if final[1] - final[0] == final[2] - final[1]:
		print(final[2] - final[1])
	else:
		print(-1)
else:
	print(-1)


num_cases = int(input())
nums = [int(x) for x in input().split()]
uniques = set(nums)
if len(uniques) == 1:
	d = 0
elif len(uniques) == 2:
	d = max(uniques) - min(uniques)
	if d % 2 == 0:
		d = d / 2
elif len(uniques) > 3:
	d = -1
else:
	for n in uniques:
		if n != max(uniques) and n != min(uniques):
			if (max(uniques) + min(uniques)) / 2 != n:
				d = -1
			else:
				d = max(uniques) - n
print(int(d))


n = int(input())
Arr1 = list(map(int, input().split(' ')))
Arr = [Arr1[0]]
flag = True
for i in range(1, n):
	if Arr1[i] not in Arr:
		Arr.append(Arr1[i])
		if len(Arr) == 4:
			print(-1)
			flag = False
			break
Arr.sort()
if flag:
	if len(Arr) == 1:
		print(0)
	elif len(Arr) == 2:
		poss_ans1 = Arr[1] - Arr[0]
		if poss_ans1 // 2 * 2 == poss_ans1:
			print(poss_ans1 // 2)
		else:
			print(poss_ans1)
	else:
		poss_ans = (Arr[2] + Arr[0]) / 2
		if poss_ans == Arr[1]:
			print(int(poss_ans) - Arr[0])
		else:
			print(-1)


input()
nums = list(map(int, input().split()))
nums = sorted(nums)
diff = nums[-1] - nums[0]
if diff == 0:
	print(0)
else:
	if diff % 2 == 1:
		t = diff + nums[0]
		D = diff
	else:
		t = diff // 2 + nums[0]
		D = int(diff // 2)
	fail = False
	for i in nums:
		if i not in [t, t - D, t + D]:
			print(-1)
			fail = True
			break
	if not fail:
		print(int(D))


n = int(input())
a = list(map(int, input().split()))
a.sort()
bb = []
a1 = []
if a[0] == a[n - 1]:
	a1.append(0)
for i in range(0, 200, 1):
	d = 0
	w = 0
	bb = a.copy()
	for j in range(n):
		if bb[j] == i:
			continue
		if d == 0:
			d = abs(bb[j] - i)
		elif d != abs(bb[j] - i):
			w = 1
			break
	if w == 0:
		a1.append(d)
if len(a1) == 0:
	print('-1')
else:
	print(min(a1))


n = int(input())
a = sorted(set(map(int, input().split())))
if len(a) == 2 and (not (a[1] - a[0]) % 2):
	print((a[1] - a[0]) // 2)
elif len(a) == 2:
	print(a[1] - a[0])
elif len(a) == 3 and (a[-1] + a[0]) // 2 in a and (not (a[-1] + a[0]) % 2):
	print((a[-1] - a[0]) // 2)
elif len(a) == 1:
	print(0)
else:
	print(-1)


import sys
n = int(input())
all_inp = input()
all_nums = all_inp.split()
all_ints = [int(s) for s in all_nums]
min_ = min(all_ints)
max_ = max(all_ints)
flag = 0
d = -1
for i in range(0, max_):
	flag = 0
	for num in all_ints:
		if num == min_ or num - i == min_ + i or num == min_ + i:
			flag = flag + 1
		else:
			flag = 0
	if flag == len(all_ints):
		d = i
		break
	else:
		d = -1
		continue
print(d)


n = int(input())
x = [int(i) for i in input().split()]
d = list(set(x))
d.sort()
if len(d) == 1:
	print(0)
elif len(d) == 2 and abs(d[1] - d[0]) % 2 == 0:
	print(abs(d[1] - d[0]) // 2)
elif len(d) == 2 and abs(d[1] - d[0]) % 2 != 0:
	print(abs(d[1] - d[0]))
elif len(d) == 3 and (d[0] + d[2]) // 2 == d[1] and (abs(d[2] - d[0]) % 2 == 0):
	print(abs(d[2] - d[0]) // 2)
else:
	print(-1)


(n, a) = (int(input()), list(sorted(set(map(int, input().split())))))
res = -1
if len(a) == 1:
	res = 0
elif len(a) == 2:
	res = a[1] - a[0]
	if res % 2 == 0:
		res //= 2
elif len(a) == 3 and a[1] - a[0] == a[2] - a[1]:
	res = a[1] - a[0]
print(res)


n = int(input())
d = list(map(int, input().split()))
s = int((max(d) + min(d)) / 2)
m = min(d)
k = -1
for i in range(0, max(d) + 1):
	f = True
	for j in d:
		if m + i != j and m + i != j + i and (m + i != j - i):
			f = False
	if f:
		k = i
		break
print(k)


n = int(input())
nums = list(map(int, input().split()))
if len(list(dict.fromkeys(nums))) > 3:
	print(-1)
else:
	dist = sorted(list(dict.fromkeys(nums)))
	if len(dist) == 1:
		print(0)
	elif len(dist) == 2:
		if (dist[1] - dist[0]) % 2 == 0:
			print((dist[1] - dist[0]) // 2)
		else:
			print(dist[1] - dist[0])
	elif dist[1] - dist[0] == dist[2] - dist[1]:
		print(dist[2] - dist[1])
	else:
		print(-1)


a = input()
a = set(map(int, input().split()))
D = 0
a = list(a)
a.sort()
if len(a) != 1:
	if len(a) > 3:
		D = -1
	else:
		D0 = abs(a[0] - a[-1])
		D1 = abs(a[-1] - a[-2])
		d2 = abs(a[0] - a[-2])
		b = sorted(list(set([D0, D1, d2])))
		if b[0] == 0:
			b.pop(0)
		if b[0] % 2 == 0 and len(b) == 1:
			b[0] //= 2
		if len(b) >= 3:
			b[0] = -1
		D = b[0]
print(D)


input()
dis = list(map(int, input().split()))
(a, b) = (max(dis), min(dis))
if (a - b) % 2 == 0:
	k = (a - b) // 2
	q = [a, b, a - k]
else:
	k = a - b
	q = [a, b]
for i in dis:
	if i not in q:
		k = -1
		break
print(k)


N = int(input())
a = input()
A = a.split(' ')
twod_list = []
for i in A:
	twod_list.append(int(i))
S = set(twod_list)
Arr = list(S)
Arr.sort()
if len(S) == 1:
	print(0)
elif len(S) > 3:
	print(-1)
elif len(S) == 3:
	if Arr[1] - Arr[0] == Arr[2] - Arr[1]:
		print(Arr[1] - Arr[0])
	else:
		print(-1)
elif len(S) == 2:
	if abs(Arr[0] - Arr[1]) % 2 == 0:
		print(int(abs(Arr[0] - Arr[1]) / 2))
	else:
		print(abs(Arr[0] - Arr[1]))


n = int(input())
a = [int(x) for x in input().split()]
a_max = max(a)
a_min = min(a)
a_diff = a_max - a_min
flag = 0
for a_ in a:
	if a_ == a_min or a_ == a_max:
		continue
	if a_ - a_min == a_diff / 2:
		flag = 1
		continue
	else:
		flag = 2
		break
if flag == 0:
	if a_diff % 2 == 0:
		print('%d' % (a_diff / 2))
	else:
		print('%d' % a_diff)
elif flag == 1:
	print('%d' % (a_diff / 2))
else:
	print(-1)


import math
n = int(input())
l = list(set(map(int, input().split())))
l.sort()
if len(l) == 1:
	ans = 0
elif len(l) == 2:
	if (l[0] + l[1]) % 2 == 0:
		ans = abs(l[0] - l[1]) // 2
	else:
		ans = abs(l[1] - l[0])
elif len(l) == 3:
	if l[2] - l[1] == l[1] - l[0]:
		ans = abs(l[2] - l[1])
	else:
		ans = -1
else:
	ans = -1
if ans >= 0:
	print(ans)
else:
	print(-1)


input()
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
mid = mn + (mx - mn) / 2
for i in a:
	if i != mn and i != mx and (i != mid):
		print(-1)
		raise SystemExit
print(mx - int(mid) if (mx - mn) % 2 == 0 else mx - mn)


n = int(input())
number = list(map(int, input().strip().split(' ')))
number.sort()
D = 0
flag = 1
j = 0
if n == 1:
	print(0)
else:
	a = number[0]
	b = number[1]
	i = 1
	while a == b and i < n:
		a = number[i - 1]
		b = number[i]
		i = i + 1
	j = i
	if i == n and a == b:
		D = 0
	else:
		if (b - a) % 2 == 0:
			D = int((b - a) / 2)
			level = a + D
			while i < n:
				if number[i] - D > level:
					flag = 0
					break
				i = i + 1
		else:
			D = b - a
			level = b
			while i < n:
				if number[i] != level and number[i] - D != level:
					flag = 0
				i = i + 1
		if flag == 0:
			flag = 1
			i = j
			D = b - a
			level = b
			while i < n:
				if number[i] != level and number[i] - D != level:
					flag = 0
				i = i + 1
	if flag == 0:
		print(-1)
	else:
		print(D)


n = int(input())
arr = [int(x) for x in input().split()]
count = []
for i in arr:
	if i not in count:
		count.append(i)
count.sort()
if len(count) == 3 and (count[0] + count[2]) / 2 == count[1]:
	print(count[2] - count[1])
elif len(count) == 2:
	if (count[1] - count[0]) // 2 != (count[1] - count[0]) / 2:
		print(count[1] - count[0])
	else:
		print((count[1] - count[0]) // 2)
elif len(count) == 1:
	print(0)
else:
	print(-1)


n = int(input())
ri = lambda : map(int, input().split(' '))
a = list(ri())
if len(set(a)) == 1:
	print(0)
	import sys
	sys.exit(0)
ans = 300
for x in range(0, 201):
	diff = set()
	for y in a:
		if x == y:
			continue
		diff.add(abs(x - y))
	if len(diff) == 1:
		for i in diff:
			ans = min(ans, i)
if ans == 300:
	ans = -1
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
mi = min(l)
mx = max(l)
if (max(l) - min(l)) % 2 == 0:
	d = (max(l) - min(l)) // 2
	lf = [min(l) + d for i in range(n)]
	for i in range(n):
		if l[i] == mi:
			l[i] += d
		if l[i] == mx:
			l[i] -= d
else:
	d = max(l) - min(l)
	lf = [min(l) for i in range(n)]
	for i in range(n):
		if l[i] == mx:
			l[i] -= d
if l == lf:
	print(d)
else:
	print(-1)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict

def main():
	(n, *a) = map(int, read().split())
	for i1 in range(0, 101):
		d = [[0] * n for _ in range(301)]
		dic1 = defaultdict(int)
		a1 = [i + i1 for i in a]
		a2 = [i - i1 for i in a]
		cnt = 0
		for (p1, p2, p3) in zip(a, a1, a2):
			d[p1 + 100][cnt] = 1
			d[p2 + 100][cnt] = 1
			d[p3 + 100][cnt] = 1
			cnt += 1
		for i2 in range(301):
			if all(d[i2]):
				print(i1)
				sys.exit()
	print(-1)
main()


import sys

def equal(a):
	uni = sorted(set(a))
	if len(uni) == 1:
		print('0')
	elif len(uni) == 2:
		if (uni[1] + uni[0]) % 2 == 0:
			print((uni[1] + uni[0]) // 2 - uni[0])
		else:
			print(uni[1] - uni[0])
	elif len(uni) == 3:
		if uni[2] - uni[1] == uni[1] - uni[0]:
			X = uni[2] - uni[1]
			print(str(X))
		else:
			print(-1)
	else:
		print(-1)
n = int(input())
a = list(map(int, input().split()))
equal(a)


def li():
	return list(map(int, input().split(' ')))
input()
a = sorted(list(set(li())))
if len(a) > 3:
	print(-1)
elif len(a) == 3:
	if (a[0] + a[2]) % 2 == 0 and (a[0] + a[2]) // 2 == a[1]:
		print(abs(a[1] - a[0]))
	else:
		print(-1)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print(abs((a[1] - a[0]) // 2))
	else:
		print(abs(a[1] - a[0]))
elif len(a) == 1:
	print(0)


from collections import defaultdict as dd
n = int(input())
l = list(map(int, input().split()))
l.sort()
f = l[0]
flag = 1
h = []
for i in range(0, l[-1] + 1):
	flag = 1
	p = dd(lambda : -1)
	p[f] = 1
	p[f + i] = 1
	p[f - i] = 1
	for j in l[1:]:
		if p[j] == 1 or p[j + i] == 1 or p[j - i] == 1:
			continue
		else:
			flag = 0
			break
	if flag:
		h.append(i)
if len(h) is 0:
	print(-1)
else:
	print(h[0])


from sys import stdin, stdout
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from math import ceil
from collections import defaultdict as dd
from collections import Counter as C
n = it()
l = sorted(mp())
c = C(l)
if len(c) == 1:
	print(0)
elif len(c) == 2:
	if abs(l[0] - l[-1]) & 1:
		print(l[-1] - l[0])
	else:
		print(abs(l[0] - l[-1]) // 2)
elif abs(l[0] - l[-1]) & 1:
	print(-1)
else:
	d = abs(l[0] - l[-1]) // 2
	l[0] += d
	for i in range(1, n):
		if l[i] == l[0]:
			continue
		elif l[i] < l[0]:
			l[i] += d
		else:
			l[i] -= d
	x = len(set(l))
	if x == 1:
		print(d)
	else:
		print(-1)


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	s = sorted(set(arr))
	if len(s) > 3:
		print(-1)
	elif len(s) == 3:
		if abs(s[0] - s[1]) == abs(s[1] - s[2]):
			print(abs(s[0] - s[1]))
		else:
			print(-1)
	elif len(s) == 2:
		if (s[0] + s[1]) % 2 == 0:
			print(abs((s[0] + s[1]) // 2 - s[0]))
		else:
			print(abs(s[0] - s[1]))
	else:
		print(0)
t = 1
for _ in range(t):
	main()


a = input()
b = list(set(map(int, input().split())))
b.sort()
num = 0
i = 0
flag = []
if len(b) < 2:
	print(num)
else:
	for i in range(100):
		s = []
		for j in b:
			d = j + i
			h = j - i
			s.append([h, j, d])
		for l in s[0]:
			flag = []
			for k in s[1:]:
				if l in k:
					flag.append(True)
				else:
					flag.append(False)
			if all(flag):
				break
		if all(flag):
			break
	if all(flag):
		print(i)
	else:
		print(-1)


N = int(input())
ip = [int(i) for i in input().split()]
least = min(ip)
most = max(ip)
if N == 2:
	if (most - least) % 2 == 0:
		print(int((most - least) / 2))
		exit()
	else:
		print(most - least)
		exit()
if (most - least) % 2 != 0:
	D = most - least
else:
	D = int((-least + most) / 2)
val = least + D
flag = 0
for num in ip:
	if num != least and num != most and (num != val):
		flag = 1
		print(-1)
		break
if flag != 1:
	print(D)


n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(1000)
b = []
for i in range(n):
	if a[i] != a[i + 1]:
		b.append(a[i])
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	b.sort()
	if abs(b[1] - b[0]) == abs(b[1] - b[2]):
		print(abs(b[1] - b[2]))
	else:
		print(-1)
elif len(b) == 2:
	m = abs(b[0] - b[1])
	if m % 2 == 0:
		print(m // 2)
	else:
		print(m)
else:
	print(0)


from sys import stdin

def main():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	e = list(set(a))
	e.sort()
	if len(e) == 1:
		return 0
	if len(e) == 2:
		if (e[1] + e[0]) % 2 == 0:
			return (e[1] - e[0]) // 2
		return e[1] - e[0]
	if len(e) == 3:
		if e[1] - e[0] == e[2] - e[1]:
			return e[1] - e[0]
		else:
			return -1
	else:
		return -1
print(main())


def solve():
	numbers = set((int(x) for x in input().split()))
	mx = max(numbers)
	mi = min(numbers)
	if len(numbers) == 1:
		return 0
	if len(numbers) == 2:
		if mx % 2 == mi % 2:
			return (mx - mi) / 2
		else:
			return mx - mi
	if len(numbers) == 3:
		if (mx + mi) / 2 in numbers:
			return (mx - mi) / 2
		else:
			return -1
	else:
		return -1
n = int(input())
print(int(solve()))


n = int(input())
a = list(map(int, input().split()))
ans = 1000
if n == 1:
	print(0)
	exit()
if len(set(a)) == 1:
	print(0)
	exit()
for s in range(101):
	t = set()
	for i in range(n):
		x = abs(s - a[i])
		if x == 0:
			continue
		t.add(x)
	if len(t) == 1:
		ans = min(ans, list(t)[0])
if ans == 1000:
	print(-1)
else:
	print(ans)


q = int(input())
w = list(map(int, input().split()))
e = []
t = (max(w) - min(w)) // 2
if len(list(set(w))) == 3:
	if (max(w) - min(w)) / 2 == t:
		if w.count(min(w) + t) != 0:
			e.append(t)
if len(list(set(w))) == 2:
	if (max(w) - min(w)) / 2 == t:
		if w.count(min(w) + 2 * t) != 0:
			e.append(t)
if len(list(set(w))) == 2:
	e.append(max(w) - min(w))
if len(e) == 0 and len(list(set(w))) != 1:
	print(-1)
elif len(list(set(w))) == 1:
	print(0)
else:
	print(min(e))


import math
a = math.inf
n = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(set(b))
c.sort()
d = len(c)
if d == 1:
	print(0)
else:
	if (c[1] - c[0]) % 2 == 0:
		e = [c[1], c[1] - c[0]]
		f = [c[0] + (c[1] - c[0]) // 2, (c[1] - c[0]) // 2]
	else:
		e = [c[1], c[1] - c[0]]
	if d == 2 and (c[1] - c[0]) % 2 == 0:
		print(f[1])
	elif d == 2:
		print(e[1])
	else:
		flag = 1
		i = 2
		while i < d:
			if c[i] - e[1] == e[0]:
				i += 1
			else:
				flag = 0
				break
		if flag:
			print(e[1])
		else:
			print(-1)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = collections.Counter(a)
	sd = sorted(d.items(), key=lambda x: x[0])
	if len(sd) > 3:
		print(-1)
		return
	if len(sd) == 1:
		print(0)
		return
	if len(sd) == 2:
		if (sd[0][0] + sd[1][0]) % 2 == 0:
			print(abs(sd[0][0] - (sd[0][0] + sd[1][0]) // 2))
		else:
			print(abs(sd[0][0] - sd[1][0]))
		return
	if sd[1][0] * 2 == sd[0][0] + sd[2][0]:
		print(sd[1][0] - sd[0][0])
	else:
		print(-1)
main()


t = int(input())
l = list(map(int, input().split()))
s = list(set(l))
s.sort()
if len(s) > 3:
	print(-1)
elif len(s) == 2:
	if (s[0] + s[1]) % 2 == 0:
		print((s[0] + s[1]) // 2 - s[0])
	else:
		n = s[1] - s[0]
		if n + s[0] == s[1]:
			print(n)
		else:
			print(-1)
else:
	flag = 0
	m = s[len(s) - 1] - s[len(s) - 2]
	for i in range(len(s) - 1, 0, -1):
		if s[i] - s[i - 1] != m:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(m)


n = input()
n = int(n)
a = input().split()
nums = {}
for num in a:
	nums[int(num)] = num
nums = list(nums.keys())
if len(nums) > 3:
	print(-1)
elif len(nums) == 3:
	nums.sort()
	if nums[1] - nums[0] == nums[2] - nums[1]:
		print(nums[2] - nums[1])
	else:
		print(-1)
elif len(nums) == 2:
	nums.sort()
	if (nums[1] - nums[0]) / 2 == int((nums[1] - nums[0]) / 2):
		print(int((nums[1] - nums[0]) / 2))
	else:
		print(nums[1] - nums[0])
elif len(nums) == 1:
	print(0)


n = int(input())
a = input().split()
max = 0
b = []
for i in range(n):
	a[i] = int(a[i])
	x = 0
	for j in range(0, len(b)):
		if a[i] == b[j]:
			x = 1
	if x == 0:
		b.append(a[i])
	if len(b) > 3:
		print(-1)
		break
if len(b) < 4:
	b.sort()
	if len(b) == 3:
		if b[1] - b[0] == b[2] - b[1]:
			print(b[1] - b[0])
		else:
			print(-1)
	if len(b) == 2:
		if (b[1] - b[0]) % 2 == 0:
			print((b[1] - b[0]) // 2)
		else:
			print(b[1] - b[0])
	if len(b) == 1:
		print(0)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
num = ai[-1] - ai[0]
ans = 0
if num == 0:
	print(0)
elif num % 2 == 0:
	num //= 2
	ans = num
	for i in range(n):
		if ai[i] != ai[0] and ai[i] != ai[-1] and (ai[i] != ai[0] + num):
			ans = -1
			break
	print(ans)
else:
	ans = num
	for i in range(n):
		if ai[i] != ai[0] and ai[i] != ai[-1]:
			ans = -1
			break
	print(ans)


n = int(input())
ls = list(map(int, input().split()))
mn = 100000000
for i in range(-200, 201):
	d = abs(ls[0] - i)
	f = True
	for j in range(1, n):
		if d == 0:
			d = abs(i - ls[j])
			continue
		if d == abs(i - ls[j]) or ls[j] == i:
			pass
		else:
			f = False
	if f:
		mn = min(d, mn)
if mn == 100000000:
	mn = -1
print(mn)


import sys
n = input()
ls = map(int, input().split(' '))
s = set(ls)
if len(s) > 3:
	print('-1')
else:
	s = list(s)
	if len(s) <= 1:
		print('0')
	elif len(s) == 2:
		t = abs(s[0] - s[1])
		if t % 2 == 0:
			print('%s' % int(t / 2))
		else:
			print(t)
	else:
		tr = [(0, 1, 2), (1, 2, 0), (0, 2, 1)]
		ans = sys.maxsize
		for r in tr:
			t = abs(s[r[0]] - s[r[1]])
			if t % 2 == 0 and min(s[r[0]], s[r[1]]) + t / 2 == s[r[2]]:
				ans = min(ans, int(t / 2))
		if ans == sys.maxsize:
			print('-1')
		else:
			print(ans)


n = int(input())
distincts = set(map(int, input().split()))
if len(distincts) > 3:
	print(-1)
elif len(distincts) == 3:
	nums = sorted(distincts)
	d1 = nums[1] - nums[0]
	d2 = nums[2] - nums[1]
	if d2 == d1:
		print(d1)
	else:
		print(-1)
elif len(distincts) == 2:
	nums = list(distincts)
	diff = abs(nums[1] - nums[0])
	if diff % 2 == 0:
		print(diff // 2)
	else:
		print(diff)
else:
	print(0)


x = int(input())
y = [int(a) for a in input().split()]
z = []
for i in y:
	if i not in z:
		z.append(i)
z = sorted(z)
l = len(z)
if l == 1:
	print(0)
if l > 3:
	print(-1)
if l == 3:
	m = z[l // 2]
	z.remove(m)
	for i in range(101):
		a = z[0] + i
		b = z[1] - i
		if a == m and b == m:
			print(i)
			quit()
	print(-1)
elif l == 2:
	for i in range(101):
		aa = z[0]
		a = z[0] + i
		b = z[1] - i
		if a == b:
			print(i)
			quit()
		elif aa == b:
			print(i)
			quit()
	print(-1)


n = int(input())
a = list(map(int, input().split()))
diff = 1
a.sort()
for i in range(1, n):
	if a[i] != a[i - 1]:
		diff += 1
if diff == 1:
	d = 0
elif diff == 2:
	d = a[n - 1] - a[0]
	if d % 2 == 0:
		d //= 2
elif diff == 3:
	for i in range(1, n):
		if a[i] != a[i - 1]:
			break
	if a[i] - a[i - 1] == a[n - 1] - a[i]:
		d = a[i] - a[i - 1]
	else:
		d = -1
else:
	d = -1
print(d)


n = int(input())
l = list(map(int, input().split()))
m = sorted(set(l))
x = len(m)
if x > 3:
	print('-1')
elif x == 1:
	print('0')
elif x == 2:
	if (m[1] - m[0]) % 2 == 0:
		print((m[1] - m[0]) // 2)
	else:
		print(m[1] - m[0])
elif m[2] - m[1] == m[1] - m[0]:
	print(m[2] - m[1])
else:
	print('-1')


n = input()
li = list(dict.fromkeys(list(map(int, input().split()))))
n = len(li)
li.sort()
temp = max(li) + min(li)
ma = max(li)
if n == 2:
	if temp % 2 != 0:
		num = max(li) - min(li)
	else:
		temp /= 2
		num = temp - min(li)
	print(int(num))
elif temp % 2 == 0:
	temp /= 2
	num = temp - min(li)
	for i in li[1:-1]:
		if not (i == temp or i + num == temp or i - num == temp):
			print(-1)
			exit(0)
	print(int(num))
else:
	print(-1)


from sys import stdin, stdout
from collections import Counter

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

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

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
n = ip()
li = ai()
x = list(set(li))
x.sort()
if len(x) == 2:
	if (x[1] - x[0]) % 2 == 0:
		print((x[1] - x[0]) // 2)
	else:
		print(x[1] - x[0])
elif len(x) == 1:
	print(0)
elif len(x) == 3:
	if x[2] - x[1] == x[1] - x[0]:
		print(x[1] - x[0])
	else:
		print(-1)
else:
	print(-1)


from sys import stdin, exit
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().split()))
if n == 1:
	print(0)
	exit()
d = -1
for i in range(0, 101):
	flag = 1
	for j in range(len(l) - 1):
		for k in range(j + 1, len(l)):
			if abs(l[j] - l[k]) == i or abs(l[j] - l[k]) == 2 * i or l[j] - l[k] == 0:
				flag = 0
			else:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		d = i
		break
print(d)


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
arr = set(intInp())
if len(arr) > 3:
	print(-1)
else:
	arr = list(arr)
	if len(arr) == 3:
		arr.sort()
		if arr[1] - arr[0] == arr[2] - arr[1]:
			print(arr[1] - arr[0])
		else:
			print(-1)
	elif len(arr) == 2:
		arr.sort()
		if sum(arr) % 2 == 0:
			print(sum(arr) // 2 - arr[0])
		else:
			print(arr[1] - arr[0])
	else:
		print(0)


import sys

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

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

def input():
	return sys.stdin.readline().strip()

def main():
	n = int(input())
	arr = get_array()
	arr.sort()
	from collections import Counter
	d = Counter(arr)
	if len(d) == 2:
		if (arr[-1] - arr[0]) % 2 == 0:
			print((arr[-1] - arr[0]) // 2)
		else:
			print(arr[-1] - arr[0])
		return
	ans = float('inf')
	for i in range(n):
		x = arr[i]
		mn = {}
		for j in range(n):
			if i == j:
				continue
			if arr[i] == arr[j]:
				continue
			curr = abs(arr[j] - arr[i])
			mn[curr] = 1
		if len(mn) == 0:
			print(0)
			return
		if len(mn) == 1:
			for l in mn:
				ans = min(ans, l)
	if ans == float('inf'):
		print(-1)
	else:
		print(ans)
main()


from math import gcd

def gcdd(d):
	g = 0
	for i in d:
		g = gcd(g, i)
	return g
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
if len(set(l)) > 3:
	print(-1)
else:
	z = list(set(l))
	z.sort()
	if len(z) == 1:
		print(0)
		exit()
	if len(z) == 2:
		if (z[1] - z[0]) % 2 == 0:
			print((z[1] - z[0]) // 2)
		else:
			print(z[1] - z[0])
		exit()
	if z[1] - z[0] == z[2] - z[1]:
		print(z[1] - z[0])
		exit()
	else:
		print(-1)


n = int(input())
l = list(map(int, input().split()))
cont = []
for i in l:
	fl = 0
	for j in cont:
		if j == i:
			fl = 1
	if fl == 0:
		cont.append(i)
	if len(cont) > 3:
		break
cont.sort()
if len(cont) == 1:
	print(0)
elif len(cont) == 2:
	if (cont[1] - cont[0]) % 2 == 1:
		print(cont[1] - cont[0])
	else:
		print((cont[1] - cont[0]) // 2)
elif len(cont) == 3:
	if cont[0] + cont[2] == 2 * cont[1]:
		print(cont[1] - cont[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
x = list(map(int, input().split()))
sett = set(x)
list_sett = list(sett)
list_sett.sort()
flag = 0
if n == 1:
	print(0)
elif n >= 2:
	if len(sett) == 1:
		print(0)
	elif len(sett) == 2 and (list_sett[1] - list_sett[0]) % 2 == 0:
		print((list_sett[1] - list_sett[0]) // 2)
	elif len(sett) == 2 and (list_sett[1] - list_sett[0]) % 2 != 0:
		print(list_sett[1] - list_sett[0])
	elif len(sett) >= 3:
		abc = list_sett[1] - list_sett[0]
		for i in range(2, len(sett)):
			if list_sett[i] - list_sett[i - 1] != abc:
				flag = 1
				break
		if flag == 1:
			print(-1)
		elif flag == 0 and max(list(sett)) - min(list(sett)) <= 2 * abc:
			print(abc)
		else:
			print(-1)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = list(set(a))
b.sort()
l = []
for i in range(len(b) - 1):
	if b[i + 1] - b[i] != 0:
		l.append(abs(b[i + 1] - b[i]))
if len(l) == 0:
	d = 0
elif len(l) == 1 and l[0] % 2 == 0:
	d = l[0] // 2
elif len(l) <= 2:
	if len(set(l)) == 1:
		d = l[0]
	else:
		d = -1
else:
	d = -1
print(d)


n = int(input())
z = list(map(int, input().split()))
d = 0
if len(set(z)) > 1:
	while True:
		q = z[:]
		d += 1
		m = min(z) + d
		for i in range(n):
			if q[i] > m:
				q[i] -= d
			elif q[i] < m:
				q[i] += d
		if len(set(q)) == 1:
			break
		elif d > 100:
			d = -1
			break
print(d)


import sys
(n, nm, mx, mn, act, same) = (int(input()), list(), -1, 101, 0, True)
an = input().split()
for i in an:
	act = int(i)
	mx = max(mx, act)
	mn = min(mn, act)
	nm.append(act)
	if same and len(nm) > 1 and (act != nm[-2]):
		same = False
(f1, f2) = ((mx - mn) / 2, mx - mn)
(ni1, ni2) = (mn + f1, mn + f2)
(md1, md2) = (True, True)
if n == 1:
	print(0)
	sys.exit()
if same:
	print(0)
	sys.exit()
if f1 >= 0 and f1 % 1 == 0:
	f1 = int(f1)
	for j in nm:
		if j == ni1:
			continue
		elif j + f1 != ni1 and j - f1 != ni1:
			md1 = False
			break
	if md1:
		print(int(f1))
		sys.exit()
if f2 >= 0 and f2 % 1 == 0:
	for j in nm:
		if j == ni2:
			continue
		elif j + f2 != ni2 and j - f2 != ni2:
			print(-1)
			sys.exit()
	print(int(f2))
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if (a[n - 1] - a[0]) % 2 == 1:
	tem = int(a[n - 1] - a[0])
	test = True
	for i in a:
		if i != a[0] and i != a[n - 1]:
			test = False
			break
	if test:
		print(tem)
	else:
		print(-1)
else:
	tem = int((a[n - 1] - a[0]) / 2)
	test = True
	e = a[0] + tem
	for i in a:
		if i != a[0] and i != a[n - 1] and (i != e):
			test = False
			break
	if test:
		print(tem)
	else:
		print(-1)


def main():
	n = int(input())
	a = list(sorted(set(map(int, input().split()))))
	if len(a) > 3:
		print(-1)
	elif len(a) == 1:
		print(0)
	elif len(a) == 2:
		d = a[1] - a[0]
		if d & 1:
			print(d)
		else:
			print(d >> 1)
	else:
		d = a[1] - a[0]
		D = a[2] - a[1]
		if d == D:
			print(d)
		else:
			print(-1)
	return 0
main()


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	s.sort()
	if len(s) == 1:
		print(0)
	elif len(s) == 3:
		if s[2] - s[1] == s[1] - s[0]:
			print(s[2] - s[1])
		else:
			print(-1)
	elif len(s) == 2:
		if (s[1] + s[0]) % 2 == 0:
			print((s[1] + s[0]) // 2 - s[0])
		else:
			print(s[1] - s[0])
	else:
		print(-1)
solution()


n = int(input())
a = list(map(int, input().strip().split()))
b = sorted(list(set(a)))
if len(b) == 1:
	print(0)
elif len(b) == 2:
	c = (b[0] + b[1]) / 2
	if c == int(c):
		print(int(abs(c - b[0])))
	else:
		print(abs(b[0] - b[1]))
elif len(b) == 3:
	c = (b[0] + b[-1]) / 2
	if b[1] == c and abs(c) == c:
		print(abs(b[0] - int(c)))
	else:
		print(-1)
else:
	print(-1)


o = int(input())
k = [*map(int, input().split())]
p = set(k)
w = []
for i in p:
	w.append(i)
z = sorted((int(x) for x in w))
if len(z) == 3:
	if z[1] - min(z) == max(z) - z[1]:
		print((max(z) - min(z)) // 2)
	else:
		print(-1)
elif len(z) == 2:
	if (max(z) - min(z)) % 2 == 0:
		print((max(z) - min(z)) // 2)
	else:
		print(max(z) - min(z))
elif len(z) == 1:
	print(0)
elif len(z) > 3:
	print(-1)


n = int(input())
a = [int(t) for t in input().split()]
if len(set(a)) > 3:
	print(-1)
	exit()
if len(set(a)) == 1:
	print(0)
	exit()
if len(set(a)) == 2:
	c = abs(list(set(a))[0] - list(set(a))[1])
	if c % 2 == 0:
		print(c // 2)
	else:
		print(c)
	exit()
(a, b, c) = sorted(list(set(a)))
if c - b != b - a:
	print(-1)
else:
	print(c - b)


n = int(input())
l = list(map(int, input().split()))
l = set(l)
l = list(l)
l.sort()
ln = len(l)
if ln == 1:
	print('0')
elif ln == 2:
	dif = abs(l[0] - l[1])
	if dif % 2 == 0:
		print(dif // 2)
	else:
		print(dif)
elif ln == 3:
	m = l[1]
	dif1 = abs(l[0] - l[1])
	dif2 = abs(l[1] - l[2])
	if dif1 == dif2:
		if dif1 + l[0] == l[1] and l[2] - dif1 == l[1]:
			print(dif1)
		else:
			print('-1')
	else:
		print('-1')
else:
	print('-1')


from functools import reduce
num = input()
input_array = list(map(int, input().split()))
input_array.sort(reverse=False)
array = list(set(input_array))
array.sort(reverse=False)
averages = int(reduce(lambda a, b: a + b, array) / len(array))
if int(len(array)) > 3:
	print(-1)
elif int(len(array)) == 3:
	if array[2] - array[1] == array[1] - array[0]:
		print(int(array[1] - array[0]))
	else:
		print(-1)
elif int(len(array)) == 2:
	if (array[1] - array[0]) % 2 == 0:
		print(int((array[1] - array[0]) / 2))
	else:
		print(int(array[1] - array[0]))
else:
	print(0)


n = int(input())
nums = list(map(int, input().split()))
ds = []
for i in range(1, 101):
	d = abs(i - nums[0])
	ok = True
	for num in nums[1:]:
		if num != i:
			if d == 0:
				d = abs(num - i)
			elif abs(num - i) != d:
				ok = False
				break
	if ok:
		ds.append(d)
if len(ds) == 0:
	print(-1)
else:
	print(min(ds))


n = int(input())
a = list(map(int, input().split()))
a.sort()
d = (a[-1] - a[0]) // 2
d1 = a[-1] - a[0]
b = 0
c = 0
for i in range(len(a)):
	if ((a[i] != a[0] and a[i] + d != a[0]) and a[i] - d != a[0]) and ((a[i] != a[0] + d and a[i] + d != a[0] + d) and a[i] - d != a[0] + d):
		b = -1
	if ((a[i] != a[0] and a[i] + d1 != a[0]) and a[i] - d1 != a[0]) and ((a[i] != a[0] + d1 and a[i] + d1 != a[0] + d1) and a[i] - d1 != a[0] + d1):
		c = -1
if b != -1:
	print(d)
elif c != -1:
	print(d1)
else:
	print(-1)


n = int(input())
ar = list(map(int, input().strip().split()))
arset = list(set(ar))
arset.sort()
if len(arset) < 3:
	if len(arset) == 1:
		print(0)
	elif (arset[0] - arset[1]) % 2 == 0:
		print(abs(arset[0] - arset[1]) // 2)
	else:
		print(abs(arset[0] - arset[1]))
elif len(arset) == 3:
	if arset[0] + arset[2] == 2 * arset[1]:
		print(abs(arset[2] - arset[1]))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
numbers = [int(i) for i in input().split()]
maxnum = -1
minnum = int(numbers[0])
for i in range(n):
	if int(numbers[i]) > maxnum:
		maxnum = int(numbers[i])
for i in range(n):
	if int(numbers[i]) < minnum:
		minnum = int(numbers[i])
if minnum == maxnum:
	print(0)
else:
	flag = 0
	for i in range(n):
		if int(numbers[i]) != maxnum and int(numbers[i]) != minnum:
			flag = -1
	if flag == 0:
		if (maxnum + minnum) % 2 == 0:
			print(maxnum - (maxnum + minnum) // 2)
		else:
			print(maxnum - minnum)
	elif (maxnum + minnum) % 2 == 0:
		mid = (maxnum + minnum) // 2
		for i in range(n):
			if int(numbers[i]) != maxnum and int(numbers[i]) != minnum and (int(numbers[i]) != mid):
				flag = 1
		if flag == 1:
			print(-1)
		else:
			print(maxnum - mid)
	else:
		print(-1)


N = int(input())
a_list = list(map(int, input().split()))
a_set = set(a_list)
b_list = list(a_set)
b_list.sort()
if len(b_list) > 3:
	print(-1)
elif len(b_list) == 3:
	mid = b_list[1]
	if abs(mid - b_list[0]) == abs(mid - b_list[2]):
		for a in a_list:
			if a in b_list:
				continue
			else:
				print(-1)
				exit()
		print(mid - b_list[0])
	else:
		print(-1)
elif len(b_list) == 2:
	if (b_list[1] - b_list[0]) % 2 == 0:
		print((b_list[1] - b_list[0]) // 2)
	else:
		print(b_list[1] - b_list[0])
else:
	for a in a_list:
		if b_list[0] == a:
			continue
		else:
			print(-1)
			exit()
	print(0)


n = int(input())
l = input().split()
for i in l:
	l[l.index(i)] = int(i)
l.sort()
(a, b) = (l[0], l[-1])
s = b - a
l2 = set(l)
if len(l2) > 3:
	print(-1)
elif len(l2) == 3 and s % 2 == 0:
	car = l[0]
	car1 = 0
	for i in l:
		if i != car:
			car1 = i
			break
	if car1 == s // 2 + car and s % 2 == 0 and (s // 2 >= 0):
		print(s // 2)
	else:
		print(-1)
elif len(l2) == 2:
	d = s
	if d >= 0:
		if d % 2 == 0:
			print(d // 2)
		else:
			print(d)
	else:
		print(-1)
elif len(l2) == 1:
	print(0)
else:
	print(-1)


input()
n = list({int(x) for x in input().split()})
if len(n) == 1:
	print('0')
elif len(n) > 3:
	print('-1')
elif len(n) == 2:
	if abs(n[0] - n[1]) % 2 == 0:
		print(abs(n[0] - n[1]) // 2)
	else:
		print(abs(n[0] - n[1]))
else:
	n = sorted(n)
	if n[2] - n[1] == n[1] - n[0]:
		print(n[2] - n[1])
	else:
		print('-1')


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
import re
pattern = '0+'
n = int(input())
nums = list(map(int, input().split()))

def check(c, nums):
	(mi, ma) = (min(nums), max(nums))
	poss = [mi, ma, ma - c, mi + c, mi - c, ma + c]
	for j in poss:
		flag = True
		for i in nums:
			if i + c != j and i - c != j and (i != j):
				flag = False
				break
		if flag:
			return True
	return False
got = False
for val in range(100):
	if check(val, nums):
		print(val)
		got = True
		break
if not got:
	print(-1)


from sys import stdin, stdout
n = int(stdin.readline())
Arr = list(map(int, stdin.readline().split()))
myArr = list(set(Arr))
myArr.sort()
if len(myArr) > 3:
	print(-1)
elif len(myArr) == 3:
	if myArr[2] - myArr[1] == myArr[1] - myArr[0]:
		print(myArr[1] - myArr[0])
	else:
		print(-1)
elif len(myArr) == 2:
	if (myArr[1] - myArr[0]) % 2 == 0:
		print((myArr[1] - myArr[0]) // 2)
	else:
		print(myArr[1] - myArr[0])
else:
	print(0)


def find(arr):
	s = min(arr)
	b = max(arr)
	if (b - s) % 2 == 1:
		D = b - s
		for val in arr:
			if val != s and val != b:
				return -1
		return D
	D = int((b - s) / 2)
	for val in arr:
		if val != s and val != b and (val != s + D):
			return -1
	return D

def main():
	n = int(input())
	arr = input().split(' ')
	arr = [int(arr[i]) for i in range(n)]
	print(find(arr))
main()


n = int(input())
arr = list(map(int, input().strip().split(' ')))
three = []
for i in arr:
	if len(three) > 3:
		break
	if i not in three:
		three.append(i)
three.sort()
if len(three) == 3 and three[1] - three[0] == three[2] - three[1]:
	print(three[1] - three[0])
elif len(three) == 2 and (three[1] - three[0]) % 2 == 0:
	print(int((three[1] - three[0]) / 2))
elif len(three) == 2 and (three[1] - three[0]) % 2:
	print(three[1] - three[0])
elif len(three) == 1:
	print(0)
else:
	print(-1)


n = int(input())
a = {int(x) for x in input().split()}
if len(a) > 3:
	print(-1)
elif len(a) == 3:
	al = list(a)
	al.sort()
	if al[0] + al[2] != al[1] * 2:
		print(-1)
	else:
		print(al[2] - al[1])
elif len(a) == 2:
	x = a.pop()
	y = a.pop()
	if (x + y) % 2 != 0:
		print(abs(x - y))
	else:
		print(abs(x - y) // 2)
else:
	print(0)


n = int(input())
array = list(map(int, input().split()))
brray = sorted(list(set(array)))
if len(brray) == 1:
	output = 0
elif len(brray) == 2:
	output = brray[1] - brray[0]
	if output % 2 == 0:
		output = int(output / 2)
elif len(brray) == 3 and brray[2] - brray[1] == brray[1] - brray[0]:
	output = brray[2] - brray[1]
else:
	output = -1
print(output)


a = int(input())
x = input()
y = list(map(int, x.split(' ')))
y.sort()
u = []
for i in y:
	if i not in u:
		u.append(i)
if len(u) == 1:
	print(0)
elif len(u) == 2:
	if (max(y) - min(y)) % 2 == 0:
		print((max(y) - min(y)) // 2)
	else:
		print(max(y) - min(y))
elif len(u) == 3:
	if u[2] - u[1] == u[1] - u[0]:
		print(u[1] - u[0])
	else:
		print(-1)
elif len(u) > 3:
	print(-1)


input()
arr = list(map(int, input().split()))
arr.sort()
brr = list(set(arr))
brr.sort()
if len(brr) == 1:
	print(0)
elif len(brr) == 2:
	if (brr[1] - brr[0]) % 2 == 0:
		print((brr[1] - brr[0]) // 2)
	else:
		print(brr[1] - brr[0])
elif len(brr) == 3:
	if brr[0] + brr[2] == 2 * brr[1]:
		print(brr[1] - brr[0])
	else:
		print(-1)
else:
	print(-1)


input()
number = sorted(list(set(list(map(int, input().split())))))
if len(number) > 3:
	print('-1')
if len(number) == 3 and (not (number[0] + number[2]) / 2 == number[1]):
	print(-1)
	exit()
if len(number) == 3:
	print(number[1] - number[0])
if len(number) == 2:
	if ((number[1] - number[0]) / 2).is_integer():
		print(int((number[1] - number[0]) / 2))
	else:
		print(number[1] - number[0])
if len(number) == 1:
	print(0)


n = int(input())
data = [int(i) for i in input().split()]
s = sorted(list(set(data)))
k = len(s)
if k == 1:
	print(0)
elif k == 2:
	maybe = []
	if (s[1] - s[0]) % 2 == 0:
		maybe.append((s[1] - s[0]) // 2)
	else:
		maybe.append(s[1] - s[0])
	print(min(maybe))
elif k == 3:
	if s[1] - s[0] == s[2] - s[1]:
		print(s[1] - s[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
b = [int(i) for i in input().split()]
b.sort()
arr = []
for i in b:
	if i not in arr:
		arr.append(i)
if len(arr) > 3:
	print(-1)
elif len(arr) == 3:
	res = -1
	for j in range(1, len(arr)):
		if res == -1:
			res = arr[j] - arr[j - 1]
		elif arr[j] - arr[j - 1] != res:
			res = -1
			break
	print(res)
elif len(arr) == 2:
	if (arr[1] - arr[0]) % 2 == 0:
		print((arr[1] - arr[0]) // 2)
	else:
		print(arr[1] - arr[0])
elif len(arr) == 1:
	print(0)
else:
	print(-1)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
n = int(z())
l = sorted(set(list(map(int, z().split()))))
if len(l) == 1:
	print(0)
	exit(0)
if len(l) > 3:
	print(-1)
	exit(0)
t = []
for i in l:
	for j in l:
		t.append(abs(i - j))
p = list(set(t))
for i in range(0, max(p) + 1):
	l1 = l[:]
	for j in range(len(l) - 1):
		t = j + 1
		if l1[j] + i == l1[t]:
			l1[j] += i
		elif l1[j] + i == l1[t] - i:
			l1[j] += i
			l1[t] -= i
	if len(set(l1)) == 1:
		print(i)
		exit(0)
if len(l) == 3:
	(a, b, c) = l
	if abs(a - b) == abs(b - c):
		print(abs(a - b))
		exit()
print(-1)


n = int(input())
l = set(map(int, input().split()))
if len(l) > 3:
	print(-1)
elif len(l) == 3:
	if max(l) - min(l) & 1:
		print(-1)
	else:
		a = (max(l) - min(l)) // 2
		if min(l) + a in l:
			print(a)
		else:
			print(-1)
elif max(l) - min(l) & 1:
	print(max(l) - min(l))
else:
	print((max(l) - min(l)) // 2)


import sys
import math
import time
c = int(input())
a = [int(j) for j in input().split()]
l = sorted(list(set(a)))
d = len(l)
if d > 3:
	print('-1')
	exit()
elif d == 1:
	print('0')
elif d == 2:
	if (l[1] - l[0]) % 2 == 0:
		print(int(abs((l[1] - l[0]) / 2)))
	else:
		print(l[1] - l[0])
elif l[2] - l[1] == l[1] - l[0]:
	print(l[2] - l[1])
else:
	print('-1')


import sys

def solve(seq):
	if len(seq) <= 1:
		return 0
	d = abs(seq[1] - seq[0])
	candidates = []
	if d % 2 == 0:
		candidates.append((seq[0] + d // 2, d // 2))
	candidates.extend([(seq[0], d), (seq[1], d)])
	tail = seq[2:]
	for (val, dif) in candidates:
		for x in tail:
			if x != val and abs(x - val) != dif:
				break
		else:
			return dif
	return -1

def solve2(seq):
	uniq = sorted(set(seq))
	if len(uniq) <= 1:
		return 0
	d = uniq[1] - uniq[0]
	if len(uniq) == 2:
		if d % 2 == 0:
			return d // 2
		else:
			return d
	if len(uniq) == 3:
		if uniq[2] - uniq[1] == d:
			return d
	return -1
n = 0
seq = None
for line in sys.stdin:
	if n == 0:
		n = int(line)
	else:
		seq = list(map(int, line.split()))
		break
print(solve2(seq))


n = input()
s = list(map(int, input().split()))
s = set(s)
s = list(s)
s.sort()
if len(s) > 3:
	print(-1)
elif len(s) == 1:
	print(0)
elif len(s) == 2:
	if (max(s) - min(s)) % 2 == 0:
		print((max(s) - min(s)) // 2)
	else:
		print(max(s) - min(s))
elif len(s) == 3:
	if (max(s) - min(s)) % 2 == 0 and min(s) + (max(s) - min(s)) // 2 in s:
		print((max(s) - min(s)) // 2)
	else:
		print(-1)


n = int(input())
arr = set(map(int, input().split()))
if len(arr) > 3:
	print('-1')
elif len(arr) == 3:
	a = max(arr)
	arr.remove(a)
	b = min(arr)
	arr.remove(b)
	if (a + b) // 2 == max(arr) and (a + b) % 2 == 0:
		print(max(arr) - b)
	else:
		print('-1')
elif len(arr) == 2:
	if (min(arr) + max(arr)) % 2 == 0:
		print((min(arr) + max(arr)) // 2 - min(arr))
	else:
		print(max(arr) - min(arr))
else:
	print('0')


n = int(input())
l = sorted(list(map(int, input().split())))
s = []
for i in range(n):
	if l[i] not in s:
		s.append(l[i])
if len(s) == 1:
	print(0)
elif len(s) == 2:
	if (s[1] - s[0]) % 2 == 0:
		print((s[1] - s[0]) // 2)
	else:
		print(s[1] - s[0])
elif len(s) == 3:
	if s[1] - s[0] == s[2] - s[1]:
		print(s[1] - s[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l = sorted(list(set(map(int, input().split()))))
if len(l) == 1:
	print(0)
elif len(l) == 2:
	if l[0] % 2 == l[1] % 2:
		print(min(l[1] - (l[0] + l[1]) // 2, l[1] - l[0]))
	else:
		print(l[1] - l[0])
elif len(l) == 3:
	if l[0] % 2 == l[2] % 2 and (l[0] + l[2]) // 2 == l[1]:
		print(l[2] - (l[0] + l[2]) // 2)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
r = [a[i] for i in range(len(a))]
r = list(set(r))
r.sort()
if len(r) == 1:
	print(0)
elif len(r) > 3:
	print(-1)
elif len(r) == 2:
	r.sort()
	z1 = r[0]
	z2 = r[-1]
	y = z2 - z1
	print(y // 2 if y % 2 == 0 else y)
else:
	z1 = r[1] - r[0]
	z2 = r[2] - r[1]
	if z1 == z2:
		print(z1)
	else:
		print(-1)


n = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] != A[-1]:
	for d in range(202):
		w = False
		if A[0] + d == A[-1]:
			w = True
			for i in range(n):
				if A[i] + d != A[-1] and A[i] != A[-1]:
					w = False
					break
		if w:
			print(d)
			exit()
		if A[0] + d == A[-1] - d:
			w = True
			for i in range(n):
				if A[i] + d != A[-1] - d and A[i] != A[-1] - d and (A[i] - d != A[-1] - d):
					w = False
					break
		if w:
			print(d)
			exit()
	print(-1)
	exit()
print(0)


def trynr(val, x):
	pos = {val, val - x, val + x}
	for el in ls:
		if el not in pos:
			return False
	return True
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, ls) = (ii(), sorted(ll()))
minv = -1
if ls[0] == ls[-1]:
	print(0)
	exit()
v = ls[-1] - ls[0]
if trynr(ls[0], v) or trynr(ls[-1], v):
	minv = v
if v & 1 == 0:
	v2 = v // 2
	if trynr((ls[0] + ls[-1]) // 2, v2):
		if minv == -1 or v2 < minv:
			minv = v2
print(minv)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = Counter(a)
la = len(a)
if la == 1:
	print(0)
elif len(a) > 3:
	print(-1)
else:
	a = sorted(list(a.keys()))
	if la == 3:
		if a[1] - a[0] == a[2] - a[1]:
			print(a[1] - a[0])
		else:
			print(-1)
	else:
		diff = a[1] - a[0]
		if diff % 2 == 0:
			print(diff // 2)
		else:
			print(diff)


n = int(input())
li = [int(x) for x in input().split()]
se = set(li)
l = len(se)
if l > 3:
	print(-1)
else:
	li1 = list(se)
	li1.sort()
	if l == 3:
		s = li1[2] + li1[0]
		if s % 2 == 0:
			quo = s // 2
			if li1[1] == quo:
				print(quo - li1[0])
			else:
				print(-1)
		else:
			print(-1)
	elif l == 2:
		dif1 = li1[1] - li1[0]
		s = li1[0] + li1[1]
		if s % 2 == 0:
			quo = s // 2
			dif2 = quo - li1[0]
			print(min(dif1, dif2))
		else:
			print(dif1)
	else:
		print(0)


n = input()
data = set(map(int, input().split()))
num = sorted(data)
if len(num) > 3:
	print(-1)
elif len(num) == 3:
	if num[1] - num[0] == num[2] - num[1]:
		print(num[1] - num[0])
	else:
		print(-1)
elif len(num) == 2:
	if (num[1] - num[0]) % 2 == 0:
		print(int((num[1] - num[0]) // 2))
	else:
		print(num[1] - num[0])
else:
	print(0)


def canEqualise(array):
	uniques = sorted(set(array))
	if len(uniques) == 1:
		print(0)
	elif len(uniques) == 2:
		if (uniques[1] - uniques[0]) % 2 == 0:
			print(int((uniques[1] - uniques[0]) / 2))
		else:
			print(uniques[1] - uniques[0])
	elif len(uniques) == 3:
		if uniques[2] - uniques[1] == uniques[1] - uniques[0]:
			X = uniques[2] - uniques[1]
			print(X)
		else:
			print(-1)
	else:
		print(-1)
n = int(input())
str = input().split(' ')
array = [int(x) for x in str]
canEqualise(array)


from collections import Counter
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
diff = 0
new = 0
count = Counter(arr).keys()
if len(count) == 2:
	for i in range(n):
		if arr[i] != arr[i + 1]:
			diff = arr[i + 1] - arr[i]
			break
	if diff % 2 == 0:
		diff = int(diff / 2)
elif len(count) == 3:
	for i in range(n - 1):
		if arr[i + 1] != arr[i]:
			diff = arr[i + 1] - arr[i]
			break
	for j in range(n - 1):
		if arr[j + 1] - arr[j] != diff:
			if arr[j] == arr[j + 1]:
				continue
			else:
				new = -1
				break
	if new == -1:
		diff = -1
elif len(count) == 1:
	diff = 0
else:
	diff = -1
print(diff)


n = int(input())
X = [int(x) for x in input().split(' ')]
s = list(set(X))
s.sort()
if len(s) == 1:
	print(0)
elif len(s) == 2:
	diff = s[1] - s[0]
	if diff % 2 == 0:
		print(int(diff / 2))
	else:
		print(diff)
elif len(s) == 3:
	if (s[0] + s[-1]) / 2 == s[1]:
		print(s[1] - s[0])
	else:
		print(-1)
elif len(s) > 3:
	print(-1)


n = int(input())
numbers = list(map(int, input().split()))
big = 0
small = 101
for i in numbers:
	big = max(big, i)
	small = min(small, i)
possible = True
if big == small:
	print(0)
elif (big + small) % 2 != 0:
	for i in numbers:
		if i != big and i != small:
			possible = False
			break
	if possible:
		print(big - small)
	else:
		print(-1)
else:
	medium = (big + small) // 2
	for i in numbers:
		if i != big and i != small and (i != medium):
			possible = False
			break
	if possible:
		print(big - medium)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
m = min(a)
M = max(a)
d = M - m
dd = 0
if d % 2 == 0:
	dd = (M - m) // 2
flag1 = True
for i in range(n):
	if a[i] == m or a[i] == M:
		pass
	else:
		flag1 = False
		break
flag2 = True
for i in range(n):
	if a[i] - m == dd or a[i] - m == 0 or a[i] - M == dd or (a[i] - M == 0):
		pass
	else:
		flag2 = False
		break
if flag1 and flag2 and (dd != 0):
	print(dd)
elif flag1:
	print(d)
elif flag2:
	print(dd)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
for i in range(0, n):
	a[i] = a[i] + 100
ans = -1
for d in range(0, 101):
	cnts = [0 for _ in range(0, 301)]
	for i in range(0, n):
		if d != 0:
			cnts[a[i] - d] += 1
			cnts[a[i] + d] += 1
		cnts[a[i]] += 1
	for i in cnts:
		if i == n:
			ans = d
	if ans == d:
		break
print(ans)


n = int(input())
ar = list(map(int, input().split()))
flag = True
ar1 = sorted(list(set(ar)))
if len(ar1) > 3:
	ans = -1
	flag1 = False
elif len(ar1) == 1:
	ans = 0
elif len(ar1) == 2:
	p = sum(ar1) // 2
	if sum(ar1) % 2 == 0:
		ans = min(abs(ar1[0] - p), abs(ar1[1] - p))
	else:
		ans = abs(ar1[1] - ar1[0])
elif abs(ar1[0] - ar1[1]) == abs(ar1[1] - ar1[2]):
	ans = abs(ar1[0] - ar1[1])
else:
	ans = -1
if flag:
	print(ans)
else:
	print(-1)


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
s = (l[0] + l[n - 1]) // 2
if s * 2 == l[0] + l[n - 1]:
	a = abs(l[n - 1] - s)
	c = a
	for i in range(n - 1):
		if l[i] != s:
			if abs(l[i] - s) != c:
				c = -1
				break
	print(c)
else:
	c = 0
	for i in range(n - 1):
		if c == 0:
			if l[i] != l[n - 1]:
				c = abs(l[i] - l[n - 1])
		elif l[i] != l[n - 1]:
			if abs(l[i] - l[n - 1]) != c:
				c = -1
				break
	print(c)


n = int(input())
arr = list(map(int, input().split()))
(ma, mi) = (max(arr), min(arr))
diff = ma - mi
if diff % 2 == 0:
	for val in arr:
		if val != ma and val != mi and (val != mi + diff // 2):
			print(-1)
			exit(0)
	print(diff // 2)
else:
	for val in arr:
		if val != ma and val != mi:
			print(-1)
			exit(0)
	print(diff)


import sys

def FILEIO():
	try:
		sys.stdin = open('in.in', 'r')
	except:
		pass
FILEIO()

def End(x):
	print(x)
	sys.exit()
input()
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
if len(a) > 3:
	End(-1)
if len(a) == 3:
	if a[2] - a[1] != a[1] - a[0]:
		End(-1)
	End(a[2] - a[1])
if len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		End((a[1] - a[0]) // 2)
	End(a[1] - a[0])
End(0)


def solve(nums):
	if len(nums) > 3:
		return -1
	if len(nums) < 2:
		return 0
	n = sorted(list(nums))
	if len(nums) == 2:
		d = n[1] - n[0]
		return d if d % 2 else d // 2
	if n[1] - n[0] == n[2] - n[1]:
		return n[1] - n[0]
	return -1
input()
nums = set(map(int, input().split()))
print(solve(nums))


N = int(input())
arr = input()
arr = [int(x) for x in arr.split(' ')]
freq = {}
count = 0
for num in arr:
	if num not in freq:
		count += 1
		freq[num] = 1
if count == 1:
	print(0)
elif count == 2:
	num = [0, 0]
	k = 0
	for key in freq:
		num[k] = key
		k += 1
	num.sort()
	if (num[1] - num[0]) % 2 == 0:
		print((num[1] - num[0]) // 2)
	else:
		print(num[1] - num[0])
elif count == 3:
	num = [0, 0, 0]
	k = 0
	for key in freq:
		num[k] = key
		k += 1
	num.sort()
	if num[1] - num[0] != num[2] - num[1]:
		print(-1)
	else:
		print(num[1] - num[0])
else:
	print(-1)


n = int(input())
A = list(map(int, input().split()))
A.sort()
l = A[0]
r = A[-1]
if l == r:
	print(0)
elif (r + 1 - l) % 2 == 0:
	target = A[-1] - A[0]
	if len(set(A)) > 2:
		print(-1)
	else:
		print(target)
else:
	target = (r - l) // 2
	value = A[0] + target
	condn = True
	for i in set(A):
		if i == value or i == A[0] or i == A[-1]:
			pass
		else:
			condn = False
			break
	if condn:
		print(target)
	else:
		print(-1)


n = int(input())
l = list(set([int(x) for x in input().split()]))
l.sort()
if len(l) > 3:
	print(-1)
elif len(l) == 3:
	if l[1] + l[1] == l[0] + l[2]:
		print(l[1] - l[0])
	else:
		print(-1)
elif len(l) == 2:
	d = l[1] - l[0]
	if d % 2 == 0:
		print(d // 2)
	else:
		print(d)
else:
	print(0)


n = int(input())
a = [int(i) for i in input().split()]
d = -1
b = [0] * 101
c = []
for i in range(n):
	b[a[i]] = 1
for i in range(len(b)):
	if b[i] == 1:
		c.append(i)
if len(c) == 3:
	c.sort()
	if 2 * c[1] == c[0] + c[2]:
		d = c[1] - c[0]
elif len(c) == 2:
	if (c[0] + c[1]) % 2 == 0:
		d = abs((c[0] - c[1]) // 2)
	else:
		d = abs(c[0] - c[1])
elif len(c) == 1:
	d = 0
print(d)


def main():
	_ = int(input())
	a = sorted(set(list(map(int, input().split()))))
	if len(a) == 1:
		if a[0] >= 0:
			print(0)
		else:
			print(-a[0])
	elif len(a) == 2:
		d = a[1] - a[0]
		if d % 2 == 0:
			print(d // 2)
		else:
			print(d)
	elif len(a) == 3 and a[1] - a[0] == a[2] - a[1]:
		print(a[1] - a[0])
	else:
		print(-1)
main()


n = int(input())
nums = list(map(int, input().split()))
if len(nums) == 1:
	print(0)
else:
	maxnum = nums.pop(nums.index(max(nums)))
	minnum = nums.pop(nums.index(min(nums)))
	dif = maxnum - minnum
	if dif % 2 == 0:
		dif = (maxnum - minnum) // 2
		poscomum = (maxnum + minnum) // 2
		for num in nums:
			if num != maxnum and num != minnum and (num != poscomum):
				dif = -1
		print(dif)
	else:
		for num in nums:
			if num != maxnum and num + dif != maxnum:
				dif = -1
		print(dif)


def input_ints():
	return [int(x) for x in input().split()]

def solve(xs):
	xs = set(xs)
	if len(xs) > 3:
		return -1
	if len(xs) == 1:
		return 0
	if len(xs) == 2:
		(a, b) = sorted(xs)
		if (b - a) % 2 == 0:
			return (b - a) // 2
		else:
			return b - a
	if len(xs) == 3:
		(a, b, c) = sorted(xs)
		if (c + a) % 2 == 0 and (c + a) // 2 == b:
			return (c - a) // 2
		return -1
input()
xs = input_ints()
print(solve(xs))


t = int(input())
l = list(set(map(int, input().split())))
l.sort()
if len(l) == 1:
	print(0)
elif len(l) == 2:
	if (l[1] - l[0]) % 2 == 0:
		print((l[1] - l[0]) // 2)
	else:
		print(l[1] - l[0])
elif len(l) == 3 and l[1] - l[0] == l[2] - l[1]:
	print(l[1] - l[0])
else:
	print(-1)


length = int(input())
nums = sorted(set(map(int, input().split())))
if len(nums) == 3 and nums[1] - nums[0] == nums[2] - nums[1] or (len(nums) == 2 and (nums[1] - nums[0]) % 2 == 1):
	print(nums[1] - nums[0])
elif len(nums) == 1:
	print(0)
elif len(nums) == 2 and (nums[1] - nums[0]) % 2 == 0:
	print(int((nums[1] - nums[0]) / 2))
else:
	print(-1)


n = int(input())
a = sorted(list(set(list(map(int, input().split(' '))))))
v = set()
if len(a) == 1:
	print(0)
	exit(0)
if len(a) == 2:
	if (a[1] - a[0]) % 2 != 0:
		print(a[1] - a[0])
	else:
		print(int((a[1] - a[0]) / 2))
	exit(0)
diff = a[1] - a[0]
result = diff
levels = [a[0], a[0] + diff, a[0] - diff]
for x in range(1, len(a)):
	if a[x] + diff not in levels and a[x] - diff not in levels:
		result = -1
		break
print(result)


n = int(input())
a = list(map(int, input().split()))
s = set(a)
if n == 1 or len(s) == 1:
	print(0)
else:
	s = sorted(s)
	if len(s) == 2:
		av = sum(s) / 2
		if av == int(av):
			print(s[1] - int(av))
		else:
			print(s[1] - s[0])
	elif len(s) == 3 and s[2] - s[1] == s[1] - s[0]:
		print(s[2] - s[1])
	else:
		print(-1)


import math
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
if len(a) == 1:
	print(0)
else:
	for i in range(1, 101):
		flag = True
		su = a[0] + i
		prin = False
		for j in range(1, len(a)):
			if a[j] + i != su and a[j] - i != su and (a[j] != su):
				flag = False
				break
		if flag:
			print(i)
			prin = True
			break
	if not prin:
		print(-1)


test = int(input())
list = list(map(int, input().split()))
list.sort()
a = list[-1] - list[0]
b = a // 2 if a % 2 == 0 else a
extra = b + list[0]
flag = False
for i in list[1:]:
	if i + b != extra and i - b != extra and (i != extra):
		flag = True
		break
if flag:
	print(-1)
elif a % 2 == 0:
	print(a // 2)
else:
	print(a)


n = int(input())
a = sorted(map(int, input().split()))
s = set(a)
if len(s) == 1:
	print(0)
elif len(s) == 2:
	mx = max(s)
	mn = min(s)
	if (mx - mn) % 2 == 0:
		print(int((mx - mn) // 2))
	else:
		print(mx - mn)
elif len(s) == 3:
	tp = sorted(list(s))
	if tp[2] - tp[1] != tp[1] - tp[0]:
		print(-1)
	else:
		print(tp[2] - tp[1])
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
h = 0
if (max(a) - min(a)) % 2 == 0:
	tb = (max(a) - min(a)) // 2
else:
	tb = max(a) - min(a)
pivot = min(a) + tb
for i in range(n):
	if (a[i] + tb != pivot) & (a[i] - tb != pivot) & (a[i] != pivot):
		print('-1')
		h = 1
		break
if h == 0:
	print(tb)


numero = input().split()
listaNumero = [int(x) for x in input().split()]
listaNumero.sort()
diferenca = 0
contador = 0
if len(listaNumero) == 2:
	a = (listaNumero[1] - listaNumero[0]) / 2
	if a % 1 != 0:
		print(listaNumero[1] - listaNumero[0])
		quit()
	else:
		print(int(a))
		quit()
for i in range(len(listaNumero) - 1):
	if listaNumero[i] - listaNumero[i + 1] != 0:
		diferenca = listaNumero[i + 1] - listaNumero[i]
		break
if diferenca == 0:
	print(0)
	quit()
for i in range(len(listaNumero) - 1):
	if listaNumero[i + 1] - listaNumero[i] == diferenca:
		contador += 1
	if listaNumero[i + 1] - listaNumero[i] != diferenca and listaNumero[i] - listaNumero[i + 1] != 0:
		print('-1')
		quit()
if contador == 1:
	a = diferenca / 2
	if a % 1 != 0:
		print(diferenca)
		quit()
	else:
		print(int(a))
		quit()
if contador > 2:
	print(-1)
	quit()
print(diferenca)


def game(l, x):
	k = 0
	leng = len(l)
	while k < leng and l[k] == x:
		k += 1
	c = 0
	if k >= leng:
		return 0
	else:
		c = abs(l[k] - x)
	for i in l:
		if i == x:
			continue
		if abs(i - x) != c:
			return -1
	return c
n = int(input())
l = list(map(int, input().split()))
ans = 10000001
for i in range(1, 102):
	temp = game(l, i)
	if temp > -1:
		ans = min(ans, temp)
if ans < 10000001:
	print(ans)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
res = 0
s = max(a) - min(a)
if s % 2 == 0:
	s //= 2
md = max(a) - s
c = 1
for q in a:
	if q + s == md or q - s == md or q == md:
		pass
	else:
		res = -1
		c = 0
if res == -1:
	print(-1)
else:
	print(int(s))


def max(a, b, c):
	if a > b:
		(b, a) = (a, b)
	if b > c:
		(b, c) = (c, b)
	if a > b:
		(a, b) = (b, a)
	return (a, b, c)
input()
A = set(map(int, input().split()))
A = list(A)
if len(A) == 1:
	print(0)
elif len(A) == 2:
	if abs(A[0] + A[1]) % 2 == 0:
		print(abs(A[0] - A[1]) // 2)
	else:
		print(abs(A[0] - A[1]))
elif len(A) == 3:
	(a, b, c) = max(A[0], A[1], A[2])
	if (c + a) % 2 == 0 and (c + a) // 2 == b:
		print((c - a) // 2)
	else:
		print(-1)
else:
	print(-1)


import sys
sys_input = sys.stdin.readline

def si():
	return sys_input().rstrip()

def ii():
	return int(si())

def sti():
	return si().split()

def iti():
	return map(int, sti())

def sli():
	return list(si())

def ili():
	return list(iti())

def main():
	set_a = list(set(A))
	if len(set_a) > 3:
		print(-1)
		return
	set_a.sort()
	if len(set_a) == 3:
		if (set_a[-1] + set_a[0]) / 2 == set_a[1]:
			print(set_a[1] - set_a[0])
			return
		else:
			print(-1)
			return
	if len(set_a) == 2:
		if (set_a[1] - set_a[0]) % 2 == 0:
			print((set_a[1] - set_a[0]) // 2)
		else:
			print(set_a[1] - set_a[0])
		return
	if len(set_a) == 1:
		print(0)
		return
	return
N = ii()
A = ili()
main()


from collections import *

def give(a):
	(first, second) = (0, 0)
	for (ind, i) in enumerate(a):
		if not ind:
			first = i
		else:
			second = i
			return [first, second]
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
temp = a
a = Counter(a)
if len(a) == 1:
	print(0)
	exit(0)
temp = list(set(temp))
temp.sort()
ab = temp[-1] - temp[0]
(ar, ay) = give(a)
if len(a) > 3 or (len(a) == 3 and ar + ab // 2 != ay):
	print(-1)
	exit(0)
if len(a) == 3:
	print(ab // 2 if len(a) == 3 and ab // 2 == ab / 2 else -1)
else:
	print(ab // 2 if len(a) == 2 and ab & 1 == 0 else ab)


n = int(input())
x = list(input().rstrip().split())
x = list(set(x))
for i in range(len(x)):
	x[i] = int(x[i])
if len(x) > 3:
	print(-1)
elif len(x) == 2:
	m = abs(x[0] - x[1])
	if m % 2 == 0:
		m //= 2
	print(m)
elif len(x) == 1:
	print(0)
else:
	t = (x[0] + x[1] + x[2]) / 3
	if t in x:
		if x[0] != t:
			print(int(abs(x[0] - t)))
		elif x[2] != t:
			print(int(abs(x[2] - t)))
		elif x[1] != t:
			print(int(abs(x[1] - t)))
	else:
		print(-1)


import math
n = input()
a = list(map(lambda x: int(x), input().split()))
a_min = min(a)
a_max = max(a)
isFind = False
ans = math.inf
for i in range(a_min, a_max + 1):
	diff = 0
	flag = True
	for j in a:
		if j - i == 0:
			continue
		elif diff == 0:
			diff = abs(i - j)
		elif abs(j - i) != diff:
			flag = False
			break
	if flag:
		ans = min(ans, diff)
		isFind = True
if not isFind:
	print(-1)
else:
	print(ans)


n = int(input())
arr = sorted(list(map(int, input().split())))
if (arr[-1] - arr[0]) % 2 == 0:
	d = (arr[-1] - arr[0]) // 2
	valid_values = [arr[-1], arr[0], arr[0] + d]
else:
	d = arr[-1] - arr[0]
	valid_values = [arr[-1], arr[0]]
for i in arr:
	if i not in valid_values:
		d = -1
		break
print(d)


s = int(input())
a = input().split()
b = []
for i in range(s):
	if abs(int(a[i])) not in b:
		b.append(abs(int(a[i])))
if len(b) == 1:
	print(0)
elif len(b) == 2:
	if abs(b[0] - b[1]) % 2 == 0:
		print(abs(b[0] - b[1]) // 2)
	else:
		print(abs(b[0] - b[1]))
elif len(b) == 3:
	b.sort()
	if float(b[1]) == abs(b[0] - b[2]) / 2 + min(b[0], b[2]):
		print(abs(b[0] - b[2]) // 2)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
sequence = list(map(int, input().split()))
sequence.sort()

def solve():
	if (sequence[n - 1] - sequence[0]) % 2 != 0:
		possible_d = sequence[n - 1] - sequence[0]
	else:
		possible_d = (sequence[n - 1] - sequence[0]) / 2
	for i in range(n - 1):
		if sequence[i + 1] - sequence[i] not in [0, possible_d, 2 * possible_d]:
			return -1
	return int(possible_d)
print(solve())


input()
d = [int(x) for x in input().split()]
u = list(set(d))
u.sort()
if len(u) == 1:
	print(0)
elif len(u) > 3:
	print(-1)
elif len(u) == 2:
	print(int((u[1] - u[0]) / 2) if ((u[1] - u[0]) / 2).is_integer() else u[1] - u[0])
elif len(u) == 3:
	print(u[2] - u[1] if u[2] - u[1] == u[1] - u[0] else -1)


n = int(input())
a = [int(x) for x in input().split()]
mass = list()
for i in a:
	if i not in mass:
		mass.append(i)
mass.sort()
if len(mass) == 1:
	print(0)
elif len(mass) == 2:
	if (mass[1] - mass[0]) % 2 == 0:
		print(int((mass[1] - mass[0]) / 2))
	else:
		print(int(mass[1] - mass[0]))
elif len(mass) == 3:
	if mass[2] - mass[1] == mass[1] - mass[0]:
		print(mass[1] - mass[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
s = list(set(l))
s.sort()
m = max(s)
if len(s) == 3:
	a = (s[2] + s[0]) / 2
	if a == s[1]:
		print(s[2] - s[1])
	else:
		print(-1)
elif len(s) == 2:
	m = (s[0] + s[1]) / 2
	if m % 1 == 0:
		print(int(s[1] - m))
	else:
		print(s[1] - s[0])
elif len(s) == 1:
	print(0)
else:
	print(-1)


n = int(input())
a = [int(item) for item in input().split()]
s = set(a)
l = list(s)
if len(s) > 3:
	print(-1)
elif len(s) == 3:
	l.sort()
	if l[1] - l[0] != l[2] - l[1]:
		print(-1)
	else:
		print(l[1] - l[0])
elif len(s) == 2:
	if abs(l[0] - l[1]) % 2:
		print(abs(l[0] - l[1]))
	else:
		print(abs(l[0] - l[1]) // 2)
else:
	print(0)


import sys
fin = sys.stdin.readline
n = int(fin())
a_list = [int(elem) for elem in fin().split()]
a_set = set(a_list)
if len(a_set) == 1:
	print(0)
elif len(a_set) > 3:
	print(-1)
elif len(a_set) == 2:
	(min_elem, max_elem) = (min(a_set), max(a_set))
	diff = max_elem - min_elem
	print(diff // 2 if diff % 2 == 0 else diff)
else:
	(min_elem, max_elem) = (min(a_set), max(a_set))
	a_set.discard(min_elem)
	a_set.discard(max_elem)
	mid_elem = next(iter(a_set))
	diff = max_elem - min_elem
	if diff % 2 == 0 and diff // 2 + min_elem == mid_elem:
		print(diff // 2)
	else:
		print(-1)


def mp():
	return map(int, input().split())
n = int(input())
x = list(mp())
x.sort()
a = b = c = 0
cnt = 1
a = x[0]
for i in range(1, n):
	if x[i] != x[i - 1]:
		cnt += 1
		if b == 0:
			b = x[i]
		elif c == 0:
			c = x[i]
f = 0
if not ((abs(a - b) == abs(b - c) or c == 0) and cnt <= 3):
	print(-1)
elif b == 0:
	print(0)
elif c == 0:
	if abs(a - b) % 2 == 0:
		print(abs(a - b) // 2)
	else:
		print(abs(a - b))
else:
	print(abs(a - b))


inp = lambda cast=int: list(map(cast, input().split()))
(n,) = inp()
A = inp()
mx = max(A)
mn = min(A)
(fs, ds) = ([mn, mx], [mx - mn, mx - mn])
if (mx - mn) % 2 == 0:
	fs = [(mx + mn) // 2] + fs
	ds = [(mx - mn) // 2] + ds
none = True
for (f, d) in zip(fs, ds):
	flag = True
	for a in A:
		if a + d != f and a - d != f and (a != f):
			flag = False
			break
	if flag:
		none = False
		print(d)
		break
if none:
	print(-1)


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

def solve(a):
	res = 105
	(ma, mi) = (max(a), min(a))
	p = ma - mi
	if all((x in [mi, ma] for x in a)):
		res = min(res, p)
	if (ma + mi) % 2 == 0:
		p = (ma + mi) // 2
		if all((x in [mi, ma, p] for x in a)):
			res = min(res, ma - p)
	return res if res != 105 else -1
print(solve(a))


n = int(input())
a = list(map(int, input().rstrip().split()))
b = sorted(a)
values = []
for i in range(len(a) - 1):
	if b[i] != b[i + 1]:
		values.append(b[i + 1] - b[i])
if len(values) > 2:
	print(-1)
elif len(values) == 0:
	print(0)
elif len(values) == 1:
	if (b[0] - b[len(b) - 1]) % 2 == 0:
		print(values[0] // 2)
	else:
		print(values[0])
elif abs(values[1] - values[0]) == 0:
	print(values[0])
else:
	print(-1)


_ = input()
arr = sorted(list(set(map(int, input().split()))))
if len(arr) == 1:
	print(0)
elif len(arr) == 2:
	u = abs(arr[0] - arr[1])
	if u % 2 != 0:
		print(u)
	else:
		print(u // 2)
elif len(arr) == 3:
	if arr[1] - arr[0] != arr[2] - arr[1]:
		print(-1)
		exit()
	else:
		print(arr[1] - arr[0])
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = []
f = {}
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i] - a[j] != 0:
			b.append(abs(a[i] - a[j]))
			f.setdefault(abs(a[i] - a[j]), 0)
			f[abs(a[i] - a[j])] = 1
if len(f) > 2:
	print(-1)
elif len(f) == 1:
	for (a, b) in f.items():
		if a % 2 == 0:
			print(a // 2)
		else:
			print(a)
elif len(f) == 0:
	print(0)
else:
	z = []
	for (a, b) in sorted(f.items()):
		z.append(a)
	if z[0] * 2 != z[1]:
		print(-1)
	else:
		print(z[0])


n = int(input())
arr = list(map(int, input().split()))
sarr = list(set(arr))
sarr.sort()
(low, mid, high) = (0, 0, 0)
if len(sarr) == 3:
	low = sarr[0]
	mid = sarr[1]
	high = sarr[2]
	if mid - low == high - mid:
		print(mid - low)
	else:
		print(-1)
elif len(sarr) == 2:
	low = sarr[0]
	high = sarr[1]
	lh = low + high
	if lh % 2 == 0:
		print(lh // 2 - low)
	else:
		print(high - low)
elif len(sarr) == 1:
	print(0)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = l[0]
b = l[-1]
c = l[0] + l[-1]
if c % 2 != 0:
	if len(set(l)) <= 2:
		print(b - a)
		exit()
	else:
		print('-1')
		exit()
else:
	c = c // 2
s = [a, b, c]
k = 0
for i in range(n):
	if l[i] not in s:
		print('-1')
		exit()
print((b - a) // 2)


def make_equal():
	n = int(input())
	S = set(map(int, input().split(' ')))
	if len(S) > 3:
		return -1
	elif len(S) == 3:
		max_element = max(S)
		min_element = min(S)
		average = (max_element + min_element) / 2
		S.remove(max_element)
		S.remove(min_element)
		other = S.pop()
		if average == other:
			return max_element - other
		else:
			return -1
	elif len(S) == 2:
		bigger = max(S)
		S.remove(bigger)
		other = S.pop()
		diff = bigger - other
		if diff % 2 == 0:
			return int(diff / 2)
		else:
			return diff
	elif len(S) == 1:
		return 0
	else:
		return -1
print(make_equal())


import sys
import math
v = True
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
if min(a) == max(a):
	print(0)
else:
	if (max(a) - min(a)) % 2 == 1:
		x = max(a) - min(a)
	else:
		x = (max(a) - min(a)) // 2
	m = min(a)
	for y in a:
		if y not in [m, m + x, m + 2 * x]:
			v = False
	if v == False:
		print(-1)
	else:
		print(x)


a = int(input())
b = list(map(int, input().split()))
x = set(b)
xs = list(x)
xs.sort()
if len(xs) == 2:
	if sum(xs) % 2 != 0:
		print(xs[1] - xs[0])
	else:
		print(int(sum(xs) / 2) - xs[0])
elif len(xs) == 3:
	if xs[-1] - xs[1] == xs[1] - xs[0]:
		print(xs[1] - xs[0])
	else:
		print(-1)
elif len(xs) == 1:
	print(0)
else:
	print(-1)


def function(n, nums):
	l = list(sorted(set(nums)))
	if len(l) > 3:
		return -1
	if len(l) == 1:
		return 0
	if len(l) == 2:
		if (l[1] - l[0]) / 2 != int((l[1] - l[0]) / 2):
			return l[1] - l[0]
		else:
			return int((l[1] - l[0]) / 2)
	if len(l) == 3:
		if l[1] - l[0] == l[2] - l[1]:
			return l[1] - l[0]
		else:
			return -1
	return -1
n = int(input())
nums = list(map(int, input().rstrip().split()))
print(function(n, nums))


n = int(input())
it = list(map(int, input().split()))
kk = set(it)
if len(kk) > 3:
	print(-1)
if len(kk) == 1:
	print(0)
if len(kk) == 2:
	kk = list(kk)
	kk.sort()
	if (kk[0] - kk[1]) % 2 == 0:
		print((kk[1] - kk[0]) // 2)
	else:
		print(kk[1] - kk[0])
if len(kk) == 3:
	kk = list(kk)
	kk.sort()
	if kk[0] - kk[1] == kk[1] - kk[2]:
		print(kk[1] - kk[0])
	else:
		print(-1)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
c = Counter(l)
ls = sorted(list(c.keys()))

def main():
	if len(c) == 3:
		if ls[2] - ls[1] == ls[1] - ls[0]:
			print(ls[2] - ls[1])
			return 0
		else:
			print(-1)
			return 0
	elif len(c) == 2:
		if (ls[1] - ls[0]) % 2 == 0:
			print((ls[1] - ls[0]) // 2)
			return 0
		else:
			print(ls[1] - ls[0])
			return 0
	elif len(c) == 1:
		print(0)
		return 0
	else:
		print(-1)
		return 0
main()


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
s = sorted(list(c.keys()))
if len(s) == 3:
	if (s[0] - s[2]) % 2 == 0 and (s[0] + s[2]) // 2 == s[1]:
		print(s[1] - s[0])
	else:
		print(-1)
elif len(s) == 2:
	if (s[1] - s[0]) % 2 == 0:
		print((s[0] + s[1]) // 2 - s[0])
	else:
		print(s[1] - s[0])
elif len(s) == 1:
	print(0)
else:
	print(-1)


n = int(input())
ks = [int(i) for i in input().split()]
ak = list(set(ks))
ak.sort()
k = -1
if len(ak) == 1:
	print('0')
elif len(ak) == 2:
	if (ak[1] + ak[0]) % 2 == 0:
		print((ak[1] + ak[0]) // 2 - ak[0])
	else:
		print(ak[1] - ak[0])
elif len(ak) == 3:
	if ak[2] - ak[1] == ak[1] - ak[0]:
		print(ak[2] - ak[1])
	else:
		print(k)
else:
	print(k)


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
b.sort()
if len(b) > 3:
	print(-1)
elif len(b) == 1:
	print(0)
elif len(b) == 2:
	d = (b[-1] + b[0]) / 2
	if d != int(d):
		print(b[-1] - b[0])
	else:
		print(int(d) - b[0])
else:
	d = (b[-1] + b[0]) / 2
	if d != int(d):
		print(-1)
	elif d == b[1]:
		print(int(d) - b[0])
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
ans = 0
d = {}
keys = []
m = 0
for i in a:
	if i not in d:
		d[i] = True
		m += 1
		keys.append(i)
if m > 3:
	ans = -1
elif m == 1:
	ans = 0
elif m == 2:
	diff = abs(keys[0] - keys[1])
	if diff % 2 == 0:
		ans = diff // 2
	else:
		ans = diff
else:
	keys.sort()
	if abs(keys[0] - keys[1]) == abs(keys[1] - keys[2]):
		ans = abs(keys[0] - keys[1])
	else:
		ans = -1
print(ans)


def main():
	n = int(input())
	ai = sorted([int(x) for x in input().split()])
	(maxim, minim) = (ai[-1], ai[0])
	k = (maxim - minim) // 2
	et = minim + k if (maxim - minim) % 2 == 0 else minim
	if et == minim:
		k = maxim - minim
	for x in ai:
		if x + k == et or x == et or x - k == et:
			pass
		else:
			print(-1)
			return
	print(k)
main()


n = input()
a = [int(i) for i in input().split()]
m = (max(a) - min(a)) / 2 + min(a)
j = 1
for i in a:
	if i != min(a) and i != max(a) and (i != m):
		j = 0
		break
if j == 1:
	if int(m) == m:
		print(int(m) - min(a))
	else:
		print(max(a) - min(a))
else:
	print(-1)


n = map(int, input().split())
arr = map(int, input().split())
arr = list(arr)
if len(set(arr)) == 1:
	print(0)
if len(set(arr)) == 2:
	if (max(arr) - min(arr)) % 2 == 0:
		print(int((max(arr) - min(arr)) / 2))
	else:
		print(int(max(arr) - min(arr)))
if len(set(arr)) == 3:
	max_ = max(arr)
	min_ = min(arr)
	arr = [a for a in arr if a not in [max_, min_]]
	arr = [a for a in arr if a != (max_ + min_) / 2]
	if len(arr) != 0:
		print(-1)
	else:
		print(int((max_ - min_) / 2))
if len(set(arr)) > 3:
	print(-1)


import math

def makeEqual(nums):
	max1 = max(nums)
	min1 = min(nums)
	d = max1 - min1
	if d % 2 == 0:
		d = d // 2
	for i in nums:
		if i != min1 and i != max1 and (i != min1 + d):
			return -1
	return d
n = int(input())
nums = list(map(int, input().split()))
print(makeEqual(nums))


n = int(input())
lst = input()
lst = lst.split(' ')
lst = [int(x) for x in lst]
dict = {}
values = [0] * len(lst)
dict = {k: v for (k, v) in zip(lst, values)}
for x in lst:
	if x in dict:
		dict[x] += 1
liste = list(dict.keys())
liste.sort(reverse=True)
if len(dict) == 3:
	if liste[0] - liste[1] == liste[1] - liste[2]:
		print(liste[0] - liste[1])
	else:
		print(-1)
elif len(dict) > 3:
	print(-1)
elif len(dict) == 2:
	if liste[0] % 2 == liste[1] % 2:
		print((liste[0] - liste[1]) // 2)
	else:
		print(liste[0] - liste[1])
elif len(dict) == 1:
	print(0)


amount = map(int, input().split())
numbers = sorted(list(set(map(int, input().split()))))
if len(numbers) == 1:
	print(0)
elif len(numbers) == 2:
	if (numbers[1] - numbers[0]) % 2:
		print(numbers[1] - numbers[0])
	else:
		print(int((numbers[1] - numbers[0]) / 2))
elif len(numbers) == 3 and numbers[2] - numbers[1] == numbers[1] - numbers[0]:
	print(numbers[2] - numbers[1])
else:
	print(-1)


from collections import deque
from math import log, sqrt, ceil

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

def si():
	return input()

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

def li():
	return list(mi())
n = ii()
a = li()
m = {}
for i in a:
	m[i] = 1
a = []
for i in m.keys():
	a.append(i)
a.sort()
n = len(a)
if n > 3:
	print('-1')
elif n == 3:
	x = a[1] - a[0]
	y = a[2] - a[1]
	if x == y:
		print(x)
	else:
		print('-1')
elif n == 2:
	x = a[1] - a[0]
	if x % 2 == 0:
		print(x // 2)
	else:
		print(x)
else:
	print('0')


n = int(input())
lis = list(map(int, input().split()))
lis.sort()
c = 0
min1 = 0
if n == 1:
	print(0)
	exit()
for i in range(1, len(lis)):
	if lis[i] > lis[i - 1]:
		if c == 0:
			min1 = lis[i] - lis[i - 1]
			c = 1
			continue
		c += 1
		if lis[i] - lis[i - 1] != min1:
			print(-1)
			exit()
		if c > 2:
			print(-1)
			exit()
if c == 1:
	x = (lis[0] + lis[-1]) / 2
	if x == int(x):
		print(int(x - lis[0]))
		exit()
print(min1)


a = int(input())
b = list(map(int, input().split()))
e = []
for elem in b:
	if elem not in e:
		e.append(elem)
if len(e) <= 3:
	if len(e) == 1:
		print(0)
	elif len(e) == 2:
		if (e[0] - e[1]) % 2:
			print(abs(e[0] - e[1]))
		else:
			print(abs(e[0] - e[1]) // 2)
	elif len(e) == 3:
		e.sort()
		if 2 * e[1] == e[0] + e[2]:
			print(abs(e[1] - e[0]))
		else:
			print(-1)
else:
	print(-1)


N = int(input())
n = list(map(int, input().split()))
(a, b) = (max(n), min(n))
if (a - b) % 2 == 0:
	D = (a - b) // 2
	q = [a, b, a - D]
else:
	D = a - b
	q = [a, b]
for s in n:
	if s not in q:
		D = -1
		break
print(D)


dic = {}
b = int(input())
a = list(map(int, input().split()))
for num in range(b):
	if a[num] in dic.keys():
		dic[a[num]] += 1
	else:
		dic[a[num]] = 1
y = list(dic.keys())
if len(dic) == 1:
	print(0)
elif len(dic) == 2:
	s = sum(y)
	if s % 2 == 0:
		z = abs(y[0] - y[1]) / 2
		print(int(z))
	else:
		print(abs(y[0] - y[1]))
elif len(dic) == 3:
	y.sort()
	if y[1] - y[0] == y[2] - y[1]:
		print(y[1] - y[0])
	else:
		print(-1)
else:
	print(-1)


a = []
n = int(input())
a = map(int, input().split())
a = list(a)
b = []
for i in range(n):
	if a[i] not in b:
		b.append(a[i])
b = sorted(b)
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	if b[2] - b[1] == b[1] - b[0]:
		print(b[1] - b[0])
	else:
		print(-1)
elif len(b) == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = set(l)
if len(s) == 1:
	print(0)
	exit()
if len(s) == 2:
	if (l[-1] - l[0]) % 2 == 0:
		print((l[-1] - l[0]) // 2)
		exit()
	else:
		print(l[-1] - l[0])
		exit()
a = 1000000000.0
for i in l:
	if i != l[0]:
		a = i
		break
x = a - l[0]
for i in range(1, n):
	if l[i] - l[0] == 0 or l[i] - l[0] == x or l[i] - l[0] == 2 * x:
		continue
	else:
		print(-1)
		exit()
print(x)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	a = list(set(a))
	a.sort()
	if len(a) == 1:
		print(0)
	elif len(a) == 2:
		if abs(a[0] - a[1]) % 2 == 0:
			print(int(abs(a[0] - a[1]) / 2))
		else:
			print(abs(a[1] - a[0]))
	elif len(a) == 3:
		if abs(a[1] - a[0]) == abs(a[2] - a[1]):
			print(abs(a[1] - a[0]))
		else:
			print(-1)
	elif len(a) > 3:
		print(-1)
main()


input()
s = list(map(int, input().split()))
s = set(s)
if len(s) == 1:
	print(0)
elif len(s) < 4:
	p = sorted(list(s))
	if len(s) == 2:
		if (p[1] - p[0]) % 2 == 0:
			print((p[1] - p[0]) // 2)
		else:
			print(p[1] - p[0])
	elif p[1] - p[0] == p[2] - p[1]:
		print(p[1] - p[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
l = []
for i in a:
	if i not in l:
		l.append(i)
	if len(l) > 3:
		print(-1)
		break
else:
	l.sort()
	if len(l) == 3:
		if l[1] - l[0] == l[2] - l[1]:
			print(l[1] - l[0])
		else:
			print(-1)
	elif len(l) == 2:
		x = 10 ** 8
		if sum(l) % 2 == 0:
			x = l[-1] - sum(l) // 2
		print(min(l[1] - l[0], x))
	else:
		print(0)


import sys
n = int(input())
l = list(map(int, input().split()))
l.sort()
g = l[n - 1] - l[0]
t = 1
for i in range(1, n):
	if l[i] - l[i - 1] == g or l[i] - l[i - 1] == 0:
		continue
	elif l[i] - l[i - 1] == g / 2:
		t = 2
		continue
	else:
		print(-1)
		sys.exit()
if g % 2 == 0:
	print(g // 2)
else:
	print(g)


n = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
a = set(a)
d = -1
if len(a) == 1:
	d = 0
elif len(a) == 2:
	d = mx - mn
	if d % 2 == 0:
		d = d // 2
elif len(a) == 3:
	a = sorted(list(a))
	m = a[1]
	if mx - m == m - mn:
		d = mx - m
print(d)


n = int(input())
a = list(map(int, input().split()))
minE = min(a)
maxE = max(a)
D1 = maxE + minE
D2 = maxE - minE
flag1 = True
flag2 = True
for i in range(n):
	if abs(2 * a[i] - D1) != D2 and abs(2 * a[i] - D1) != 0:
		flag1 = False
if flag1:
	if D2 % 2 == 0:
		print(D2 // 2)
	else:
		print(D2)
else:
	print(-1)


t = int(input())
a = list(map(int, input().split()))[:t]
b = list(set(a))
b.sort()
c = []
if len(b) > 2:
	for i in range(len(b) - 1):
		c.append(b[i + 1] - b[i])
	if len(list(set(c))) == 1 and len(b) <= 3:
		print(c[0])
	elif len(b) > 3:
		print(-1)
	else:
		print(-1)
elif len(b) == 1:
	print(0)
elif len(b) == 2 and abs(b[1] - b[0]) % 2 == 0:
	print(abs(b[1] - b[0]) // 2)
else:
	print(abs(b[1] - b[0]))


n = int(input())
l = [*map(int, input().split())]
l = list(set(l))
l.sort()
su = sum(l)
tool = len(l)
if tool == 2:
	if (l[1] + l[0]) % 2 == 0:
		print((l[1] + l[0]) // 2 - l[0])
	else:
		print(l[1] - l[0])
elif tool == 1:
	print(0)
elif tool > 3:
	print(-1)
elif l[1] - l[0] == l[2] - l[1]:
	print(l[2] - l[1])
else:
	print(-1)


import math

def f():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = list(set(arr))
	arr.sort()
	first_last = arr[0] + arr[-1]
	if len(arr) == 1:
		print('0')
		return
	elif len(arr) == 2:
		if first_last % 2 == 0:
			mid = (arr[0] + arr[-1]) / 2
			diff = arr[-1] - arr[0]
			ans = arr[-1] - mid
			print(int(min(mid, ans)))
		else:
			print(arr[-1] - arr[0])
	elif len(arr) == 3:
		if first_last % 2 == 0:
			mid = (arr[0] + arr[-1]) / 2
			if int(mid) == arr[1]:
				print(int(mid - arr[0]))
			else:
				print('-1')
		else:
			print('-1')
	else:
		print('-1')
f()


N = int(input())
args = sorted(list(map(int, input().split())))
if len(args) > 1:
	result = []
	for index in range(0, len(args) - 1):
		if args[index] != args[index + 1]:
			result.append(abs(args[index] - args[index + 1]))
	if len(result) > 0:
		minimum_value = min(result)
		for index in range(1, len(result)):
			if result[index] == 2 * minimum_value:
				result[index] = minimum_value
		if result[1:] == result[:-1] and abs(args[0] - args[-1]) <= 2 * minimum_value:
			if len(result) == 1 and result[0] % 2 == 0:
				print(result[0] // 2)
			else:
				print(result[0])
		else:
			print(-1)
	else:
		print(0)
else:
	print(0)


n = int(input())
a = [int(k) for k in input().split()]
s = list(set(a))
s.sort()
dl = len(s)
if dl > 3:
	print(-1)
elif dl == 1:
	print(0)
elif dl == 2:
	if (s[1] - s[0]) % 2 == 0:
		print((s[1] - s[0]) // 2)
	else:
		print(s[1] - s[0])
elif s[1] - s[0] == s[2] - s[1]:
	print(s[1] - s[0])
else:
	print(-1)


n = int(input())
lst = [int(x) for x in input().split()]
lst = list(set(lst))
lst.sort()
last = lst[0]
count = len(lst) - 1
flag = True
(dif1, dif2) = (0, 0)
if count > 2:
	flag = False
if count == 2:
	dif1 = lst[1] - lst[0]
	dif2 = lst[2] - lst[1]
	if dif1 != dif2:
		flag = False
if flag:
	if count == 2:
		print(dif1)
	elif count == 1:
		dif1 = lst[1] - lst[0]
		if dif1 % 2 != 0:
			print(dif1)
		else:
			print(int(dif1 / 2))
	else:
		print(0)
else:
	print(int(-1))


p = int(input())
v = list(map(int, input().split()))
w = 1
for i in range(101):
	for k in range(101):
		q = 1
		for j in v:
			if k != j - i and k != i + j and (j != k):
				q = 0
				break
		if q:
			print(i)
			break
	if q:
		w = 0
		break
if w:
	print(-1)


input()
arr = list({int(i) for i in input().split()})
ma = count = 0
mi = 100
for j in arr:
	count += 1
	ma = max(ma, j)
	mi = min(mi, j)
if count > 3:
	print(-1)
elif count == 3:
	arr.sort()
	print(arr[2] - arr[1] if arr[2] - arr[1] == arr[1] - arr[0] else -1)
elif count == 2:
	print((ma - mi) // 2 if mi & 1 == ma & 1 else ma - mi)
else:
	print(0)


n = int(input())
li = list(map(int, input().strip().split()))
li.sort()
fin = []
ans = []
flag = 0
if n == 1 or len(set(li)) == 1:
	print(0)
else:
	for i in range(li[0], li[n - 1] + 1):
		fin = []
		for j in range(n):
			fin.append(abs(li[j] - i))
		if len(set(fin).difference({0})) == 1:
			flag = 1
			ans.append(list(set(fin).difference({0}))[0])
	if flag == 0:
		print(-1)
	else:
		print(min(ans))


n = int(input())
array = list(map(int, input().split()))
arr = sorted(set(array))
x = 0
if len(arr) == 1:
	x = 0
elif len(arr) == 2:
	x = arr[1] - arr[0]
	if x % 2 == 0:
		x = int(x / 2)
elif len(arr) == 3:
	if arr[2] - arr[1] == arr[1] - arr[0]:
		x = arr[2] - arr[1]
	else:
		x = -1
else:
	x = -1
print(x)


import sys, math, queue
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
n = int(input())
a = sorted(set(map(int, input().split())))
if len(a) == 1:
	print(0)
elif len(a) == 2:
	d = a[1] - a[0]
	if (a[1] + a[0]) % 2 == 0:
		d = min(d, a[1] - (a[1] + a[0]) // 2)
	print(d)
elif len(a) == 3:
	if a[1] - a[0] != a[2] - a[1]:
		print(-1)
	else:
		print(a[1] - a[0])
else:
	print(-1)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print(0)
	exit()
for D in range(1, 101):
	d = defaultdict(int)
	for j in range(n):
		d[a[j] + D] += 1
		d[a[j] - D] += 1
		d[a[j]] += 1
	if d[a[-1]] == n or d[a[-1] + D] == n or d[a[-1] - D] == n:
		print(D)
		exit()
print(-1)


n = int(input())
a = list(map(int, input().split()))
minimo = 1002
maximo = 0
num_dif = []
for i in range(n):
	maximo = max(maximo, a[i])
	minimo = min(minimo, a[i])
	if not a[i] in num_dif:
		num_dif.append(a[i])
l = len(num_dif)
if l == 1:
	print('0')
elif l == 2:
	if (maximo + minimo) % 2 == 0:
		print(int(maximo - (maximo + minimo) / 2))
	else:
		print(int(maximo - minimo))
elif l == 3:
	if (maximo + minimo) % 2 == 0:
		if (maximo + minimo) / 2 in num_dif:
			print(int(maximo - (maximo + minimo) / 2))
		else:
			print('-1')
	else:
		print('-1')
elif l > 3:
	print('-1')


n = int(input())
a = list(map(int, input().split()))
x = max(a)
y = min(a)
r = (x - y) // 2
k1 = 0
k2 = 0
k3 = 0
for i in a:
	if i != x and i != y and (i != x - r) or ((x - y) % 2 != 0 and i != x and (i != y)):
		print(-1)
		break
	elif i == x:
		k1 += 1
	elif i == y:
		k3 += 1
	else:
		k2 += 1
else:
	if k1 * k2 * k3 != 0:
		print(r)
	elif (x - y) % 2 == 0:
		print(r)
	else:
		print(x - y)


import sys
n = int(input())
t = [0 for i in range(101)]
a = []
for i in list(map(int, input().split())):
	if not t[i]:
		t[i] = 1
		a.append(i)
if (max(a) - min(a)) % 2:
	if len(a) > 2:
		print(-1)
	else:
		print(max(a) - min(a))
elif len(a) > 2:
	if sum(a) - max(a) - min(a) == min(a) + (max(a) - min(a)) // 2:
		print((max(a) - min(a)) // 2)
	else:
		print(-1)
else:
	print((max(a) - min(a)) // 2)


n = int(input())
a = list(map(int, input().split()))
dif = max(a) - min(a)
ma = max(a)
mi = min(a)
check = set(a)
count = len(check)
b = [0] * n
if dif % 2 == 0:
	dif = int(dif / 2)
	count = 3
for i in range(len(a)):
	if a[i] == mi and count > 2:
		b[i] = a[i] + dif
	elif a[i] == ma:
		b[i] = a[i] - dif
	else:
		b[i] = a[i]
for i in range(len(b)):
	if not b[i] == b[0]:
		dif = -1
		break
print(dif)


n = int(input())
l = input().split(' ')
l1 = list(map(int, l))
l1 = list(set(l1))
if len(l1) == 1:
	print(0)
elif len(l1) == 2:
	d = abs(l1[1] - l1[0])
	if d % 2 == 0:
		print(d // 2)
	else:
		print(d)
elif len(l1) == 3:
	l1.sort()
	d1 = abs(l1[1] - l1[0])
	d2 = abs(l1[2] - l1[1])
	if d1 == d2:
		print(d1)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
ans = 10 ** 5
sett = list(set(arr))
if len(sett) == 1:
	print(0)
elif len(sett) == 2:
	a = sett[0]
	b = sett[1]
	if (a + b) % 2 == 0:
		ans = min(abs(a - (a + b) // 2), abs(a - b))
		print(ans)
	else:
		print(abs(a - b))
elif len(sett) == 3:
	sett = sorted(sett)
	if abs(sett[0] - sett[1]) != abs(sett[1] - sett[2]):
		print(-1)
	else:
		print(abs(sett[0] - sett[1]))
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
ans = []
a.sort()
b = []
if a[0] == a[n - 1]:
	ans.append(0)
for i in range(0, 200, 1):
	b = a.copy()
	d = 0
	work = 0
	for j in range(n):
		if b[j] == i:
			continue
		if d == 0:
			d = abs(b[j] - i)
		elif d != abs(b[j] - i):
			work = 1
			break
	if work == 0:
		ans.append(d)
if len(ans) == 0:
	print('-1')
else:
	print(min(ans))


n = int(input())
a = [int(s) for s in input().split()]
x = max(a)
y = min(a)
k = 0
if (x + y) % 2 == 0:
	for i in range(n):
		if ((x + y) // 2 == a[i]) | ((x + y) // 2 == a[i] + (x + y) // 2 - y) | ((x + y) // 2 == a[i] - (x + y) // 2 + y):
			k += 1
	if k == n:
		print((x + y) // 2 - y)
	else:
		print(-1)
else:
	for i in range(n):
		if (x == a[i]) | (y == a[i]):
			k += 1
	if k == n:
		print(x - y)
	else:
		print(-1)


n = int(input())
z = str(input()).split()
arr = []
for i in range(len(z)):
	status = True
	for j in range(len(arr)):
		if int(z[i]) == arr[j]:
			status = False
			break
	if status:
		arr.append(int(z[i]))
arr.sort()
if len(arr) == 2:
	if (arr[1] - arr[0]) % 2 == 0:
		print((arr[1] - arr[0]) // 2)
	else:
		print(arr[1] - arr[0])
elif len(arr) == 1:
	print(0)
elif len(arr) == 3:
	if arr[2] - arr[1] == arr[1] - arr[0]:
		print(arr[2] - arr[1])
	else:
		print(-1)
else:
	print(-1)


from math import gcd
n = int(input())
l = list(map(int, input().split()))
l = list(set(l))
k = 0
l.sort()
if len(l) > 3:
	k = -1
elif len(l) == 3:
	if l[2] - l[1] == l[1] - l[0]:
		k = l[2] - l[1]
	else:
		k = -1
elif len(l) == 2:
	if (l[1] - l[0]) % 2 == 0:
		k = (l[1] - l[0]) // 2
	else:
		k = l[1] - l[0]
else:
	k = 0
print(k)


n = int(input())
a = list(map(int, input().split()))
l = set(a)
k = [i for i in l]
if len(l) == 1:
	print(0)
elif len(l) == 2:
	t = max(k[1], k[0]) - min(k[1], k[0])
	if t % 2 == 0:
		print(t // 2)
	else:
		print(t)
elif len(l) == 3:
	k = [i for i in l]
	k.sort()
	if k[2] - k[1] == k[1] - k[0]:
		print(k[1] - k[0])
	else:
		print(-1)
else:
	print(-1)


def equal(a):
	a = sorted(set(a))
	if len(a) > 3:
		return -1
	elif len(a) == 3:
		if a[1] - a[0] == a[2] - a[1]:
			return a[1] - a[0]
		else:
			return -1
	elif len(a) == 1:
		return 0
	elif len(a) == 2:
		if (a[1] - a[0]) % 2 == 0:
			return (a[1] - a[0]) // 2
		else:
			return a[1] - a[0]
n = int(input())
a = list(map(int, input().split()))
print(equal(a))


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR, insort as INSORT
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write
L = list
M = map

def player1():
	print('')

def player2():
	print('')

def yes():
	PRINT('YES\n')

def no():
	PRINT('NO\n')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def checkPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def main():
	n = int(INPUT())
	a = sorted(C(M(int, INPUT().split())))
	l = len(a)
	if l > 3:
		PRINT('%d' % -1)
		return
	if l == 1:
		PRINT('0')
		return
	if l == 3:
		if a[1] - a[0] == a[2] - a[1]:
			PRINT('%d' % (a[2] - a[1]))
		else:
			PRINT('%d' % -1)
	if l == 2:
		if not a[1] - a[0] & 1:
			PRINT('%d' % ((a[1] - a[0]) // 2))
		else:
			PRINT('%d' % (a[1] - a[0]))
main()


def dunc():
	from math import floor, ceil
	n = int(input())
	a = [int(i) for i in input().split()]
	num1 = floor(sum(a) / n)
	num2 = ceil(sum(a) / n)
	b = []
	c = []
	d = 10 ** 9
	d1 = 10 ** 9
	for i in range(len(a)):
		b.append(abs(a[i] - num1))
	for i in range(len(a)):
		c.append(abs(a[i] - num2))
	if len(set(b) - {0}) == 1:
		d = min(d, b[0])
	if len(set(c) - {0}) == 1:
		d1 = min(d1, c[0])
	if d == 10 ** 9 and d1 == 10 ** 9:
		print(-1)
	else:
		print(min(d, d1))
n = int(input())
a = [int(i) for i in input().split()]
b = list(set(a))
b.sort()
if len(b) == 1:
	print(0)
elif len(b) == 2:
	if (b[-1] - b[0]) % 2 == 0:
		print((b[-1] - b[0]) // 2)
	else:
		print(b[-1] - b[0])
elif len(b) == 3:
	if b[-1] - b[1] == b[1] - b[0]:
		print(b[-1] - b[1])
	else:
		print(-1)
else:
	print(-1)


def findDiff(a, n):
	st = set()
	for i in range(n):
		st.add(a[i])
	if len(st) == 1:
		return 0
	if len(st) == 2:
		st = list(st)
		st.sort()
		el1 = st[0]
		el2 = st[1]
		if (el2 - el1) % 2 == 0:
			return int((el2 - el1) / 2)
		else:
			return el2 - el1
	if len(st) == 3:
		st = list(st)
		st.sort()
		el1 = st[0]
		el2 = st[1]
		el3 = st[2]
		if el2 - el1 == el3 - el2:
			return el2 - el1
		else:
			return -1
	return -1

def main():
	n = int(input())
	numbers = list(map(int, input().split()))
	print(findDiff(numbers, n))
main()


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
k = 1
list_1 = [l[0]]
for i in range(1, len(l)):
	if l[i] != l[i - 1]:
		k = k + 1
		list_1.append(l[i])
if k > 3:
	print(-1)
elif k == 1:
	print(0)
elif k == 2:
	if (list_1[-1] - list_1[0]) % 2 == 0:
		print(int((list_1[-1] - list_1[0]) / 2))
	else:
		print(list_1[-1] - list_1[0])
elif list_1[-1] - list_1[1] == list_1[1] - list_1[0]:
	print(list_1[-1] - list_1[1])
else:
	print(-1)


n = int(input())
b = list(map(int, input().split()))
arr = sorted(b)
lis = []
lis.append(arr[0])
k = 1
for i in range(1, n):
	if lis[k - 1] != arr[i]:
		lis.append(arr[i])
		k = k + 1
if len(lis) == 1:
	print(0)
if len(lis) > 3:
	print(-1)
if len(lis) == 3:
	q = lis[1] - lis[0]
	w = lis[2] - lis[1]
	if q == w:
		print(q)
	else:
		print(-1)
if len(lis) == 2:
	e = lis[1] - lis[0]
	if e % 2 == 0:
		e = e // 2
		print(e)
	else:
		print(e)


n = int(input())
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	(low, mid, high) = b
	if mid - low != high - mid:
		print(-1)
	else:
		print(mid - low)
elif len(b) == 2:
	s = sum(b)
	if s % 2 != 0:
		print(b[1] - b[0])
	else:
		print(s // 2 - b[0])
else:
	print(0)


numbers = set()
array_size = int(input())
list_of_numbers = map(int, input().split())
for i in list_of_numbers:
	numbers.add(i)
numbers = sorted(numbers)
if len(numbers) == 1:
	print('0')
elif len(numbers) == 2:
	sum_of_elements = numbers[0] + numbers[1]
	if sum_of_elements % 2 == 0:
		print(int(abs(sum_of_elements / 2 - numbers[0])))
	else:
		print(abs(numbers[1] - numbers[0]))
elif len(numbers) == 3:
	if numbers[0] + numbers[2] == 2 * numbers[1]:
		print(numbers[1] - numbers[0])
	else:
		print('-1')
else:
	print('-1')


def make_right(lst):
	if len(lst) == 1:
		return 0
	d = lst[-1] - lst[0]
	if d % 2 == 0:
		flag = True
		for i in range(len(lst)):
			if lst[i] != lst[0] and lst[i] != lst[-1] and (lst[i] != lst[0] + d // 2):
				flag = False
		if flag:
			return d // 2
	flag = True
	for i in range(len(lst)):
		if lst[i] != lst[0] and lst[i] != lst[-1]:
			flag = False
	if flag:
		return d
	return -1
n = int(input())
b = [int(j) for j in input().split()]
print(make_right(sorted(b)))


n = int(input())
a = [int(x) for x in input().split()]
b = sorted(set(a))
if len(b) == 1:
	print(0)
elif len(b) == 2:
	b.sort()
	if sum(b) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
elif len(b) == 3:
	b.sort()
	if b[0] + b[2] == 2 * b[1]:
		print(b[1] - b[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 6
a.sort()
d = a[-1] - a[0]
if d % 2 == 0:
	D1 = d // 2
	num = a[0] + D1
	stop = 0
	for elem in a:
		if elem + D1 != num and elem != num and (elem - D1 != num):
			stop = 1
			break
	if stop == 0:
		ans = min(ans, D1)
D1 = d
num = a[0] + D1
stop = 0
for elem in a:
	if elem + D1 != num and elem != num and (elem - D1 != num):
		stop = 1
		break
if stop == 0:
	ans = min(ans, D1)
if a[0] == a[-1]:
	ans = 0
if ans == 10 ** 6:
	print(-1)
else:
	print(ans)


def solve(n, items):
	items = list(set(items))
	items.sort()
	size = len(items)
	if len(items) >= 4:
		return -1
	if size == 1:
		return 0
	if size == 2:
		if items[0] == items[1]:
			return 0
		diff = abs(items[0] - items[1])
		if diff & 1 == 0:
			return diff // 2
		return diff
	else:
		diff = abs(items[0] - items[1])
		difft = abs(items[1] - items[2])
		if diff != difft:
			return -1
		else:
			return diff
c = input()
items = [int(x) for x in input().split()]
ans = solve(c, items)
print(ans)


from sys import stdin, stdout

def fn(final, d):
	for v in a:
		if v != final and v + d != final and (v - d != final):
			return False
	return True
for _ in range(1):
	n = int(stdin.readline())
	ans = -1
	a = list(map(int, stdin.readline().split()))
	for d in range(111):
		if fn(a[0], d) or fn(a[0] + d, d) or fn(a[0] - d, d):
			ans = d
			break
	print(ans)


input()
a = sorted(set(map(int, input().split())))
l = len(a)
s = a[0] + a[-1]
d = -1
if l == 1:
	d = 0
if l == 2 and s % 2 == 0 or (l == 3 and s == 2 * a[1]):
	d = s // 2 - a[0]
elif l == 2:
	d = a[-1] - a[0]
print(d)


from sys import stdin
import math
from collections import defaultdict, deque

def check(arr, num):
	myset = set()
	for i in range(len(arr)):
		if arr[i] < num:
			myset.add(num - arr[i])
		elif arr[i] > num:
			myset.add(arr[i] - num)
	if len(myset) <= 1:
		return True
	else:
		return False
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
mn = float('inf')
flag = 0
for i in range(0, 101):
	if check(arr, i):
		flag = 1
		mx = -float('inf')
		for k in arr:
			mx = max(mx, abs(k - i))
		mn = min(mx, mn)
if flag == 0:
	print(-1)
else:
	print(mn)


n = int(input())
line = input().split(' ')
li = []
ma = int(line[0])
mi = int(line[0])
for x in line:
	x = int(x)
	if x > ma:
		ma = x
	if x < mi:
		mi = x
can = True
dif = ma - mi
if dif % 2 == 1:
	for x in line:
		x = int(x)
		if not x == ma and (not x == mi):
			can = False
			break
else:
	dif = int(dif / 2)
	for x in line:
		x = int(x)
		if not x == ma and (not x == mi) and (not x == int((ma + mi) / 2)):
			can = False
			break
if can:
	print(dif)
else:
	print(-1)


n = int(input())
p = [int(x) for x in input().split()]
if len(set(p)) >= 4:
	print(-1)
elif len(set(p)) == 2:
	if (max(p) - min(p)) % 2 == 0:
		print(int((max(p) - min(p)) / 2))
	else:
		print(max(p) - min(p))
elif len(set(p)) == 1:
	print(0)
else:
	a = max(p)
	b = min(p)
	if int((a + b) / 2) in p and int((a + b) / 2) == (a + b) / 2:
		print(a - int((a + b) / 2))
	else:
		print(-1)


n = int(input())
l = list(map(int, input().split()))
ans = -1
for d in range(101):
	res = l[0] + d
	possible = True
	for i in range(1, n):
		if not (l[i] + d == res or l[i] == res or l[i] - d == res):
			possible = False
	if possible:
		ans = d
		break
	res = l[0]
	possible = True
	for i in range(1, n):
		if not (l[i] + d == res or l[i] == res or l[i] - d == res):
			possible = False
	if possible:
		ans = d
		break
	res = l[0] - d
	possible = True
	for i in range(1, n):
		if not (l[i] + d == res or l[i] == res or l[i] - d == res):
			possible = False
	if possible:
		ans = d
		break
print(ans)


n = int(input())
a = set(map(int, input().split()))
b = list(a)
ans = -1
for x in range(-200, 200):
	g = set()
	for t in b:
		if x == t:
			continue
		g.add(abs(x - t))
	if len(g) == 0:
		ans = 0
	elif len(g) == 1:
		d = list(g)[0]
		if ans == -1:
			ans = d
		else:
			ans = min(ans, d)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = -1
for d in range(0, 101):
	etalon = a[0] + d
	flag = 1
	for j in range(1, n):
		if a[j] > etalon and a[j] - d != etalon or (a[j] < etalon and a[j] + d != etalon):
			flag = 0
	if flag:
		ans = d
		break
print(ans)


n = int(input())
aas = list(map(int, input().split(' ')))
bs = sorted(list(set(aas)))

def check(v):
	if len(v) > 3:
		return -1
	if len(v) == 1:
		return 0
	if len(v) == 2:
		diff = v[1] - v[0]
		if diff % 2 == 0:
			return diff // 2
		return diff
	if len(v) == 3:
		diff1 = v[1] - v[0]
		diff2 = v[2] - v[1]
		if diff1 == diff2:
			return diff1
		else:
			return -1
print(check(bs))


n = int(input())
l = list(map(int, input().split()))
se = list(set(l))
se.sort()
if len(se) == 2:
	d = abs(se[0] - se[1])
	if d % 2 == 0:
		print(d // 2)
	else:
		print(d)
	exit()
if len(se) == 1:
	print(0)
	exit()
d = abs(se[1] - se[0])
for i in range(2, len(se)):
	if se[i] - d != se[1]:
		print(-1)
		exit()
print(d)


n = int(input())
a = sorted(set(map(int, input().split())))
if len(a) > 3:
	print(-1)
elif len(a) == 3:
	print(-1 if 3 * a[1] != sum(a) else a[2] - a[1])
elif len(a) == 2:
	print(a[1] - a[0] if (a[1] - a[0]) % 2 else (a[1] - a[0]) // 2)
else:
	print(0)


_ = input()
m = {int(x) for x in input().split()}
if len(m) > 3:
	print(-1)
	exit
if len(m) == 3:
	x = sorted(list(m))
	d = x[2] - x[1]
	if x[0] + d == x[1]:
		print(d)
	else:
		print(-1)
if len(m) == 2:
	x = sorted(list(m))
	d = x[1] - x[0]
	if d % 2 == 0:
		print(d // 2)
	else:
		print(d)
if len(m) == 1:
	print(0)


from math import *
n = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
if (mx - mn) % 2 == 1:
	d = mx - mn
else:
	d = (mx - mn) // 2
mid = mn + d
for i in range(n):
	if a[i] < mid:
		a[i] += d
	if a[i] > mid:
		a[i] -= d
	if a[i] != mid:
		print(-1)
		break
else:
	print(d)


def canEqualise(array):
	uniques = sorted(set(array))
	flag = 0
	if len(uniques) == 1:
		print(0)
	elif len(uniques) == 2:
		x = uniques[1] - uniques[0]
		for i in range(x):
			if uniques[1] - i == uniques[0] + i:
				print(i)
				flag = 1
				break
			elif uniques[1] - i == uniques[0]:
				print(i)
				flag = 1
				break
		if flag == 0:
			print(str(x))
	elif len(uniques) == 3:
		if uniques[2] - uniques[1] == uniques[1] - uniques[0]:
			X = uniques[2] - uniques[1]
			print(str(X))
		else:
			print('-1')
	else:
		print('-1')
n = int(input())
integers = list(map(int, input().split()))
canEqualise(integers)


N = int(input())
a = list(set(list(map(int, input().split()))))

def mean():
	sum = 0
	min = a[0]
	for i in a:
		sum += i
		if i < min:
			min = i
	return (sum // len(a), min)

def modulus(a):
	if a < 0:
		return -1 * a
	return a
flag = False
if len(a) > 3:
	print(-1)
elif len(a) == 2:
	if (a[0] + a[1]) % 2 == 0:
		temp = (a[0] + a[1]) // 2
		if a[0] > a[1]:
			print(a[0] - temp)
		else:
			print(a[1] - temp)
	elif a[0] > a[1]:
		print(a[0] - a[1])
	else:
		print(a[1] - a[0])
else:
	(const, D) = mean()
	D = const - D
	for i in a:
		if i == const:
			continue
		elif i < const:
			if i + D != const:
				print(-1)
				flag = True
				break
		elif i - D != const:
			print(-1)
			flag = True
			break
	if flag == False:
		print(modulus(D))


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = sorted(list(set(il())))
x = len(l)
if x == 1:
	print(0)
elif x == 2:
	y = sum(l) // 2
	if l[1] - y == y - l[0]:
		print(l[1] - y)
	else:
		print(l[1] - l[0])
elif x == 3:
	if l[2] - l[1] == l[1] - l[0]:
		print(l[2] - l[1])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
y = list(sorted(set(l)))
if len(y) > 3:
	print(-1)
elif len(y) == 1:
	print(0)
elif len(y) == 2:
	c = (y[1] - y[0]) / 2
	if c % 1 == 0:
		print(int(c))
	else:
		print(y[1] - y[0])
elif len(y) == 3:
	if y[1] - y[0] == y[2] - y[1]:
		print(y[1] - y[0])
	else:
		print(-1)


import sys, os
f = lambda : list(map(int, input().split()))
if 'local' in os.environ:
	sys.stdin = open('./input.txt', 'r')

def solve():
	n = f()[0]
	a = f()
	b = sorted(a)
	if len(set(b)) == 1:
		print(0)
	elif len(set(b)) == 2:
		if (b[n - 1] - b[0]) % 2:
			print(b[n - 1] - b[0])
		else:
			print((b[n - 1] - b[0]) // 2)
	else:
		if (b[n - 1] + b[0]) % 2:
			print(-1)
			return
		c = (b[n - 1] + b[0]) // 2
		d = [b[n - 1], b[0], c]
		for i in b:
			if i not in d:
				print(-1)
				return
		print((b[n - 1] - b[0]) // 2)
solve()


n = int(input())
a = list(set([int(num) for num in input().split()]))
a.sort()
if len(a) > 3:
	print('-1')
elif len(a) == 1:
	print(0)
elif len(a) == 2:
	diff = a[1] - a[0]
	if diff % 2:
		print(diff)
	else:
		print(int(diff / 2))
elif a[1] - a[0] != a[2] - a[1]:
	print(-1)
else:
	print(a[1] - a[0])


n = int(input())
l = list(map(int, input().split(' ')))
ans = -1
for i in range(20001):
	flag = False
	cnt = l[-1] + i
	for j in range(n):
		if l[j] + i != cnt and l[j] - i != cnt and (l[j] != cnt):
			break
		if j == n - 1:
			flag = True
	cnt = l[-1] - i
	for j in range(n):
		if l[j] + i != cnt and l[j] - i != cnt and (l[j] != cnt):
			break
		if j == n - 1:
			flag = True
	cnt = l[-1]
	for j in range(n):
		if l[j] + i != cnt and l[j] - i != cnt and (l[j] != cnt):
			break
		if j == n - 1:
			flag = True
	if flag:
		ans = i
		break
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
mid = (l[0] + l[n - 1]) // 2
req = mid - l[0]
x = 0
c = 1
for i in range(n - 1):
	if l[i] != l[i + 1]:
		c += 1
for i in range(n):
	if l[i] + req == mid or l[i] - req == mid or l[i] == mid:
		x += 1
	elif c == 2:
		print(l[n - 1] - l[0])
		break
	else:
		print(-1)
		break
if x == n:
	print(req)


n = int(input())
l = list(map(int, input().split()))
b = sorted(list(set(l)))
m = len(b)
if m != 1:
	if m == 2:
		if b[0] % 2 == 0 and b[1] % 2 == 0 or (b[0] % 2 != 0 and b[1] % 2 != 0):
			D = abs(b[1] - b[0]) // 2
		else:
			D = b[1] - b[0]
			D = abs(D)
	elif m == 3:
		if b[1] - b[0] == b[-1] - b[-2]:
			D = b[1] - b[0]
			D = abs(D)
		else:
			D = -1
	else:
		D = -1
	print(D)
else:
	print(0)


n = int(input())
a = [int(e) for e in input().split()]
st = set()
for i in a:
	st.add(i)
b = sorted(list(st))
if len(st) > 3:
	print(-1)
elif len(st) == 3:
	if b[0] + b[2] == b[1] * 2:
		print(b[1] - b[0])
	else:
		print(-1)
elif len(st) == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
else:
	print(0)


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter

def solve():
	n = IN()
	a = LI()
	b = sorted(set(a))
	x = len(b)
	if x > 3:
		print(-1)
	elif x == 1:
		print(0)
	elif x == 2:
		if (b[1] - b[0]) % 2 == 0:
			print((b[1] - b[0]) // 2)
		else:
			print(b[1] - b[0])
	elif b[-1] + b[0] == 2 * b[1]:
		print(b[1] - b[0])
	else:
		print(-1)
for i in range(1):
	solve()


input()
X = sorted(set(list(map(int, input().split()))))
print(0 if len(X) == 1 else (X[-1] - X[-2] if (X[-1] - X[-2]) % 2 == 1 else (X[-1] - X[-2]) // 2) if len(X) == 2 else X[-1] - X[-2] if len(X) <= 3 and X[-1] - X[-2] == X[1] - X[0] else -1)


n = int(input())
a = list(map(int, input().split()))
D = 0
s = []
for o in range(0, 150):
	f = True
	D = 0
	for i in a:
		if D == 0:
			D = max(i, o) - min(i, o)
		elif i + D != o and i - D != o and (i != o):
			f = False
	if f:
		s.append(D)
if s:
	print(min(s))
else:
	print(-1)


def canEqualise(array):
	uniques = sorted(set(array))
	if len(uniques) == 1:
		print('0')
	elif len(uniques) == 2:
		if (uniques[1] - uniques[0]) % 2 == 0:
			print(int((uniques[1] - uniques[0]) / 2))
		else:
			print(str(uniques[1] - uniques[0]))
	elif len(uniques) == 3:
		if uniques[2] - uniques[1] == uniques[1] - uniques[0]:
			X = uniques[2] - uniques[1]
			print(str(X))
		else:
			print('-1')
	else:
		print('-1')
n = int(input())
array = list(map(int, input().split()))
canEqualise(array)


def solve(nums):
	if len(nums) < 2:
		return 0
	if len(nums) < 3:
		diff = nums[1] - nums[0]
		return diff if diff % 2 == 1 else diff // 2
	if len(nums) == 3 and nums[2] - nums[1] == nums[1] - nums[0]:
		return nums[2] - nums[1]
	return -1
input()
print(solve(sorted(list(set((int(tok) for tok in input().split()))))))


n = int(input())
arr = list(map(int, input().split()))
new = sorted(set(arr))
k = len(new)
if k > 3:
	print(-1)
elif k == 1:
	print(0)
elif k == 2:
	if (new[1] - new[0]) % 2 == 0:
		print((new[1] - new[0]) // 2)
	else:
		print(new[1] - new[0])
elif new[1] - new[0] == new[2] - new[1]:
	print(new[1] - new[0])
else:
	print(-1)


n = int(input())
numbers = list(map(int, input().split()))
m = 1000
for i in range(-100, 200, 1):
	new = [i for _ in range(n)]
	for j in range(n):
		new[j] = new[j] - numbers[j]
	pos = 1000
	neg = -1000
	zero = 0
	valid = True
	for j in range(n):
		if new[j] > 0:
			if pos == 1000:
				pos = new[j]
			elif pos != new[j]:
				valid = False
				break
		if new[j] < 0:
			if neg == -1000:
				neg = new[j]
			elif neg != new[j]:
				valid = False
				break
	if valid:
		if pos == 1000:
			if neg == -1000:
				m = 0
			elif abs(neg) < m:
				m = abs(neg)
		elif neg == -pos:
			if pos < m:
				m = pos
if m == 1000:
	print(-1)
else:
	print(m)


import sys
n = int(input())
inp = set(map(int, input().split()))
inp = sorted(inp)
inp = list(inp)
maxi = max(inp)
mini = min(inp)
if max == mini:
	print(0)
	exit()
flag = True
for i in range(maxi):
	num = inp[0] + i
	D = i
	flag = True
	for j in range(1, len(inp)):
		if inp[j] - i == num or inp[j] == num:
			pass
		else:
			flag = False
			break
	if flag == True:
		print(D)
		exit()
	else:
		pass
if flag == False:
	print(-1)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb = RI()
arr = RMI()
(a, b) = (max(arr), min(arr))
if (a - b) % 2 == 0:
	diff = (a - b) // 2
	valid = [a, b, a - diff]
else:
	diff = a - b
	valid = [a, b]
for i in arr:
	if i not in valid:
		diff = -1
		break
print(diff)


n = int(input())
a = list(map(int, input().split()))
mapped = {}
for i in range(n):
	if a[i] in mapped.keys():
		mapped[a[i]] += 1
	else:
		mapped[a[i]] = 1
setted = list(mapped.keys())
if len(mapped) == 1:
	print(0)
elif len(mapped) == 2:
	summ = sum(setted)
	if summ % 2 == 0:
		ans = abs(setted[0] - setted[1]) / 2
		print(int(ans))
	else:
		ans = abs(setted[0] - setted[1])
		print(ans)
elif len(mapped) == 3:
	setted.sort()
	if setted[1] - setted[0] == setted[2] - setted[1]:
		ans = setted[1] - setted[0]
		print(ans)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = [int(x) for x in input().split()]
a = list(set(a))
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[0] - a[1]) % 2 == 0:
		print(abs(a[0] - a[1]) // 2)
	else:
		print(abs(a[0] - a[1]))
elif len(a) == 3:
	a.sort()
	if a[1] - a[0] == a[2] - a[1]:
		print(a[1] - a[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
if len(set(a)) == 1:
	print(0)
elif len(set(a)) == 2:
	a.sort()
	d = (a[n - 1] - a[0]) / 2
	if (a[n - 1] - a[0]) / 2 != (a[n - 1] - a[0]) // 2:
		print(a[n - 1] - a[0])
	else:
		print(int(d))
else:
	a.sort()
	d = (a[n - 1] - a[0]) / 2
	if (a[n - 1] - a[0]) / 2 != (a[n - 1] - a[0]) // 2:
		print(-1)
	else:
		f = a[n - 1] - int(d)
		flag = 1
		for i in range(n):
			if a[i] + d != f and a[i] - d != f and (a[i] != f):
				flag = 0
		if flag == 1:
			print(int(d))
		else:
			print(-1)


import os
import sys
from io import BytesIO, IOBase
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
dif = {}
for i in range(n):
	dif[l[n - 1] - l[i]] = None
dif = list(dif.keys())
if len(dif) == 1:
	print('0')
elif len(dif) == 2:
	if dif[0] % 2 == 0:
		print(dif[0] // 2)
	else:
		print(dif[0])
elif len(dif) == 3:
	if dif[0] % dif[1] == 0:
		if dif[1] == 1 and dif[0] == 2:
			print('1')
		elif dif[1] == 1 and dif[0] != 2:
			print('-1')
		else:
			print(dif[1])
	else:
		print('-1')
else:
	print('-1')


n = int(input())
a = list(map(int, input().split()))
L = max(a)
l = min(a)
z = False
if (L - l) % 2 == 1:
	for i in a:
		if i != L and i != l:
			z = True
	if z:
		print(-1)
	else:
		print(L - l)
else:
	for i in a:
		if i != l and i != L and (2 * i != L + l):
			z = True
	if z:
		print(-1)
	else:
		print((L - l) // 2)


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) > 3:
	print('-1')
elif len(set(a)) == 1:
	print('0')
elif len(set(a)) == 2:
	if (min(a) + max(a)) % 2 == 0:
		print((max(a) - min(a)) // 2)
	else:
		print(max(a) - min(a))
else:
	a = list(set(a))
	a.sort()
	if a[2] - a[1] == a[1] - a[0]:
		print(a[-1] - a[-2])
	else:
		print('-1')


n = int(input())
a = list(map(int, input().split()))
b = set(a)
if len(b) > 3:
	print(-1)
else:
	z = sorted(b)
	if len(z) == 1:
		print(0)
	elif len(z) == 2:
		if (z[0] - z[1]) % 2:
			print(max(z) - min(z))
		else:
			print((max(z) - min(z)) // 2)
	elif z[0] - z[1] == z[1] - z[2]:
		print(z[2] - z[1])
	else:
		print(-1)


n = int(input())
l = [int(x) for x in input().split()]
minn = min(l)
maxx = max(l)
midd = (maxx + minn) / 2
ans = (maxx - minn) / 2
if midd not in l:
	if midd == int(midd):
		ans = (maxx - minn) / 2
	else:
		ans = maxx - minn
for i in l:
	if i == minn or i == maxx or i == midd:
		pass
	else:
		ans = -1
print(int(ans))


n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(-1000, 1000):
	d = []
	for j in a:
		d.append(abs(j - i))
		d = list(set(d))
	if len(d) == 1 or (len(d) == 2 and 0 in d):
		ans.append(sum(d))
else:
	if len(ans) == 0:
		print(-1)
	else:
		print(min(ans))


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

def solve(arr):
	(Max, Min) = (max(arr), min(arr))
	rem = 0
	for i in range(len(arr)):
		if arr[i] != Max and arr[i] != Min:
			rem = arr[i]
			break
	if rem == 0:
		if (Max + Min) % 2 == 0:
			return (Max + Min) // 2 - Min
		else:
			return Max - Min
	if arr.count(Max) + arr.count(Min) + arr.count(rem) == len(arr):
		if abs(Max - rem) == abs(Min - rem):
			return Max - rem
		else:
			return -1
	else:
		return -1
print(solve(data))


def solve(A):
	unique_elems = set(A)
	if len(unique_elems) == 1:
		return 0
	if len(unique_elems) == 2:
		(mn, mx) = sorted(unique_elems)
		candidate = mx - mn
		D = candidate // 2
		if mx - D == mn + D:
			return D
		else:
			return candidate
	(max_A, min_A) = (max(A), min(A))
	mid_val = (max_A + min_A) // 2
	D = mid_val - min_A
	for x in A:
		if x < mid_val and x + D != mid_val:
			return -1
		elif x > mid_val and x - D != mid_val:
			return -1
	return D
n = int(input())
A = list(map(int, input().split()))
print(solve(A))


n = int(input())
A = [int(x) for x in input().split()]
sA = set(A)
if len(sA) == 1:
	print(0)
elif len(sA) == 2:
	(a, b) = list(sA)
	if abs(a - b) % 2 == 0:
		print(abs(a - b) // 2)
	else:
		print(abs(a - b))
elif len(sA) == 3:
	(a, b, c) = sorted(list(sA))
	if a + c != 2 * b:
		print(-1)
	else:
		print(b - a)
else:
	print(-1)


import sys
num = int(input())
inputs = []
raw = input().split()
inputs = [int(item) for item in raw]
a = -1
b = -1
c = -1
ans = 0
for item in inputs:
	if a == -1:
		a = item
	elif b == -1 and item != a:
		b = item
	elif c == -1 and item != a and (item != b):
		c = item
	elif item != a and item != b and (item != c) and (a != -1) and (b != -1) and (c != -1):
		ans = -1
if ans != -1:
	if b == -1 and c == -1:
		ans = 0
	elif c == -1:
		if abs(a - b) % 2 == 0:
			ans = int(abs(a - b) / 2)
		else:
			ans = abs(a - b)
	elif abs(a - b) == abs(a - c):
		ans = abs(a - b)
	elif abs(a - b) == abs(b - c):
		ans = abs(a - b)
	elif abs(a - c) == abs(b - c):
		ans = abs(a - c)
	else:
		ans = -1
print(ans)


import sys
from collections import defaultdict
n = int(input())
nums = [int(i) for i in input().split()]
same = True
for i in range(1, len(nums)):
	if nums[i] != nums[i - 1]:
		same = False
		break
if same:
	print(0)
	sys.exit()
D = 1
found = False
while D <= 101:
	num_dict = defaultdict(int)
	for i in nums:
		num_dict[i] += 1
		num_dict[i - D] += 1
		num_dict[i + D] += 1
	for i in num_dict:
		if num_dict[i] == n:
			found = True
			break
	if found:
		break
	D += 1
if found:
	print(D)
else:
	print(-1)


from collections import *
n = int(input())
l = list(map(int, input().split()))
d = Counter(l)
if len(d) > 3:
	print(-1)
	exit()
elif len(d) == 2:
	val = list(d.keys())
	val.sort()
	if sum(val) % 2 == 0:
		print((val[1] - val[0]) // 2)
	else:
		print(val[1] - val[0])
elif len(d) == 3:
	val = list(d.keys())
	val.sort()
	if val[1] - val[0] == val[2] - val[1]:
		print(val[1] - val[0])
	else:
		print(-1)
else:
	print(0)


def main():
	n = int(input())
	array = list(map(int, input().split()))
	if n == 1:
		print(0)
		return
	dist = set()
	array.sort()
	for i in array:
		if i not in dist:
			dist.add(i)
	if len(dist) == 2:
		if (array[-1] - array[0]) % 2 != 0:
			print(array[-1] - array[0])
			return
	if (array[-1] - array[0]) % 2 != 0:
		print(-1)
		return
	d = (array[-1] - array[0]) // 2
	req = array[0] + d
	for i in range(n):
		if array[i] < req:
			array[i] += d
		elif array[i] > req:
			array[i] -= d
		if array[i] != req:
			print(-1)
			return
	print(d)
main()


def quick_sort(lst):
	if lst == []:
		return []
	pivot = lst[0]
	small_elements = []
	large_elements = []
	for i in lst[1:]:
		if i < pivot:
			small_elements += [i]
		else:
			large_elements += [i]
	return quick_sort(small_elements) + [pivot] + quick_sort(large_elements)
n = int(input())

def convert(string):
	return string.split(sep=None, maxsplit=-1)

def toint(lst):
	result = []
	for i in lst:
		result.append(int(i))
	return result
s = toint(convert(input()))
lst = []
for i in s:
	if not i in lst:
		lst = lst + [i]
l = len(lst)
if l == 0 or l == 1:
	print(0)
elif l == 2:
	if (lst[0] + lst[1]) % 2 == 0:
		print(abs(lst[0] - lst[1]) // 2)
	else:
		print(abs(lst[1] - lst[0]))
elif l == 3:
	lst = quick_sort(lst)
	if lst[1] - lst[0] == lst[2] - lst[1]:
		print(abs(lst[1] - lst[0]))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
st = list(set(a))
st.sort()
if len(st) == 1:
	print(0)
elif len(st) == 2:
	if st[1] - st[0] & 1:
		print(st[1] - st[0])
	else:
		print((st[1] - st[0]) // 2)
elif len(st) == 3:
	tt = set()
	for i in range(1, 3):
		tt.add(st[i] - st[i - 1])
	if len(tt) == 1:
		print(list(tt)[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = sorted(list(map(int, input().split())))
mat = []
if len(set(a)) == 1:
	print(0)
else:
	for i in range(1, n):
		if a[i] != a[0]:
			p = abs(a[i] - a[0])
			if p % 2 == 0:
				mat.append([p // 2, p])
			else:
				mat.append([p])
	ans = mat[0]
	for i in range(1, len(mat)):
		s = set(mat[i])
		ans = list(s.intersection(ans))
	if len(ans) >= 1:
		print(ans[0])
	else:
		print(-1)


N = int(input())
nums = [int(i) for i in input().split()]
(maxi, mini) = (max(nums), min(nums))
check = True
for i in nums:
	if i not in (maxi, mini):
		check = False
		break
if (maxi - mini) % 2 != 0:
	if check == True:
		print(maxi - mini)
	else:
		print(-1)
else:
	double_check = True
	D = (maxi - mini) // 2
	for i in nums:
		if i not in (mini, mini + D, maxi):
			double_check = False
			break
	if double_check == True:
		print(D)
	elif check == True:
		print(maxi - mini)
	else:
		print(-1)


n = int(input())
a = [int(i) for i in input().split()]
l = []
hash = {}
c = 0
for i in range(n):
	if a[i] not in hash:
		l.append(a[i])
		hash[a[i]] = 1
		c += 1
if c == 1:
	print(0)
elif c == 2:
	d = abs(l[1] - l[0])
	if d % 2 == 0:
		d = d / 2
	print(int(d))
elif c == 3:
	l.sort()
	if (l[0] + l[2]) / 2 == l[1]:
		d = l[1] - l[0]
		print(d)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
maxi = max(l)
mini = min(l)
median = (maxi + mini) / 2
if median in l and len(set(l)) == 3:
	print(int(maxi - median))
elif len(set(l)) == 2:
	if (maxi + mini) % 2 == 0:
		print(maxi - (maxi + mini) // 2)
	else:
		print(maxi - mini)
elif n == 1 or len(set(l)) == 1:
	print(0)
else:
	print(-1)


def main():
	N = int(input())
	A = [int(i) for i in input().split()]
	INF = 10 ** 3
	D = INF
	for p in range(1, 101):
		B = {abs(a - p) for a in A}
		if len(B - {0}) == 1 or len(B) == 1:
			c = max((abs(a - p) for a in A))
			D = min(D, c)
	print(D if D != INF else -1)
main()


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
a = set(a)
if len(a) > 3:
	print(-1)
	exit()
a = sorted(a)
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(abs(a[0] - a[1]))
else:
	pv = abs(a[0] - a[1])
	vt = abs(a[1] - a[2])
	if pv == vt:
		print(pv)
	else:
		print(-1)


def fun(l, x):
	i = 0
	while i < len(l) and l[i] == x:
		i += 1
	c = 0
	if i < len(l):
		c = abs(l[i] - x)
	else:
		return 0
	for i in l:
		if i == x:
			continue
		if abs(i - x) != c:
			return -1
	return c
n = int(input())
l = list(map(int, input().split()))
ans = 1000001
for i in range(1, 101):
	temp = fun(l, i)
	if temp > -1:
		ans = min(ans, temp)
if ans < 1000001:
	print(ans)
else:
	print(-1)


import sys

def check_mid(arr, D):
	if len(arr) % 2 != 0:
		mid = len(arr) // 2
	else:
		mid = len(arr) // 2 + 1
	if arr[-1] + D == arr[mid]:
		return True
	else:
		return False

def main():
	sys.stdin.readline()
	numbers = list(map(int, sys.stdin.readline().split()))
	numbers = set(numbers)
	if len(numbers) == 1:
		sys.stdout.write('0')
		return
	numbers = list(numbers)
	numbers.sort()
	x = numbers.pop()
	D = x - max(numbers)
	numbers.append(x)
	numbers.sort(reverse=True)
	x = numbers.pop()
	D_2 = min(numbers) - x
	numbers.append(x)
	if abs(D) == abs(D_2):
		if len(numbers) >= 3:
			flag = check_mid(numbers, abs(D))
			if flag:
				if abs(D) % 2 == 0 and abs(D) != 2:
					if numbers[0] - abs(D) == numbers[-1] + abs(D):
						sys.stdout.write(f'{abs(D)}')
					else:
						sys.stdout.write(f'{abs(D) // 2}')
				else:
					sys.stdout.write(f'{abs(D)}')
			else:
				sys.stdout.write(f'{-1}')
		elif abs(D) % 2 == 0:
			sys.stdout.write(f'{abs(D) // 2}')
		else:
			sys.stdout.write(f'{abs(D)}')
	else:
		sys.stdout.write(f'{-1}')
main()


input()
nums = list(sorted(set(map(int, input().split()))))
if len(nums) > 3:
	print('-1')
elif len(nums) == 3:
	if nums[0] + nums[-1] != nums[1] * 2:
		print('-1')
	else:
		print(nums[1] - nums[0])
elif len(nums) == 1:
	print('0')
elif (nums[0] + nums[1]) % 2:
	print(nums[1] - nums[0])
else:
	print((nums[1] - nums[0]) // 2)


n = int(input())
a = sorted(set(map(int, input().split())))
m = max(a) - min(a)
if m % 2 and len(a) == 2:
	print(m)
elif not m % 2 and len(a) == 3 and (abs(a[0] - a[1]) == abs(a[1] - a[2])) or len(a) == 2 or len(a) == 1:
	print(m // 2)
else:
	print(-1)


n = int(input())
ar = list(map(int, input().split()))
s = set(ar)
b = []
for i in range(len(s)):
	b.append(s.pop())
b.sort()
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	if b[2] - b[1] == b[1] - b[0]:
		print(b[2] - b[1])
	else:
		print(-1)
elif len(b) == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
elif len(b) == 1:
	print(0)


n = int(input())
m = input().split()
for i in range(len(m)):
	m[i] = int(m[i])
mi = min(m)
ma = max(m)
if (ma - mi) % 2 == 0:
	d = (ma - mi) // 2
	l = set()
	l.add(mi + d)
	for i in m:
		if i < mi + d:
			l.add(i + d)
		elif i > mi + d:
			l.add(i - d)
	if len(l) <= 1:
		print(d)
		exit(0)
l = set()
d = ma - mi
l.add(ma)
for i in m:
	if i < ma:
		l.add(i + d)
if len(l) <= 1:
	print(d)
	exit(0)
print(-1)


a = []
b = []
import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(n):
	if a[i] not in b:
		b.append(a[i])
l = len(b)
if l == 1:
	print(0)
	sys.exit()
if l == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
	sys.exit()
if l > 3 or 2 * b[1] != b[0] + b[2]:
	print(-1)
	sys.exit()
print(b[2] - b[1])


n = int(input())
v = [0 for i in range(101)]
l = [int(a) for a in input().split()]
w = [0, 0, 0, 0]
k = 0
for i in l:
	if v[i] == 0:
		w[k] = i
		k += 1
	v[i] += 1
	if k > 3:
		break
result = 1
d = 0
if k > 3:
	result = 0
f3w = [w[i] for i in range(min(3, k))]
f3w.sort()
if k > 2:
	if f3w[2] - f3w[1] != f3w[1] - f3w[0]:
		result = 0
if k == 3:
	d = f3w[1] - f3w[0]
if k == 2:
	if (f3w[1] - f3w[0]) % 2 == 0:
		d = int((f3w[1] - f3w[0]) / 2)
	else:
		d = f3w[1] - f3w[0]
if result == 1:
	print('%s' % d)
else:
	print('-1')


import sys
MOD = 1000000007
no = lambda : print('NO')
yes = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
test_case = 1

def ans():
	n = cin()
	arr = ari()
	un = list(set(arr))
	un.sort()
	ans = -1
	prev = -1
	loc = 0
	for i in range(0, 101):
		loc = 0
		prev = -1
		for j in un:
			if prev == -1:
				prev = j + i
				continue
			if prev == j:
				continue
			if prev != j - i:
				loc = 1
				break
		if loc == 0:
			print(i)
			return
	print(-1)
	return
for _ in range(test_case):
	ans()


n = int(input())
s = [int(x) for x in input().split()]
s.sort()
for d in range(101):
	cnt = 0
	mediana = s[0] + d
	for i in range(len(s)):
		if s[i] + d != mediana and s[i] - d != mediana and (s[i] != mediana):
			break
		else:
			cnt += 1
	if cnt == n:
		print(d)
		exit()
print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	new = list(set(a))
	new = sorted(new)
	if len(new) > 3:
		print(-1)
	elif len(new) == 3:
		if new[1] - new[0] == new[2] - new[1]:
			print(new[1] - new[0])
		else:
			print(-1)
	elif len(new) == 2:
		if new[0] % 2 == new[1] % 2:
			print(sum(new) // 2 - new[0])
		else:
			print(new[1] - new[0])
	else:
		print(0)
testcase(1)


a = int(input())
n = list(map(int, input().split()))
arr = []
flag = 0
for i in range(0, len(n)):
	if not n[i] in arr:
		arr.append(n[i])
arr.sort()
if len(arr) > 3:
	print('-1')
elif len(arr) == 3:
	if arr[2] - arr[1] == arr[1] - arr[0]:
		print(round(arr[1] - arr[0]))
	else:
		print('-1')
elif len(arr) == 2:
	if (arr[1] - arr[0]) % 2 == 0:
		print(round((arr[1] - arr[0]) / 2))
	else:
		print(round(arr[1] - arr[0]))
elif len(arr) == 1:
	print('0')


N = int(input())
L = list(map(int, input().split()))
S = set(L)
if len(S) > 3:
	print(-1)
elif len(S) == 3:
	L = list(S)
	L.sort(reverse=True)
	if L[0] + L[2] == 2 * L[1]:
		print(L[0] - L[1])
	else:
		print(-1)
elif len(S) == 2:
	L = list(S)
	L.sort(reverse=True)
	if (L[0] - L[1]) % 2 == 0:
		print((L[0] - L[1]) // 2)
	else:
		print(L[0] - L[1])
else:
	print(0)


n = int(input())
arr = list(map(int, input().strip().split()))
arr = sorted(arr)
ans = 10000000000
for k in range(200):
	d = -1
	fl = 0
	for i in range(n):
		c = abs(arr[i] - k)
		if d == -1:
			d = c
		elif d != c and c > 0:
			fl = 1
	if fl == 0:
		ans = min(ans, d)
if ans == 10000000000:
	print(-1)
else:
	print(ans)


a = int(input())
x = list(map(int, input().split()))
caf = x.copy()
x = list(set(x))
x = sorted(x)
r = []
for i in range(len(x) - 1):
	r.append(x[i + 1] - x[i])
if len(x) == 1:
	print(0)
	exit()
if len(r) > 2:
	print(-1)
else:
	if len(r) == 2:
		if len(set(r)) == 1:
			r = list(r)
			print(r[0])
			exit()
		else:
			print(-1)
			exit()
	if len(caf) == 2:
		if r[0] % 2 == 0:
			print(r[0] // 2)
		else:
			print(x[1] - x[0])
	elif r[0] % 2 == 0 and len(x) == 2:
		print(r[0] // 2)
	else:
		print(r[0])


n = int(input())
a = list(map(int, input().rstrip().split()))
maxi = max(a)
mini = min(a)
c = 0
s = set(a)
if len(s) == 2:
	if (maxi - mini) % 2 == 0:
		print(int((maxi - mini) / 2))
	else:
		print(int(maxi - mini))
elif len(s) > 3:
	print(-1)
elif len(s) == 1:
	print(0)
else:
	for i in s:
		if i != mini and i != maxi:
			c = i
	if abs(maxi - c) == abs(c - mini):
		print(maxi - c)
	else:
		print(-1)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
uniq = []
for i in arr:
	if i not in uniq:
		uniq.append(i)
if len(uniq) == 1:
	print(0)
elif len(uniq) == 2:
	if uniq[0] % 2 == uniq[1] % 2 == 0 or (uniq[1] - uniq[0]) % 2 == 0:
		print(int((uniq[1] - uniq[0]) / 2))
	else:
		print(uniq[1] - uniq[0])
elif len(uniq) == 3:
	if 2 * uniq[len(uniq) // 2] == uniq[0] + uniq[-1]:
		print(uniq[len(uniq) // 2] - uniq[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort(reverse=True)
l2 = []
for i in l1:
	if i not in l2:
		l2.append(i)
if len(l2) == 3:
	if l2[0] - l2[1] == l2[1] - l2[2]:
		print(int(abs(l2[0] - l2[1])))
	else:
		print(-1)
elif len(l2) == 2:
	if (l2[0] + l2[1]) % 2 == 0:
		print(int((l2[0] - l2[1]) / 2))
	else:
		print(int(l2[0] - l2[1]))
elif len(l2) == 1:
	print(0)
else:
	print(-1)


N = int(input())
arr = [int(x) for x in input().split()]
ans = []
for x in range(1, 101):
	diff = 0
	flag = True
	for y in range(N):
		if abs(arr[y] - x) == 0:
			continue
		elif abs(arr[y] - x) == diff:
			continue
		elif abs(arr[y] - x) != diff and diff != 0:
			flag = False
			break
		else:
			diff = abs(arr[y] - x)
	if flag:
		ans.append(diff)
if len(ans):
	print(min(ans))
else:
	print(-1)


import sys
s = sys.stdin.read().split()
s.pop(0)
s = list(set((int(x) for x in s)))
s.sort()
if len(s) > 3:
	print('-1')
elif len(s) == 3:
	temp = s[1] - s[0]
	s[0] += temp
	s[2] -= temp
	if s[0] == s[1] and s[1] == s[2]:
		print(temp)
	else:
		print(-1)
elif len(s) == 1:
	print(0)
elif s[0] % 2 == 0 and s[1] % 2 == 1 or (s[1] % 2 == 0 and s[0] % 2 == 1):
	print(s[1] - s[0])
else:
	print(int(s[1] - (s[0] + s[1]) / 2))


lens = int(input())
arrs = [int(x) for x in input().split()]
arrs = sorted(set(arrs))
l = len(arrs)
if l == 1:
	print(0)
elif l == 2:
	d = arrs[1] - arrs[0]
	print([d // 2, d][d % 2])
elif l == 3:
	print([-1, arrs[1] - arrs[0]][arrs[1] - arrs[0] == arrs[2] - arrs[1]])
else:
	print(-1)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
mod = 10 ** 9 + 7
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

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

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	n = int(input())
	arr = list_input()
	d = 1000
	for num in range(1, 101):
		k = 'undefined'
		flag = True
		for i in arr:
			if num > i:
				temp = num - i
			elif num < i:
				temp = i - num
			else:
				continue
			if k == 'undefined':
				k = temp
			elif k != temp:
				flag = False
				break
		if flag:
			if k != 'undefined':
				d = min(d, k)
			else:
				d = 0
	if d == 1000:
		print(-1)
		return
	print(d)
t = 1
for _ in range(t):
	solve()


n = int(input())
IN = input().split()
A = [0] * n
for i in range(0, n):
	A[i] = int(IN[i])
A = list(set(A))
A.sort()
if len(A) > 3:
	print(-1)
if len(A) == 3:
	res = (A[2] - A[0]) // 2
	if A[1] == A[0] + res and A[2] == A[1] + res:
		print(res)
	else:
		print(-1)
if len(A) == 2:
	res = A[1] - A[0]
	if res % 2 == 0:
		res //= 2
	print(res)
if len(A) == 1:
	print(0)


input()
A = sorted(set(map(int, input().split())))
if len(A) < 2:
	print(0)
else:
	x = A[1] - A[0]
	if len(A) < 3:
		print(x if x % 2 else x // 2)
	else:
		print(x if len(A) < 4 and A[2] - A[1] == x else -1)


n = int(input())
x = [int(z) for z in input().split()]
s = set()
for i in x:
	s.add(i)
ans = -1
if len(s) == 1:
	ans = 0
elif len(s) == 2:
	a = max(x)
	b = min(x)
	avg = (a + b) / 2
	diff = abs(a - b)
	ans = min(diff, int(abs(a - avg))) if (a + b) % 2 == 0 else diff
elif len(s) == 3:
	a = max(x)
	b = min(x)
	avg = (a + b) / 2
	if avg in s:
		ans = abs(a - avg)
print(int(ans))


n = int(input())
a = list(map(int, input().split()))
ans = -100
length = len(set(a))
b = list(set(list(a)))
b.sort()
if length > 3:
	ans = -1
elif length == 1:
	ans = 0
elif length == 2:
	if (max(b) - min(b)) % 2 == 1:
		ans = b[1] - b[0]
	else:
		ans = (max(b) - min(b)) // 2
elif b[2] - b[1] == b[1] - b[0]:
	ans = b[2] - b[1]
else:
	ans = -1
print(ans)


from sys import stdin

def readLine():
	return stdin.readline().strip()

def readInt():
	return int(readLine())

def readInts():
	return list(map(int, readLine().split()))

def allEqual(D, N, A):
	for e in A:
		if e != A[0] and abs(e - A[0]) != D:
			return False
	return True

def isSolution(D, N, A):
	if allEqual(D, N, A):
		return True
	A[0] += D
	if allEqual(D, N, A):
		return True
	A[0] -= 2 * D
	if allEqual(D, N, A):
		return True
	A[0] += D
	return False

def solve(N, A):
	for D in range(0, 101):
		if isSolution(D, N, A):
			return D
	return -1

def main():
	N = readInt()
	A = readInts()
	print(solve(N, A))
main()


a = int(input())
x = input()
L = x.split()
l2 = []
f = True
for a in L:
	if int(a) not in l2:
		l2.append(int(a))
	if len(l2) > 3:
		f = False
		break
if f == False:
	print('-1')
else:
	l2.sort()
	if len(l2) == 1:
		print(0)
	if len(l2) == 2:
		if (l2[1] - l2[0]) % 2 == 0:
			print((l2[1] - l2[0]) // 2)
		else:
			print(l2[1] - l2[0])
	if len(l2) == 3:
		if l2[1] - l2[0] == l2[2] - l2[1]:
			print(l2[1] - l2[0])
		else:
			print(-1)


n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
	if a[i] not in b:
		b.append(a[i])
if len(b) > 3:
	print(-1)
elif len(b) == 1:
	print(0)
elif len(b) == 2:
	if (max(b) - min(b)) % 2 == 0:
		print((max(b) - min(b)) // 2)
	else:
		print(max(b) - min(b))
else:
	for i in range(3):
		if min(b) < b[i] < max(b):
			c = b[i]
	if c - min(b) == max(b) - c:
		print(c - min(b))
	else:
		print(-1)


n = int(input())
arr = list(map(int, input().split()))[:n]
modifiedArr = sorted(list(set(arr)))
n = len(modifiedArr)
if n == 1:
	print(0)
elif n == 2:
	d = modifiedArr[1] - modifiedArr[0]
	if d & 1:
		print(d)
	else:
		print(d // 2)
elif n == 3:
	if modifiedArr[2] - modifiedArr[1] == modifiedArr[1] - modifiedArr[0]:
		print(modifiedArr[2] - modifiedArr[1])
	else:
		print(-1)
else:
	print(-1)


def func(count, params):
	diff = []
	for x in params:
		for y in params:
			if x > y:
				if x - y not in diff:
					diff.append(x - y)
			elif x < y:
				if y - x not in diff:
					diff.append(y - x)
	if len(diff) == 0:
		print(0)
	elif len(diff) == 1:
		if diff[0] % 2 == 0:
			print(diff[0] // 2)
		else:
			print(diff[0])
	elif len(diff) == 2:
		diff = sorted(diff)
		if diff[0] == 0:
			if diff[1] % 2 == 0:
				print(diff[1] // 2)
			else:
				print(diff[1])
		else:
			print(diff[0])
	elif len(diff) == 3:
		diff = sorted(diff)
		if diff[0] == 0:
			if diff[2] != 2 * diff[1]:
				print(-1)
			else:
				print(diff[1])
		else:
			print(-1)
	else:
		print(-1)
count = int(input())
params = list(map(int, input().split()))
func(count, params)


c = int(input())
n = list(map(int, input().split()))
s_n = sorted(n)
pos = dict()
for num in s_n:
	pos[num] = True
key_count = len(pos.keys())
if key_count > 3:
	print(-1)
elif key_count == 3:
	key_l = sorted(list(pos.keys()))
	max_val = key_l[2]
	min_val = key_l[0]
	if (max_val + min_val) / 2 != key_l[1]:
		print(-1)
	else:
		print(key_l[2] - key_l[1])
elif key_count == 2:
	key_l = list(pos.keys())
	if (key_l[0] + key_l[1]) % 2 == 0:
		print(abs((key_l[0] + key_l[1]) // 2 - key_l[0]))
	else:
		print(abs(key_l[0] - key_l[1]))
else:
	print(0)


n = int(input().strip())
eles = set(map(int, input().strip().split()))
if len(eles) > 3:
	print(-1)
	exit(0)
the_list = sorted(list(eles))
if len(eles) == 3:
	if (the_list[0] + the_list[2]) % 2 == 0 and (the_list[0] + the_list[2]) / 2 == the_list[1]:
		print(the_list[1] - the_list[0])
	else:
		print(-1)
elif len(eles) == 2:
	if (the_list[0] + the_list[1]) % 2 == 0:
		print(min(int(abs(the_list[1] - the_list[0]) / 2), abs(the_list[1] - the_list[0])))
	else:
		print(abs(the_list[1] - the_list[0]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
from collections import Counter
c = Counter(l)
ln = len(c)
if ln > 3:
	print(-1)
else:
	l1 = []
	for i in c:
		l1.append(i)
	l1.sort()
	if ln == 3:
		if l1[-1] - l1[-2] == l1[-2] - l1[-3]:
			print(l1[-1] - l1[-2])
		else:
			print(-1)
	elif ln == 2:
		if (l1[0] + l1[1]) % 2 == 0:
			print((l1[0] + l1[1]) // 2 - l1[0])
		else:
			print(l1[1] - l1[0])
	else:
		print(0)


n = int(input())
a = list(map(int, input().split()))
D_min = 200
for target in range(1, 101):
	diff = abs(target - a[0])
	ok = True
	for val in a:
		if diff == 0:
			diff = abs(target - val)
		if abs(target - val) != diff and val != target:
			ok = False
			break
	if ok:
		D_min = min(D_min, diff)
print(-1 if D_min == 200 else D_min)


from sys import stdin

def ria(sep=''):
	if sep == '':
		return list(map(int, input().split()))
	else:
		return list(map(int, input().split(sep)))

def rsa(sep=''):
	if sep == '':
		return input().split()
	else:
		return input().split(sep)

def ri():
	return int(input())

def rd():
	return float(input())

def rs():
	return input()
N = ri()
A = ria()
inf = int(1000000000.0)
mi = inf
for i in range(-200, 301):
	s = set()
	for j in range(N):
		s.add(abs(i - A[j]))
	if len(s) == 1:
		l = list(s)
		mi = min(mi, l[0])
	if len(s) == 2:
		l = list(s)
		l.sort()
		if l[0] == 0:
			mi = min(mi, l[1])
print(mi if mi != inf else -1)


def line():
	return map(int, input().split())
input()
a = sorted(set(line()))
if len(a) > 3:
	print(-1)
elif len(a) == 3:
	if a[1] - a[0] != a[2] - a[1]:
		print(-1)
	else:
		print(a[1] - a[0])
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(a[1] - a[0])
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
a = []
for i in l:
	if i not in a:
		a.append(i)
a.sort()
if len(a) > 3:
	ans = -1
elif len(a) == 3:
	if sum(a) / 3 == a[1]:
		ans = (max(a) - min(a)) // 2
	else:
		ans = -1
elif len(a) == 2:
	if sum(a) % 2 == 1:
		ans = max(a) - min(a)
	else:
		ans = (max(a) - min(a)) // 2
else:
	ans = 0
print(ans)


try:
	a = int(input())
	b = input()
	b = b.split()
	for i in range(a):
		b[i] = int(b[i])
	t = (max(b) + min(b)) / 2
	u = (max(b) - min(b)) / 2
	if t == int(t):
		for i in range(a):
			if b[i] > t:
				if b[i] - t == u:
					continue
				else:
					raise ValueError
			if b[i] < t:
				if t - b[i] == u:
					continue
				else:
					raise ValueError
			if b[i] == t:
				continue
		print(int(u))
	elif len(set(b)) == 2:
		print(int(2 * u))
	else:
		raise ValueError
except ValueError:
	print(-1)


x = int(input())
num = list(sorted(set(map(int, input().split()))))

def difference(num):
	if len(num) > 3:
		print(-1)
	elif len(num) == 1:
		print(0)
	elif len(num) == 2:
		if (num[1] - num[0]) % 2 == 0:
			print((num[1] - num[0]) // 2)
		else:
			print(num[1] - num[0])
	else:
		c = num[1] - num[0]
		c1 = num[2] - num[1]
		if c == c1:
			print(c)
		else:
			print(-1)
difference(num)


n = int(input())
a = list(map(int, input().split()))
flag = 0
if len(set(a)) == 1:
	print(0)
elif len(set(a)) == 2 and (max(a) - min(a)) % 2 == 0:
	print((max(a) - min(a)) // 2)
elif len(set(a)) == 2 and (max(a) - min(a)) % 2 == 1:
	print(max(a) - min(a))
elif (max(a) - min(a)) % 2 == 1:
	print(-1)
else:
	posd = (max(a) - min(a)) // 2
	for i in range(n):
		if a[i] == min(a) or a[i] == max(a) or (a[i] == min(a) + posd and a[i] == max(a) - posd):
			flag += 1
	if flag == n:
		print(posd)
	else:
		print(-1)


N = int(input())
ls = sorted(list(set(map(int, input().split()))))
if len(ls) == 1:
	print(0)
elif len(ls) == 2:
	Sum = ls[0] + ls[1]
	if Sum % 2:
		print(ls[1] - ls[0])
	else:
		print(min(ls[1] - ls[0], ls[1] - Sum // 2))
elif len(ls) == 3:
	Sum = ls[0] + ls[2]
	if Sum % 2 or Sum // 2 != ls[1]:
		print(-1)
	else:
		print(ls[2] - ls[1])
else:
	print(-1)


n = input()
x = input().split()
set_x = set(x)
list_x = list(set_x)
length = len(list_x)
for x in range(length):
	list_x[x] = int(list_x[x])
list_x.sort()
if length > 1:
	diff = abs(list_x[0] - list_x[1])
if length > 2:
	for i in range(length - 1):
		new_diff = abs(list_x[i] - list_x[i + 1])
		if diff == new_diff:
			val = 1
		else:
			val = 0
if length == 2:
	if diff % 2 == 0:
		diff = diff // 2
		val = 1
	else:
		val = 1
if length == 1:
	val = -1
if length > 3:
	val = 0
if val == 1:
	print(diff)
elif val == 0:
	print(-1)
else:
	print(0)


def func(arr):
	uni = sorted(set(arr))
	if len(uni) == 1:
		print('0')
	elif len(uni) == 2:
		if uni[0] % 2 == 0 and uni[1] % 2 != 0 or (uni[0] % 2 != 0 and uni[1] % 2 == 0):
			print(abs(uni[1] - uni[0]))
		else:
			print(abs(uni[1] - uni[0]) // 2)
	elif len(uni) == 3:
		if uni[2] - uni[1] == uni[1] - uni[0]:
			X = uni[2] - uni[1]
			print(X)
		else:
			print(-1)
	else:
		print(-1)
n = int(input())
arr = list(map(int, input().split()))
func(arr)


def abs(x, y):
	if x > y:
		return x - y
	return y - x
n = int(input())
l = list(map(int, input().split()))
s = set(l)
s = sorted(s)
if len(s) == 1:
	print(0)
elif len(s) == 2:
	if abs(s[0], s[1]) % 2 == 0:
		print(int(abs(s[0], s[1]) / 2))
	else:
		print(abs(s[0], s[1]))
elif len(s) == 3:
	if abs(s[0], s[1]) != abs(s[1], s[2]):
		print(-1)
	else:
		print(int(abs(s[0], s[1])))
else:
	print(-1)


n = int(input())
arr = [int(x) for x in input().split(' ')]
arr.sort()
small = arr[0]
large = arr[-1]
tocheck = range(small, large + 1)
ans = []
for item in tocheck:
	flag = True
	newArr = []
	for x in arr:
		newArr.append(abs(item - x))
	newArr.sort()
	cand = newArr[-1]
	for x in newArr:
		if x == 0 or x == cand:
			continue
		else:
			flag = False
	if flag:
		ans.append(cand)
if len(ans):
	print(min(ans))
else:
	print(-1)


n = int(input())
z = [int(x) for x in input().split(' ')]
a = len(set(z))
if a not in [1, 2, 3]:
	print(-1)
else:
	b = list(set(z))
	b.sort()
	if a == 1:
		print(0)
	elif a == 2:
		if (b[1] - b[0]) % 2 == 0:
			print((b[1] - b[0]) // 2)
		else:
			print(b[1] - b[0])
	elif b[2] - b[1] == b[1] - b[0]:
		print(b[1] - b[0])
	else:
		print(-1)


n = int(input())
tab = list(map(int, input().split()))
valide = True
for d in range(500):
	vu = [0] * 1000
	for i in tab:
		vu[i + d] += 1
		if d and i - d >= 0:
			vu[i - d] += 1
		if d:
			vu[i] += 1
	if max(vu) >= n:
		print(d)
		valide = False
		break
if valide:
	print(-1)


n = int(input())
L = [int(x) for x in input().strip().split(' ')]
x = len(set(L))
if x > 3:
	print(-1)
elif x == 1:
	print(0)
elif x == 2:
	y = max(L) - min(L)
	if y / 2 == y // 2:
		print(y // 2)
	else:
		print(y)
else:
	L = list(set(L))
	L.sort()
	if L[1] - L[0] == L[2] - L[1]:
		print(L[1] - L[0])
	else:
		print(-1)


n = input()
data = set(map(int, input().split()))
num = sorted(data)
if len(num) > 2:
	big = num[-1]
	small = num[0]
	diff = (big - small) // 2
	com = small + diff
	if big - diff != com:
		print(-1)
	else:
		testing = set()
		testing.add(com)
		for i in num:
			if i < com:
				testing.add(i + diff)
			elif i == com:
				testing.add(i)
			else:
				testing.add(i - diff)
		if len(testing) == 1:
			print(diff)
		else:
			print(-1)
elif len(num) == 1:
	print(0)
else:
	lol = num[-1] - num[0]
	lol2 = (num[-1] - num[0]) // 2
	if num[0] + lol2 == num[-1] - lol2:
		print(lol2)
	else:
		print(lol)


n = int(input())
lst = [int(x) for x in input().split()]
setlst = set(lst)
if len(setlst) > 3:
	print('-1')
elif len(setlst) == 3:
	sortedlst = sorted(setlst)
	t1 = sortedlst[1] - sortedlst[0]
	t2 = sortedlst[2] - sortedlst[1]
	if t1 == t2:
		print(t1)
	else:
		print('-1')
elif len(setlst) == 2:
	sortedlst = sorted(setlst)
	temp = sortedlst[1] - sortedlst[0]
	fl = temp / 2
	if fl - int(fl) == 0:
		print(int(fl))
	else:
		print(sortedlst[1] - sortedlst[0])
else:
	print('0')


n = int(input())
a = list(map(int, input().split(' ')))
if n == 1:
	print(0)
else:

	def sameItem(a):
		if len(a) < 1:
			return True
		return len(a) == a.count(a[0])
	D = -1
	if sameItem(a) == True:
		D = 0
	a = set(a)
	a = sorted(a)
	if len(a) == 2:
		if (a[1] + a[0]) % 2 == 0:
			D = (a[1] + a[0]) // 2 - a[0]
		else:
			D = a[1] - a[0]
	elif len(a) == 3:
		if a[1] - a[0] == a[2] - a[1]:
			D = a[1] - a[0]
		else:
			D = -1
	print(D)


input()
l = list(map(int, input().split()))
ss = sorted(set(l))
if len(ss) > 3:
	print(-1)
elif len(ss) == 1:
	print(0)
elif len(ss) == 2:
	if (ss[1] - ss[0]) % 2 == 0:
		print((ss[1] - ss[0]) // 2)
	else:
		print(ss[-1] - ss[0])
elif ss[-1] - ss[1] == ss[1] - ss[0]:
	print(ss[1] - ss[0])
else:
	print(-1)


n = int(input())
s = set()
for i in input().split():
	s.add(int(i))
s = sorted(s)
if len(s) > 3:
	print(-1)
elif len(s) == 3:
	if s[2] - s[1] == s[1] - s[0]:
		print(s[2] - s[1])
	else:
		print(-1)
elif len(s) == 2:
	if (s[1] - s[0]) % 2 == 0:
		print((s[1] - s[0]) // 2)
	else:
		print(s[1] - s[0])
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
st = set(arr)
arr = list(st)
dif = []
if len(arr) == 1:
	dif.append(0)
arr.sort()
for x in range(len(arr) - 1):
	dif.append(arr[x + 1] - arr[x])
dif = list(set(dif))
if len(dif) != 1 or len(arr) > 3:
	print(-1)
elif len(arr) == 3:
	print(dif[0])
elif dif[0] % 2 == 0:
	print(dif[0] // 2)
else:
	print(dif[0])


n = int(input())
l = [int(x) for x in input().split()]
s = sorted(set(l))
if len(s) == 1:
	print(0)
elif len(s) == 2:
	a = abs(s[0] - s[1])
	min = 1000
	if a % 2 == 0:
		min = int(a / 2)
		print(min)
	elif min > a:
		print(a)
elif len(s) == 3 and s[1] - s[0] == s[2] - s[1]:
	print(s[2] - s[1])
else:
	print(-1)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
mn = a[0]
mx = a[-1]
c = Counter(a)
med = -1
for i in c:
	if mn < i < mx:
		med = i
if len(c) > 3:
	print(-1)
elif len(c) == 3:
	if med - mn == mx - med:
		print(med - mn)
	else:
		print(-1)
elif len(c) == 2:
	print((mx - mn) // 2 if (mx - mn) % 2 == 0 else mx - mn)
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
maxm = max(a)
minm = min(a)
mid = (maxm + minm) // 2
if (maxm + minm) % 2 == 1:
	mid = minm
allow = maxm - mid
flag = 1
for x in a:
	diff = abs(mid - x)
	if diff != allow and diff != 0:
		flag = 0
		break
if flag:
	print(allow)
else:
	print(-1)


n = int(input())
L = [int(i) for i in input().split()]
F = []
mi = 101
ma = 0
for i in L:
	if i not in F:
		F.append(i)
if len(F) > 3:
	print(-1)
else:
	F.sort()
	if len(F) == 3:
		D = F[1] - F[0]
		if F[2] - F[1] == D:
			print(D)
		else:
			print(-1)
	elif len(F) == 2:
		D = F[1] - F[0]
		if D % 2:
			print(D)
		else:
			print(D // 2)
	else:
		print(0)


input()
m = map(int, input().split())
a = sorted(frozenset(m))
if len(a) == 1:
	print(0)
elif len(a) == 2:
	t = a[1] - a[0]
	if t % 2 == 0:
		print(t >> 1)
	else:
		print(t)
elif len(a) == 3:
	if a[2] - a[1] == a[1] - a[0]:
		print(a[1] - a[0])
	else:
		print(-1)
else:
	print(-1)


a = int(input())
l = list(map(int, input().split()))
ma = max(l)
mi = min(l)
f = ma - mi
s = (ma - mi) // 2
c = 0
d = 0
ans2 = -1
ans1 = -1
for x in l:
	if x + f == mi + f:
		c = c + 1
	elif x - f == mi + f:
		c = c + 1
	elif x == mi + f:
		c = c + 1
if c == a:
	ans1 = f
else:
	ans1 = -1
if (ma - mi) % 2 == 0:
	for x in l:
		if x + s == mi + s:
			d = d + 1
		elif x - s == mi + s:
			d = d + 1
		elif x == mi + s:
			d = d + 1
else:
	ans2 = -2
if d == a and ans2 != -2:
	ans2 = s
if ans1 >= 0 and ans2 >= 0:
	print(min(ans1, ans2))
elif ans1 >= 0 and ans2 < 0:
	print(ans1)
elif ans1 < 0 and ans2 >= 0:
	print(ans2)
else:
	print(-1)


from sys import stdin
input = stdin.readline

def check(_input, value, k):
	for i in _input:
		if i < value:
			if i + k != value:
				return False
		elif i > value:
			if i - k != value:
				return False
	return True
T = 1
for t in range(1, T + 1):
	n = int(input())
	_input = list(map(int, input().split()))
	min_value = min(_input)
	for i in range(0, 100):
		if check(_input, i + min_value, i):
			print(i)
			exit(0)
	print(-1)


n = int(input())
a = list(map(int, input().split()))
s = set(a)
(mn, mx) = (min(a), max(a))
if len(s) == 1:
	print(0)
elif len(s) == 2:
	d = 1
	while mn + d < mx - d:
		d += 1
	if mn + d == mx - d:
		print(d)
	else:
		print(mx - mn)
elif len(s) == 3:
	poss = True
	if mn % 2 == 0 and mx % 2 == 1 or (mn % 2 == 1 and mx % 2 == 0):
		print(-1)
		exit(0)
	ans = (mn + mx) // 2
	for x in a:
		if x != mn and x != mx and (x != ans):
			poss = False
			break
	if poss:
		print(ans - mn)
	else:
		print(-1)
else:
	print(-1)


input()
b = sorted(set(map(int, input().split())))
z = set()
k = len(b)
if k > 3:
	print(-1)
elif k == 1:
	print(0)
elif k == 2:
	if b[0] % 2 == b[1] % 2:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
else:
	p = set()
	p.add(b[1] - b[0])
	p.add(b[2] - b[1])
	if len(p) == 1:
		print(*p)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
a = set(a)
res = -1
if len(a) == 3:
	a = list(a)
	a.sort()
	if a[1] - a[0] == a[2] - a[1]:
		res = abs(a[1] - a[0])
elif len(a) == 2:
	a = list(a)
	(x, y) = a
	res = abs(x - y)
	if not res & 1:
		res //= 2
elif len(a) == 1:
	res = 0
print(res)


n = int(input())
a = input().split()
a = [int(i) for i in a]
a = set(a)
l = []
for i in a:
	l.append(i)
if len(l) > 3:
	print(-1)
else:
	l.sort()
	if len(l) == 3:
		if l[0] + l[2] == 2 * l[1]:
			print(l[2] - l[1])
		else:
			print(-1)
	elif len(l) == 2:
		if l[1] - l[0] == 2 * int((l[1] - l[0]) / 2):
			print(int((l[1] - l[0]) / 2))
		else:
			print(l[1] - l[0])
	else:
		print(0)


n = int(input().strip())
numbers = [int(i) for i in input().strip().split()]
D = -1
numbers.sort()
has = False
no_answer = False
minus = 0
for j in range(1, n):
	if numbers[j] - numbers[j - 1] != 0:
		if not has:
			has = True
			minus = numbers[j] - numbers[j - 1]
			check_range = max(numbers[j], numbers[j - 1])
		elif numbers[j] != check_range and numbers[j] - minus != check_range and (numbers[j] + minus != check_range):
			no_answer = True
			break
if not no_answer:
	ans = 0
	if (numbers[-1] - numbers[0]) % 2 != 0:
		ans = numbers[-1] - numbers[0]
	else:
		ans = (numbers[-1] - numbers[0]) // 2
	print(ans if numbers[0] != numbers[-1] else 0)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
l = []
a.sort()
b = set(a)
b = list(b)
if n == 1 or len(b) == 1:
	print('0')
elif len(set(a)) == 2:
	if sum(b) % 2 == 0:
		print(abs(sum(b) // 2 - max(b)))
	else:
		print(max(b) - min(b))
elif len(b) > 3:
	print('-1')
else:
	c = b[1] - b[0]
	d = b[0] + c
	e = b[2] - c
	if d == e:
		print(c)
	else:
		print('-1')


import sys

def unique(lst):
	return dict(((o, o) for o in lst)).values()

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		x = sorted(unique([self.next_int() for _ in range(0, n)]))
		if len(x) == 1:
			print(0)
		elif len(x) == 2:
			print(x[1] - x[0] if (x[1] - x[0]) % 2 == 1 else (x[1] - x[0]) // 2)
		elif len(x) == 3 and x[2] - x[1] == x[1] - x[0]:
			print(x[2] - x[1])
		else:
			print(-1)
Main().solve()


t = int(input())
lst = list(map(int, input().split()))
b = sorted(set(lst))
b_len = len(set(lst))
if b_len > 3:
	print(-1)
elif b_len == 3:
	if b[1] - b[0] == b[2] - b[1]:
		print(b[1] - b[0])
	else:
		print(-1)
elif b_len == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
elif b_len == 1:
	print(0)


length = input()
integers = list(map(float, input().split(' ')))
minimum = min(integers)
maximum = max(integers)
spread = maximum - minimum
expected_middle = minimum + spread / 2
result = '?'
middle = '?'
for i in integers:
	if i == expected_middle:
		middle = 'yes'
	if i != minimum and i != maximum and (i != expected_middle):
		result = '-1'
if result == '-1':
	print(result)
elif middle == '?':
	if spread % 2 == 0:
		print(int(spread / 2))
	else:
		print(int(spread))
elif middle == 'yes':
	print(int(spread / 2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
mx = a[-1]
f = 0
if a[0] == a[-1]:
	print(0)
	exit()
for d in range(mx + 1):
	b = []
	if a[0] == a[-1] or a[0] == a[-1] - d:
		b.append(a[0])
	if a[0] + d == a[-1]:
		b.append(a[1])
	if a[0] + d == a[-1] - d:
		b.append(a[0] + d)
	for j in b:
		z = 1
		for x in range(1, n - 1):
			if not (a[x] == j or a[x] + d == j or a[x] - d == j):
				z = 0
				break
		if z:
			f = 1
		break
	if f:
		print(d)
		exit()
print(-1)


for _ in range(1):
	n = int(input())
	lst = list(map(int, input().split()))
	st = list(set(lst))
	st = sorted(st)
	l = len(st)
	if l == 1:
		print(0)
	elif l == 2:
		diff = st[1] - st[0]
		if diff % 2 == 0:
			print(diff // 2)
		else:
			print(diff)
	elif l == 3:
		diff1 = st[1] - st[0]
		diff2 = st[2] - st[1]
		if diff1 == diff2:
			print(diff1)
		else:
			print(-1)
	else:
		print(-1)


import sys

def main():
	n = int(input())
	nums = list(map(int, input().split()))
	(mn, mx) = (min(nums), max(nums))
	s = set(nums)
	types = len(s)
	if (mx + mn) % 2 == 0:
		if types <= 2:
			print((mx - mn) // 2)
		else:
			print((mx - mn) // 2 if all((num == mn + (mx - mn) // 2 for num in s if num != mx and num != mn)) else -1)
	elif types <= 2:
		print(mx - mn)
	else:
		print(-1)
main()


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt, ceil
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def ds(d):
	for i in range(2, d + 1):
		if d % i == 0:
			return i

def main():
	n = inp()
	v = inlt()
	d = sorted(set(v))
	if len(d) == 1:
		print(0)
	elif len(d) == 2:
		diff = d[1] - d[0]
		print(diff if diff % 2 != 0 else diff // 2)
	elif len(d) == 3:
		diff = d[2] - d[0]
		if diff % 2 == 0 and d[0] + diff // 2 == d[1]:
			print(diff // 2)
		else:
			print(-1)
	else:
		print(-1)
main()


m = input()
data = set(map(int, input().split()))
num = sorted(data)
if len(num) > 2:
	big = num[-1]
	small = num[0]
	diff = (big - small) // 2
	com = small + diff
	if big - diff != com:
		print(-1)
	else:
		testing = set()
		testing.add(com)
		for i in num:
			if i < com:
				testing.add(i + diff)
			elif i == com:
				testing.add(i)
			else:
				testing.add(i - diff)
		if len(testing) == 1:
			print(diff)
		else:
			print(-1)
elif len(num) == 1:
	print(0)
else:
	lol1 = num[-1] - num[0]
	lol23 = (num[-1] - num[0]) // 2
	if num[0] + lol23 == num[-1] - lol23:
		print(lol23)
	else:
		print(lol1)


n = int(input())
l = list(map(int, input().split()))
la = sorted(list(set(l)))
k = set()
for i in range(len(la) - 1):
	d = la[i + 1] - la[i]
	k.add(d)
if len(k) == 0:
	k.add(0)
	d = 0
if len(k) == 1 and len(la) <= 3:
	if len(la) == 2:
		z = (la[0] + la[1]) // 2
		if z - la[0] == la[1] - z:
			print(z - la[0])
		else:
			print(d)
	else:
		print(abs(d))
else:
	print(-1)


import os
import sys

def log(*args, **kwargs):
	if os.environ.get('CODEFR'):
		print(*args, **kwargs)
n = int(input())
a = sorted(list(set(list(map(int, input().split())))))
if len(a) == 1:
	print(0)
	sys.exit(0)
if len(a) == 2:
	result = abs(a[0] - a[1]) / 2
	if result != int(result):
		print(a[1] - a[0])
	else:
		print(int(result))
	sys.exit(0)
if len(a) == 3:
	if a[2] - a[1] == a[1] - a[0]:
		print(abs(a[0] - a[1]))
	else:
		print(-1)
	sys.exit(0)
if len(a) > 3:
	print(-1)
	sys.exit(0)


gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
l = gi()

def g(v, x):
	for k in range(1, n):
		if l[k] > v and l[k] - x != v:
			return False
		elif l[k] < v and l[k] + x != v:
			return False
	return True

def f(x):
	return g(x + l[0], x) or g(l[0] - x, x) or g(l[0], x)
for k in range(500):
	if f(k):
		print(k)
		exit()
print(-1)


def read_ints():
	return list(map(int, input().split()))
n = int(input())
a = read_ints()
if n == 1:
	print(0)
else:
	used = list()
	for x in a:
		if x not in used:
			used.append(x)
	l = len(used)
	d = max(used) - min(used)
	if l == 1:
		print(0)
	elif l == 2:
		if d % 2 == 0:
			print(int(d / 2))
		else:
			print(d)
	elif l == 3:
		if d % 2 != 0:
			print(-1)
		else:
			d = int(d / 2)
			proba = min(a) + d
			if proba in used:
				print(d)
			else:
				print(-1)
	else:
		print(-1)


n = int(input())
A = list(map(int, input().split()))
if len(set(A)) > 3:
	print(-1)
else:
	mx = max(A)
	mn = min(A)
	md = mn
	for a in set(A):
		if a != mx and a != mn:
			md = a
			break
	if md != mn:
		if md == (mx + mn) / 2:
			print(md - mn)
		else:
			print(-1)
	elif (mn + mx) % 2 == 0:
		md = (mn + mx) // 2
		print(md - mn)
	else:
		print(mx - mn)


N = int(input())
arr = list(map(int, input().split()))
(a, b) = (max(arr), min(arr))
if (a - b) % 2 == 0:
	D = (a - b) // 2
	q = [a, b, a - D]
else:
	D = a - b
	q = [a, b]
for i in arr:
	if i not in q:
		D = -1
		break
print(D)


t = int(input())
l = list(map(int, input().split()))
l.sort()
r = list(dict.fromkeys(l))
if len(r) > 3:
	print('-1')
elif len(r) == 1:
	print(0)
elif len(r) == 2:
	if (r[1] - r[0]) % 2 == 0:
		print((r[1] - r[0]) // 2)
	else:
		print(r[1] - r[0])
elif r[1] - r[0] != r[2] - r[1]:
	print('-1')
else:
	print(r[1] - r[0])


n = int(input())
arr = list(map(int, input().split()))
ans = -1
lis = []
for i in range(1, 101):
	diff = -1
	c = 0
	for j in range(n):
		if diff == -1 and arr[j] != i:
			diff = abs(arr[j] - i)
			continue
		if arr[j] != i:
			if abs(arr[j] - i) == diff:
				continue
			else:
				c = 1
				break
	if c == 0:
		lis.append(diff)
if min(arr) == max(arr):
	print(0)
elif len(lis) == 0:
	print(-1)
else:
	print(min(lis))


n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
	if (a[i] in b) == False:
		b.append(a[i])
b.sort()
if len(b) > 3 or (len(b) == 3 and b[1] - b[0] != b[2] - b[1]):
	print(-1)
elif len(b) == 3:
	print(b[1] - b[0])
elif len(b) == 2 and (b[0] + b[1]) % 2 == 0:
	print((b[0] + b[1]) // 2 - b[0])
elif len(b) == 2:
	print(b[1] - b[0])
else:
	print(0)


import math
n = input()
A = list(map(int, input().split()))
A = set(A)
A = list(A)
A.sort()
n = len(A)
if n == 3 and A[1] - A[0] == A[2] - A[1]:
	print(A[1] - A[0])
elif n == 2:
	a = A[1] - A[0]
	if (A[1] - A[0]) % 2 == 0 and a > (A[1] - A[0]) / 2:
		a = int((A[1] - A[0]) / 2)
	print(a)
elif n == 1:
	print(0)
else:
	print(-1)


from sys import stdin
from collections import Counter
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
d = dict(Counter(a))
if len(d) > 3:
	print(-1)
else:
	val = sorted(d.keys())
	if len(val) == 1:
		print(0)
	elif len(val) == 2:
		diff = val[1] - val[0]
		if diff % 2 == 0:
			print(diff // 2)
		else:
			print(diff)
	else:
		diff1 = val[1] - val[0]
		diff2 = val[2] - val[1]
		if diff1 != diff2:
			print(-1)
		else:
			print(diff1)


a = int(input())
c = [int(uhgo) for uhgo in input().split()]
c = sorted(c)
d = []
d.append(c[0])
for i in range(1, a):
	if c[i] != c[i - 1]:
		d.append(c[i])
if len(d) > 3:
	print(-1)
elif len(d) == 2:
	if (d[1] - d[0]) % 2 == 0:
		print((d[1] - d[0]) // 2)
	else:
		print(d[1] - d[0])
elif len(d) == 1:
	print(0)
elif d[2] - d[1] != d[1] - d[0]:
	print(-1)
else:
	print(d[2] - d[1])


n = int(input())
cl = sorted(list(map(int, input().split())))
i = 0
while i < n - 1 and cl[i] == cl[i + 1]:
	i += 1
if n == 1 or i == n - 1:
	print(0)
else:
	d1 = abs(cl[i] - cl[i + 1])
	d2 = d1 // 2
	d3 = d1 * 2
	st1 = True
	st2 = True
	st3 = True
	x1 = min(cl[i], cl[i + 1]) + d1
	x2 = min(cl[i], cl[i + 1]) + d2
	x3 = min(cl[i], cl[i + 1]) + d3
	for i in range(n):
		if abs(cl[i] - x1) != d1 and cl[i] != x1:
			st1 = False
		if abs(cl[i] - x2) != d2 and cl[i] != x2:
			st2 = False
		if abs(cl[i] - x3) != d3 and cl[i] != x3:
			st3 = False
	if not st1:
		d1 = 10000
	if not st2:
		d2 = 10000
	if not st3:
		d3 = 10000
	mn = min(d1, d2, d3)
	if mn == 10000:
		print(-1)
	else:
		print(mn)


def input_one(f=int):
	return f(input().strip())

def input_row(f=int):
	return list(map(f, input_one(str).split()))
n = input_one()
x = input_row()
x = sorted(set(x))
if len(x) == 3:
	(a, b, c) = x
	if b - a == c - b:
		print(b - a)
	else:
		print(-1)
elif len(x) == 2:
	(a, b) = x
	if (b - a) % 2 == 0:
		print((b - a) // 2)
	else:
		print(b - a)
elif len(x) == 1:
	print(0)
else:
	print(-1)


N = int(input())
sk = [int(x) for x in input().split()]
kiek = set(sk)
if len(kiek) == 1:
	print(0)
	exit()
nauj = list(kiek)
if len(kiek) == 2:
	diff = abs(nauj[0] - nauj[-1])
	print(diff // 2 if diff % 2 == 0 else diff)
	exit()
if len(kiek) == 3:
	nauj.sort()
	if nauj[1] - nauj[0] == nauj[-1] - nauj[1]:
		print(nauj[1] - nauj[0])
		exit()
print(-1)


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return map(int, input().split())

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	n = int(input())
	ls = [int(i) for i in input().split()]
	for d in range(0, 128):
		flag = True
		for i in range(1, n):
			if ls[i] in [ls[0], ls[0] + d, ls[0] - d]:
				continue
			else:
				flag = False
				break
		if flag:
			print(d)
			return 0
		flag = True
		for i in range(1, n):
			if ls[i] in [ls[0] + d, ls[0] + 2 * d, ls[0]]:
				continue
			else:
				flag = False
				break
		if flag:
			print(d)
			return 0
		flag = True
		for i in range(1, n):
			if ls[i] in [ls[0] - d, ls[0] - 2 * d, ls[0]]:
				continue
			else:
				flag = False
				break
		if flag:
			print(d)
			return 0
	print(-1)
main()


def main(argc, argv) -> {}:
	sync_with_stdio(false)
	cin.tie(0)
	cout.tie(0)
	n = 0
	n <<= cin
	A = vector << int >> n
	A <<= cin
	C = vector << int >> 101
	i = 0
	while i < len(A) or {}:
		C[A[i]] += 1
		i += 1
		{}
	nz = vector << int >> 3
	nzi = 0
	i = 0
	ok = true
	while i < len(C) or {}:
		if C[i] != 0 or {}:
			if nzi == 3 or {}:
				ok = false
				break
				{}
			nz[nzi] = i
			nzi += 1
			{}
		i += 1
		{}
	if not ok or {}:
		cout << -1 << endl
		{}
	elif nzi == 1 or {}:
		cout << 0 << endl
		{}
	elif nzi == 2 or {}:
		diff = nz[1] - nz[0]
		cout << (diff // 2 if diff % 2 == 0 else diff) << endl
		{}
	elif nz[1] - nz[0] == nz[2] - nz[1] or {}:
		cout << nz[1] - nz[0] << endl
		{}
	else:
		cout << -1 << endl
		{}
		{}
import base64
exec(base64.decodebytes('cHkyID0gcm91bmQoMC41KQoKaWYgcHkyOgogICAgZnJvbSBmdXR1cmVfYnVpbHRpbnMgaW1wb3J0IGFzY2lpLCBmaWx0ZXIsIGhleCwgbWFwLCBvY3QsIHppcAogICAgcmFuZ2UgPSB4cmFuZ2UKCmRlZiBzeW5jX3dpdGhfc3RkaW8oYik6CiAgICBpZiBiOiByZXR1cm4KICAgIGltcG9ydCBvcywgc3lzCiAgICBmcm9tIGlvIGltcG9ydCBCeXRlc0lPLCBJT0Jhc2UKICAgIAogICAgIyBGYXN0SU8gZm9yIFB5UHkyIGFuZCBQeVB5MyAod29ya3Mgd2l0aCBpbnRlcmFjdGl2ZSkgYnkgUGFqZW5lZ29kCiAgICBjbGFzcyBGYXN0SShvYmplY3QpOgogICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCBmZD0wLCBidWZmZXJzaXplPTIqKjE0KToKICAgICAgICAgICAgc2VsZi5zdHJlYW0gPSBzdHJlYW0gPSBCeXRlc0lPKCk7IHNlbGYuYnVmZW5kbCA9IDAKICAgICAgICAgICAgZGVmIHJlYWQyYnVmZmVyKCk6CiAgICAgICAgICAgICAgICBzID0gb3MucmVhZChmZCwgYnVmZmVyc2l6ZSArIG9zLmZzdGF0KGZkKS5zdF9zaXplKTsgcG9zID0gc3RyZWFtLnRlbGwoKQogICAgICAgICAgICAgICAgc3RyZWFtLnNlZWsoMCwyKTsgc3RyZWFtLndyaXRlKHMpOyBzdHJlYW0uc2Vlayhwb3MpOyByZXR1cm4gcwogICAgICAgICAgICBzZWxmLnJlYWQyYnVmZmVyID0gcmVhZDJidWZmZXIKICAgICAgICAjIFJlYWQgZW50aXJlIGlucHV0CiAgICAgICAgZGVmIHJlYWQoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYucmVhZDJidWZmZXIoKTogcGFzcwogICAgICAgICAgICByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZCgpIGlmIHNlbGYuc3RyZWFtLnRlbGwoKSBlbHNlIHNlbGYuc3RyZWFtLmdldHZhbHVlKCkKICAgICAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYuYnVmZW5kbCA9PSAwOiBzID0gc2VsZi5yZWFkMmJ1ZmZlcigpOyBzZWxmLmJ1ZmVuZGwgKz0gcy5jb3VudChiIlxuIikgKyAobm90IHMpCiAgICAgICAgICAgIHNlbGYuYnVmZW5kbCAtPSAxOyByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZGxpbmUoKQogICAgICAgIGRlZiBpbnB1dChzZWxmKTogcmV0dXJuIHNlbGYucmVhZGxpbmUoKS5yc3RyaXAoYidcclxuJykKICAgICAgICAKICAgICAgICAjIFJlYWQgYWxsIHJlbWFpbmluZyBpbnRlZ2VycywgdHlwZSBpcyBnaXZlbiBieSBvcHRpb25hbCBhcmd1bWVudAogICAgICAgIGRlZiByZWFkbnVtYmVycyhzZWxmLCB6ZXJvPTApOgogICAgICAgICAgICBjb252ID0gb3JkIGlmIHB5MiBlbHNlIGxhbWJkYSB4OngKICAgICAgICAgICAgQSA9IFtdOyBudW1iID0gemVybzsgc2lnbiA9IDE7IGMgPSBiIi0iWzBdCiAgICAgICAgICAgIGZvciBjIGluIHNlbGYucmVhZCgpOgogICAgICAgICAgICAgICAgaWYgYyA+PSBiIjAiWzBdOiBudW1iID0gMTAgKiBudW1iICsgY29udihjKSAtIDQ4CiAgICAgICAgICAgICAgICBlbGlmIGMgPT0gYiItIlswXTogc2lnbiA9IC0xCiAgICAgICAgICAgICAgICBlbGlmIGMgIT0gYiJcciJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYik7IG51bWIgPSB6ZXJvOyBzaWduID0gMQogICAgICAgICAgICBpZiBjID49IGIiMCJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYikKICAgICAgICAgICAgcmV0dXJuIEEKICAgIAogICAgY2xhc3MgRmFzdE8oSU9CYXNlKToKICAgICAgICBkZWYgX19pbml0X18oc2VsZiwgZmQ9MSk6CiAgICAgICAgICAgIHN0cmVhbSA9IEJ5dGVzSU8oKQogICAgICAgICAgICBzZWxmLmZsdXNoID0gbGFtYmRhOiBvcy53cml0ZSgxLCBzdHJlYW0uZ2V0dmFsdWUoKSkgYW5kIG5vdCBzdHJlYW0udHJ1bmNhdGUoMCkgYW5kIHN0cmVhbS5zZWVrKDApCiAgICAgICAgICAgIHNlbGYud3JpdGUgPSBzdHJlYW0ud3JpdGUgaWYgcHkyIGVsc2UgbGFtYmRhIHM6IHN0cmVhbS53cml0ZShzLmVuY29kZSgpKQogICAgCiAgICBzeXMuc3RkaW4sIHN5cy5zdGRvdXQgPSBGYXN0SSgpLCBGYXN0TygpCiAgICBnbG9iYWwgaW5wdXQKICAgIGlucHV0ID0gc3lzLnN0ZGluLmlucHV0CgoKaW1wb3J0IHN5cwoKY2xhc3Mgb3N0cmVhbToKICAgIGRlZiBfX2xzaGlmdF9fKHNlbGYsYSk6CiAgICAgICAgaWYgYSA9PSBlbmRsOgogICAgICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIpCiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoc3RyKGEpKQogICAgICAgIHJldHVybiBzZWxmCiAgICBkZWYgdGllKHNlbGYsIHZhbCk6cGFzcwpjb3V0ID0gb3N0cmVhbSgpCmVuZGwgPSBvYmplY3QoKQoKY2xhc3MgaXN0cmVhbToKICAgIHRpZWR0byA9IGNvdXQKICAgIGlucCA9IE5vbmUKICAgIGRlZiBfX3Jsc2hpZnRfXyhhLGIpOgogICAgICAgIGlmIGEudGllZHRvID09IGNvdXQ6CiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGlmIHR5cGUoYik9PXR1cGxlIG9yIHR5cGUoYik9PWxpc3Q6CiAgICAgICAgICAgIHJldHVybiB0eXBlKGIpKHR5cGUoYykoYS5nZXQoKSkgZm9yIGMgaW4gYikKICAgICAgICByZXR1cm4gdHlwZShiKShhLmdldCgpKQogICAgZGVmIHRpZShzZWxmLCB2YWwpOgogICAgICAgIHNlbGYudGllZHRvID0gdmFsCiAgICBkZWYgZ2V0KGEpOgogICAgICAgIHdoaWxlIG5vdCBhLmlucDoKICAgICAgICAgICAgYS5pbnAgPSBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpWzo6LTFdCiAgICAgICAgcmV0dXJuIGEuaW5wLnBvcCgpCmNpbiA9IGlzdHJlYW0oKQoKY2xhc3MgVmVjdG9yOgogICAgZGVmIF9fbHNoaWZ0X18oc2VsZiwgb3RoZXIpOgogICAgICAgIHNlbGYudHlwZSA9IG90aGVyCiAgICAgICAgcmV0dXJuIHNlbGYKICAgIGRlZiBfX3JzaGlmdF9fKHNlbGYsIG90aGVyKToKICAgICAgICBpZiB0eXBlKG90aGVyKSA9PSB0dXBsZToKICAgICAgICAgICAgcmV0dXJuIFtzZWxmLnR5cGUob3RoZXJbMV0pXSpvdGhlclswXQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBbc2VsZi50eXBlKCldKm90aGVyCnZlY3RvciA9IFZlY3RvcigpCg=='.encode()))
true = True
false = False
main(len(sys.argv), sys.argv)


def B():
	n = input()
	s = set()
	arr = input().split()
	for num in arr:
		s.add(int(num))
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		x1 = s.pop()
		x2 = s.pop()
		if (x1 + x2) % 2 == 1:
			print(abs(x1 - x2))
		else:
			print(abs(x1 - x2) // 2)
	elif len(s) == 3:
		x1 = s.pop()
		x2 = s.pop()
		x3 = s.pop()
		tmp_x1 = max(x1, x2, x3)
		tmp_x3 = min(x1, x2, x3)
		x2 = (set([x1, x2, x3]) ^ set([tmp_x1, tmp_x3])).pop()
		x1 = tmp_x1
		x3 = tmp_x3
		if x1 - x2 == x2 - x3:
			print(x1 - x2)
		else:
			print(-1)
	else:
		print(-1)
B()


import sys
line = sys.stdin.readline().strip('\n')
line = sys.stdin.readline().strip('\n')
num = list(set(map(int, line.split())))
num.sort()
if len(num) == 1:
	print(0)
elif len(num) == 2:
	if (num[1] - num[0]) % 2 == 0:
		print((num[1] - num[0]) // 2)
	else:
		print(num[1] - num[0])
elif len(num) == 3:
	if num[2] + num[0] == 2 * num[1]:
		print(num[1] - num[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
t = list(map(int, input().split()))
t.sort()
m = max(t)
if n == 1 or len(set(t)) == 1:
	print(0)
	exit()
for target in range(m + 1):
	bool = True
	needed = abs(t[0] - target)
	for j in range(1, n):
		if target == t[j] or needed == abs(t[j] - target):
			continue
		else:
			bool = False
			break
	if bool:
		print(needed)
		exit()
print(-1)


def solve(n, arr):
	s = set(arr)
	s = list(s)
	s.sort()
	if len(s) == 1:
		return 0
	elif len(s) == 2:
		if (s[1] - s[0]) % 2 != 0:
			return s[1] - s[0]
		else:
			return (s[1] - s[0]) // 2
	elif len(s) == 3:
		if s[2] - s[1] != s[1] - s[0]:
			return -1
		else:
			return s[1] - s[0]
	return -1
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr))


import itertools

def solve():
	input()
	n = {int(i) for i in str.split(input())}
	so = sorted(list(n))
	if len(n) == 1:
		return 0
	if len(n) == 2:
		if (so[1] + so[0]) % 2 == 0:
			return so[1] - (so[1] + so[0]) // 2
		else:
			return so[1] - so[0]
	if len(n) == 3 and so[2] - so[1] == so[1] - so[0]:
		return so[1] - so[0]
	return -1
print(solve())


n = int(input().strip())
a = list(map(int, input().split()))
l = len(set(a))
if l > 3:
	print(-1)
elif l == 1:
	print(0)
elif l == 2:
	b = list(set(a))
	b.sort()
	diff = b[1] - b[0]
	if diff % 2 == 0:
		print(diff // 2)
	else:
		print(diff)
else:
	b = list(set(a))
	b.sort()
	diff = []
	for i in range(len(b) - 1):
		diff.append(b[i + 1] - b[i])
	if len(set(diff)) == 1:
		print(diff[0])
	else:
		print(-1)


n = int(input())
nums = list(map(int, input().split()))
new = []
for i in range(len(nums)):
	if nums[i] not in new:
		new.append(nums[i])
new.sort()
if len(new) > 3:
	print('-1')
elif len(new) == 3:
	if new[1] - new[0] == new[2] - new[1]:
		print(new[1] - new[0])
	else:
		print('-1')
elif len(new) == 2:
	if (new[1] - new[0]) % 2 == 0:
		print((new[1] - new[0]) // 2)
	else:
		print(new[1] - new[0])
elif len(new) == 1:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
a = list(set(arr))
a.sort()
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[0] + a[1]) % 2 == 0:
		print(int(abs((a[0] + a[1]) / 2 - a[0])))
	else:
		print(abs(a[1] - a[0]))
elif len(a) == 3:
	if a[1] - a[0] == a[2] - a[1]:
		print(a[2] - a[1])
	else:
		print(-1)
else:
	print(-1)


import math
x = int(input())
y = input().split(' ')
big_no = -math.inf
small_no = math.inf
mid_no = 0
for i in y:
	if int(i) > big_no:
		big_no = int(i)
	if int(i) < small_no:
		small_no = int(i)
if len(set(y)) > 2:
	for i in y:
		if big_no != int(i) and small_no != int(i):
			mid_no = int(i)
			break
if len(set(y)) == 1:
	print(0)
elif len(set(y)) == 2:
	if (big_no + small_no) % 2 == 0:
		print(int((big_no + small_no) / 2 - small_no))
	else:
		print(big_no - small_no)
elif mid_no - small_no != big_no - mid_no or len(set(y)) > 3:
	print(-1)
else:
	print(mid_no - small_no)


import re, math, decimal, bisect

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

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
n = iread()
nums = sorted(viread())
for i in range(len(nums)):
	nums[i] = nums[-1] - nums[i]
nums = set(nums) - {0}
if len(nums) == 0:
	print(0)
elif len(nums) == 1:
	if min(nums) % 2 == 0:
		print(min(nums) // 2)
	else:
		print(min(nums))
elif len(nums) == 2:
	if min(nums) * 2 == max(nums):
		print(min(nums))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
lis = [int(x) for x in input().split()]
s = set(lis)
li = list(s)
li.sort()
if len(li) > 3:
	print('-1')
elif len(li) == 3:
	if li[1] - li[0] == li[2] - li[1]:
		print(li[1] - li[0])
	else:
		print(-1)
elif len(li) == 2:
	if (li[1] - li[0]) % 2 == 0:
		print((li[1] - li[0]) // 2)
	else:
		print(li[1] - li[0])
else:
	print(0)


def main():
	n = int(input())
	ints = list(map(int, input().split()))
	ints = sorted(list(set(ints)))
	if len(ints) > 3:
		print(-1)
		return
	if len(ints) == 3:
		if ints[1] - ints[0] == ints[2] - ints[1]:
			print(ints[1] - ints[0])
		else:
			print(-1)
		return
	if len(ints) == 2:
		if (ints[0] + ints[1]) % 2 == 0:
			print((ints[0] + ints[1]) // 2 - ints[0])
		else:
			print(ints[1] - ints[0])
		return
	print(0)
	return
main()


n = int(input())
a = list(map(int, input().split()))
v = sorted(set(a))
if len(v) == 1:
	print(0)
elif len(v) == 2:
	diff = v[1] - v[0]
	if diff % 2 == 0:
		print(diff // 2)
	else:
		print(diff)
elif len(v) == 3:
	(a, b, c) = v
	if b - a == c - b:
		print(b - a)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
amin = min(a)
amax = max(a)
ares_1 = (amin + amax) // 2
D1 = amax - ares_1
ares_2 = max(a)
D2 = amax - amin
for i in range(n):
	if a[i] != ares_1 and abs(a[i] - ares_1) != D1:
		D1 = -1
	if a[i] != ares_2 and abs(a[i] - ares_2) != D2:
		D2 = -1
if D1 > 0:
	print(D1)
else:
	print(D2)


n = int(input())
a = sorted(list(map(int, input().split())))
mx = max(a)
mn = min(a)
if (mx - mn) % 2 == 0:
	d = (mx - mn) // 2
	ans = [mx, mn, mx - d]
else:
	d = mx - mn
	ans = [mx, mn]
for i in a:
	if i not in ans:
		exit(print(-1))
print(d)


import sys
n = int(input())
a = set([int(i) for i in input().split()])
a = sorted(list(a))
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(a[1] - a[0])
elif len(a) == 3 and a[1] - a[0] == a[2] - a[1]:
	print(a[1] - a[0])
else:
	print(-1)


input()
S = list(set(map(int, input().split())))
S.sort()
l = len(S)
if l == 1:
	print(0)
elif l == 2:
	s = S[1] - S[0]
	if s % 2:
		print(S[1] - S[0])
	else:
		print((S[1] - S[0]) // 2)
elif l == 3:
	print(S[1] - S[0] if S[1] - S[0] == S[2] - S[1] else -1)
else:
	print(-1)


N = int(input())
A = list(map(int, input().split()))
A.sort()
newA = [A[0]]
for i in range(1, N):
	if A[i] not in newA:
		newA.append(A[i])
		if len(newA) == 4:
			break
if len(newA) == 1:
	print(0)
elif len(newA) == 2:
	if (newA[1] - newA[0]) % 2 == 0:
		print((newA[1] - newA[0]) // 2)
	else:
		print(newA[1] - newA[0])
elif len(newA) == 3:
	if newA[2] - newA[1] != newA[1] - newA[0]:
		print(-1)
	else:
		print(newA[2] - newA[1])
else:
	print(-1)


import collections

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	c = collections.Counter(A)
	ck = list(c.keys())
	ck.sort()
	ck_len = len(ck)
	if ck_len >= 4:
		return -1
	elif ck_len == 3:
		if ck[2] - ck[1] == ck[1] - ck[0]:
			return ck[2] - ck[1]
		else:
			return -1
	elif ck_len == 2:
		if (ck[1] - ck[0]) % 2 == 0:
			return (ck[1] - ck[0]) // 2
		else:
			return ck[1] - ck[0]
	else:
		return 0
print(solve())


input()
a = set(map(int, input().split()))
if len(a) > 3:
	print(-1)
elif len(a) == 1:
	print(0)
elif len(a) == 2:
	x = max(a)
	y = min(a)
	if (x - y) % 2 == 0:
		print((x - y) // 2)
	else:
		print(x - y)
else:
	max = max(a)
	a.remove(max)
	min = min(a)
	a.remove(min)
	(mean,) = a
	if max - mean == mean - min:
		print(max - mean)
	else:
		print(-1)


n = int(input())
lst = list(map(int, input().split()))
s = list(set(lst))
s.sort()
length = len(s)
if length > 3:
	print(-1)
elif length == 3:
	if s[2] - s[1] == s[1] - s[0]:
		print(s[1] - s[0])
	else:
		print(-1)
elif length == 2:
	x = (s[1] - s[0]) // 2
	if x * 2 == s[1] - s[0]:
		print(x)
	else:
		print(s[1] - s[0])
else:
	print(0)


from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10 ** 6)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
n = iin()
a = lin()
sa = list(set(a))
sa.sort()
l = len(sa)
if l == 1:
	print(0)
	exit()
if l == 2:
	df = abs(sa[0] - sa[1])
	if df % 2 == 0:
		print(df // 2)
	else:
		print(df)
	exit()
if l == 3:
	(d1, d2) = (sa[2] - sa[1], sa[1] - sa[0])
	if d1 != d2:
		print(-1)
		exit()
	print(d1)
	exit()
print(-1)


n = int(input())
a = sorted(set(map(int, input().split())))
if len(a) > 3:
	print('-1')
if len(a) == 2:
	b = [a[i] - a[i - 1] for i in range(1, len(a))]
	if len(set(b)) > 1:
		print('-1')
	elif b[0] % 2:
		print(b[0])
	else:
		print(b[0] // 2)
if len(a) == 3:
	b = [a[i] - a[i - 1] for i in range(1, len(a))]
	if len(set(b)) > 1:
		print('-1')
	else:
		print(b[0])
if len(a) == 1:
	print('0')


input()
data = [int(i) for i in input().split()]
s = set()
for a in data:
	s.add(a)
if len(s) == 1:
	print('0')
elif len(s) == 2:
	d = list(s)
	if (d[0] + d[1]) % 2 == 0:
		print(abs((d[0] - d[1]) // 2))
	else:
		print(abs(d[0] - d[1]))
elif len(s) == 3:
	d = list(s)
	d.sort()
	if d[2] - d[1] == d[1] - d[0]:
		print(d[2] - d[1])
	else:
		print('-1')
else:
	print('-1')


n = int(input())
list1 = list(map(int, input().split()))
list1 = list(set(list1))
list1.sort()
if len(list1) > 3:
	print('-1')
else:
	if len(list1) == 1:
		print('0')
	if len(list1) == 2:
		if (list1[1] - list1[0]) % 2 == 0:
			print(int((list1[1] - list1[0]) / 2))
		else:
			print(list1[1] - list1[0])
	if len(list1) == 3:
		if list1[1] - list1[0] == list1[2] - list1[1]:
			print(list1[1] - list1[0])
		else:
			print('-1')


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		a = li()
		a.sort()
		bf = -1
		for i in range(0, 1001):
			x1 = a[0] + i
			x2 = a[0] - i
			x3 = a[0]
			zp = [0] * n
			for ii in range(n):
				zp[ii] = a[ii]
			for ii in range(n):
				if zp[ii] == x1:
					continue
				if zp[ii] > x1:
					zp[ii] -= i
					continue
				if zp[ii] <= x1:
					zp[ii] += i
					continue
			fl = True
			for ii in range(n):
				if zp[ii] != zp[0]:
					fl = False
					break
			if fl:
				bf = i
				break
			zp = [0] * n
			for ii in range(n):
				zp[ii] = a[ii]
			for ii in range(n):
				if zp[ii] == x2:
					continue
				if zp[ii] > x2:
					zp[ii] -= i
					continue
				if zp[ii] <= x2:
					zp[ii] += i
					continue
			fl = True
			for ii in range(n):
				if zp[ii] != zp[0]:
					fl = False
					break
			if fl:
				bf = i
				break
			zp = [0] * n
			for ii in range(n):
				zp[ii] = a[ii]
			for ii in range(n):
				if zp[ii] == x3:
					continue
				if zp[ii] > x3:
					zp[ii] -= i
					continue
				if zp[ii] <= x3:
					zp[ii] += i
					continue
			fl = True
			for ii in range(n):
				if zp[ii] != zp[0]:
					fl = False
					break
			if fl:
				bf = i
				break
		print(bf)
solve()


n = int(input())
a = [int(a) for a in input().split()]
a.sort()
s = set()
min1 = -9999
for i in a:
	s.add(i)
	if i > min1:
		min2 = min1
		min1 = i
if len(s) == 2:
	if (max(a) - min(a)) % 2 == 0:
		print(int((max(a) - min(a)) / 2))
	else:
		print(max(a) - min(a))
elif len(s) == 3:
	if min2 - min(a) == max(a) - min2:
		print(min2 - min(a))
	else:
		print(-1)
elif len(s) == 1:
	print(0)
else:
	print(-1)


n = input()
input = input()
a = list(map(int, input.strip().split()))
num = dict()
for i in a:
	num[i] = 1
L = len(num)
now = sorted(num)
ans = True
if L > 3:
	ans = False
elif L == 3:
	if now[1] - now[0] == now[2] - now[1]:
		D = now[1] - now[0]
	else:
		ans = False
elif L == 2:
	D = now[1] - now[0]
	if D / 2 == D // 2:
		D /= 2
else:
	D = 0
if ans:
	print(int(D))
else:
	print(-1)


k = {}
n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
	if a[i] not in k:
		k[a[i]] = 1
a.sort()
l = list(k.keys())
l.sort()
if len(l) == 3 and 2 * l[1] == l[0] + l[2]:
	print(l[1] - l[0])
elif len(l) == 2 and (l[0] + l[1]) % 2 == 0:
	print((l[1] - l[0]) // 2)
elif len(l) == 2:
	print(l[1] - l[0])
elif len(l) == 1:
	print(0)
else:
	print(-1)


from math import ceil as ce
n = int(input())
x = [int(i) for i in input().split(' ')]
x = list(set(x))
x.sort()
if len(x) > 3:
	print(-1)
elif len(x) == 3:
	if x[2] - x[1] == x[1] - x[0]:
		print(x[1] - x[0])
	else:
		print(-1)
elif len(x) == 2:
	a = x[1] - x[0]
	if a % 2 == 0:
		print(a // 2)
	else:
		print(a)
else:
	print(0)


t = int(input())
l = list((int(i) for i in input().split(' ')))
x = []
for i in l:
	if i not in x:
		x.append(i)
if len(x) > 3:
	print(-1)
else:
	x.sort()
	if len(x) == 1:
		print(0)
	elif len(x) == 2:
		if (x[1] - x[0]) % 2 == 1:
			print(x[1] - x[0])
		else:
			print((x[1] - x[0]) // 2)
	elif x[1] - x[0] == x[2] - x[1]:
		print(x[1] - x[0])
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
dif = []
for i in range(1, n):
	d = a[i] - a[i - 1]
	if d != 0:
		dif.append(d)
if len(dif) == 0:
	print(0)
elif len(dif) > 2:
	print(-1)
else:
	cnt = 0
	for i in range(len(dif) - 1):
		if dif[i] != dif[i + 1]:
			cnt = 1
			break
	if cnt == 1:
		print(-1)
	elif len(dif) > 1:
		print(dif[0])
	elif len(dif) == 1 and dif[0] % 2 == 0 and (dif[0] != 1):
		print(dif[0] // 2)
	else:
		print(dif[0])


n = int(input())
l = [int(x) for x in input().split()]
(a, b) = (max(l), min(l))
if (a - b) % 2 == 0:
	D = (a - b) // 2
	q = [a, b, a - D]
else:
	D = a - b
	q = [a, b]
for _ in l:
	if _ not in q:
		D = -1
		break
print(D)


num = int(input())
lst = list(dict.fromkeys([int(x) for x in str(input()).split(' ')]))
if len(lst) > 3:
	d = -1
elif len(lst) == 3:
	mx = max(lst)
	lst.remove(mx)
	if mx - max(lst) == max(lst) - min(lst):
		d = mx - max(lst)
	else:
		d = -1
elif len(lst) == 2:
	if (max(lst) - min(lst)) % 2 == 0:
		d = int((max(lst) - min(lst)) / 2)
	else:
		d = max(lst) - min(lst)
else:
	d = 0
print(d)


number = int(input())
lst = [int(x) for x in str(input()).split()]
unique = []
for el in lst:
	if el not in unique:
		unique.append(el)
if len(unique) > 3:
	print(-1)
elif len(unique) == 1:
	print(0)
elif len(unique) == 2:
	if (max(unique) - min(unique)) % 2 != 0:
		print(max(unique) - min(unique))
	else:
		print((max(unique) - min(unique)) // 2)
elif len(unique) == 3:
	unique = sorted(unique)
	if unique[2] - unique[1] == unique[1] - unique[0]:
		print(unique[2] - unique[1])
	else:
		print(-1)


import math
n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
d = set(l)
if len(d) == 1:
	print(0)
if len(d) == 2:
	r = sorted(list(set(l)))
	a = r[1] - r[0]
	b = (r[1] - r[0]) / 2
	if math.ceil(b) == math.floor(b):
		if a < b:
			print(a)
		else:
			print(int(b))
	else:
		print(a)
if len(d) > 3:
	print(-1)
if len(d) == 3:
	r = sorted(list(set(l)))
	if r[2] - r[1] == r[1] - r[0]:
		print(r[2] - r[1])
	else:
		print(-1)


n = int(input())
ln = sorted([int(i) for i in input().split(' ')])
ct = [ln[0]]
for i in range(1, len(ln)):
	if ln[i] != ln[i - 1]:
		ct.append(ln[i])
if len(ct) > 3:
	print(-1)
elif len(ct) == 3:
	if ct[2] - ct[1] == ct[1] - ct[0]:
		print(ct[2] - ct[1])
	else:
		print(-1)
elif len(ct) == 2:
	if (ct[1] - ct[0]) % 2 == 0:
		print((ct[1] - ct[0]) // 2)
	else:
		print(ct[1] - ct[0])
else:
	print(0)


import math
n = int(input())
lis = list(map(int, input().split()))
lis = list(set(lis))
lis.sort()
n = len(lis)
if n > 3:
	print(-1)
elif n == 1:
	print(0)
elif n == 2:
	if (lis[1] - lis[0]) % 2 == 0:
		print((lis[1] - lis[0]) // 2)
	else:
		print(lis[1] - lis[0])
elif lis[1] - lis[0] == lis[2] - lis[1]:
	print(lis[1] - lis[0])
else:
	print(-1)


num = input()
data = list(set(list(map(int, input().split()))))
data.sort()
if len(data) > 3:
	print(-1)
elif len(data) == 3:
	if (data[0] + data[-1]) // 2 == data[1] and (data[0] + data[-1]) % 2 == 0:
		print((data[-1] - data[0]) // 2)
	else:
		print(-1)
elif len(data) == 2:
	if (data[0] + data[-1]) % 2 == 0:
		print(abs((data[-1] - data[0]) // 2))
	else:
		print(abs(data[-1] - data[0]))
else:
	print(0)


n = int(input())
lst = [int(x) for x in input().split()]
lst.sort()
last = lst[0]
count = 0
dif = []
for curr in lst:
	if curr != last:
		dif.append(curr - last)
		count += 1
	last = curr
flag = True
if count > 2:
	flag = False
if count == 2:
	if dif[1] != dif[0]:
		flag = False
if flag:
	if count == 2:
		print(dif[0])
	elif count == 1:
		if dif[0] % 2 != 0:
			print(dif[0])
		else:
			print(int(dif[0] / 2))
	else:
		print(0)
else:
	print(int(-1))


n = int(input())
x = list(map(int, input().split()))
mx = max(x)
mn = min(x)
if (mx - mn) % 2 == 0:
	mid = (mx - mn) // 2
	poss = [mx, mn, mx - mid]
else:
	mid = mx - mn
	poss = [mx, mn]
for i in x:
	if i not in poss:
		mid = -1
print(mid)


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, a) = (int(input()), arr_inp(1))
dis = sorted(set(a))
if len(dis) == 1:
	print(0)
elif len(dis) == 2:
	mid = (dis[0] + dis[1]) / 2
	print(int(mid) - dis[0] if mid == int(mid) else dis[1] - dis[0])
elif len(dis) == 3:
	mid = (dis[0] + dis[2]) / 2
	print(int(mid) - dis[0] if mid == dis[1] else -1)
else:
	print(-1)


n = int(input())
a = set(map(int, input().split()))
if len(a) > 3:
	print(-1)
	exit(0)
if len(a) == 2:
	if (max(a) - min(a)) % 2 == 0:
		print((max(a) - min(a)) // 2)
		exit(0)
	else:
		print(max(a) - min(a))
		exit(0)
if len(a) == 1:
	print(0)
	exit(0)
else:
	x = sum(a)
	mi = min(a)
	ma = max(a)
	if x - mi - ma != (ma - mi) / 2 + mi:
		print(-1)
		exit(0)
	else:
		print((ma - mi) // 2)
		exit(0)


n = int(input())
nums = sorted(list(map(int, input().split())))
maxn = nums[-1]
minn = nums[0]
numset = set(nums)
lower = 0
upper = maxn - minn
answer = -1
for D in range(lower, upper + 1):
	rez = []
	for x in numset:
		vals3 = {x - D, x, x + D}
		rez.append(vals3)
	intersection = rez[0].intersection(*rez[1:])
	if len(intersection) > 0:
		answer = D
		break
print(answer)


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

def func(arr):
	n = len(arr)
	if n > 3:
		return -1
	if n == 1:
		return 0
	if n == 2:
		(a, b) = (arr.pop(), arr.pop())
		c = abs(a - b)
		return c // 2 if not c & 1 else c
	arr = list(arr)
	arr.sort()
	(a, b) = (arr[0], arr[2])
	c = abs(a - b) // 2
	return c if (a + b) / 2 == arr[1] else -1
print(func(arr))


n = int(input())
A = list(map(int, input().split()))
if len(set(A)) == 1:
	print(0)
	exit(0)
A.sort()
x = A[-1] - A[0]
heh = x
if x % 2 == 0:
	heh = x // 2
for kek in (heh, x):
	s = set()
	for elem in A:
		if elem > A[0] + kek:
			s.add(elem - kek)
		elif elem < A[0] + kek:
			s.add(elem + kek)
	if len(s) == 1 and A[0] + kek in s:
		print(kek)
		exit(0)
print(-1)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
n = 0
a = []

def test(d, targ):
	if d != floor(d):
		return False
	global a
	d = floor(d)
	for x in a:
		if (targ in [x - d, x, x + d]) == False:
			return False
	return True

def main():
	global n, a
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	a.sort()
	maxD = a[n - 1] - a[0]
	for testD in [0, float(maxD) / 2, maxD]:
		if test(testD, a[0] + testD) == True:
			stdout.write('%d' % testD)
			return 0
	stdout.write('-1')
	return 0
main()


def method(a):
	b = list(set(a))
	b.sort()
	if len(b) > 3:
		return -1
	elif len(b) == 3:
		if b[2] - b[1] != b[1] - b[0]:
			return -1
		else:
			return b[2] - b[1]
	elif len(b) == 1:
		return 0
	elif len(b) == 2:
		m = b[1] - b[0]
		if m % 2 == 0:
			return int(m / 2)
		else:
			return b[1] - b[0]
t = int(input())
a = input().split(' ')
for i in range(t):
	a[i] = int(a[i])
print(method(a))


def main():
	length = int(input())
	numbers = list(map(int, input().split()))
	(high, low) = (max(numbers), min(numbers))
	D = (high - low) // 2
	if (high - low) % 2 == 1:
		D = high - low
	desired = high - D
	for num in numbers:
		if num > desired:
			if num - D != desired:
				return -1
		elif num < desired:
			if num + D != desired:
				return -1
	return D
print(main())


n = int(input())
e = input().split()
l = []
for i in e:
	if int(i) not in l:
		l.append(int(i))
l.sort()
if len(l) == 1:
	d = 0
elif len(l) == 2:
	d = l[-1] - l[0]
	if d % 2 == 0:
		d = d // 2
elif len(l) == 3:
	d = (l[-1] - l[0]) // 2
	if l[0] + d not in l or l[0] + d != l[-1] - d:
		print(-1)
		exit(0)
	for i in l:
		if i != l[0] + d and i != l[0] and (i != l[-1]):
			print(-1)
			exit(0)
else:
	print(-1)
	exit(0)
print(d)


from math import gcd
n = int(input())
v = [int(i) for i in input().split()]
v.sort()
dist = 0
a = len(set(v))
for i in range(1, n):
	if v[i] - v[i - 1] != 0:
		dist = v[i] - v[i - 1]
		break
for i in range(1, n):
	if v[i] - v[i - 1] != dist and v[i] - v[i - 1] != 0 and (v[i] - v[i - 1] != -dist):
		break
else:
	if a == 2:
		if int(dist / 2) == dist / 2:
			print(dist // 2)
			exit()
	elif a > 3:
		print(-1)
		exit()
	print(dist)
	exit()
if a == 1:
	print(0)
elif a > 2:
	print(-1)


n = int(input())
A = list(map(int, input().split()))
A.sort()
for d in range(101):
	t = A[0] + d
	for a in A:
		if a - d == t or a + d == t or a == t:
			continue
		else:
			break
	else:
		print(d)
		exit()
else:
	print(-1)


n = int(input().strip())
data = [int(x) for x in input().split(' ')]
s = set(data)
if len(s) > 3:
	print(-1)
elif len(s) == 1:
	print(0)
elif len(s) == 2:
	(a, b) = (min(s), max(s))
	if (b - a) % 2 == 0:
		print((b - a) // 2)
	else:
		print(b - a)
else:
	data = list(s)
	data.sort()
	(a, b, c) = data
	if (c - a) % 2 == 0 and b + (c - a) // 2 == c:
		print((c - a) // 2)
	else:
		print(-1)


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect

def solve():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if n == 1:
		print(0)
		return
	ans = max(a) - min(a)
	stable = False
	if ans % 2 == 0:
		stable = True
		ans = ans // 2
	for i in range(n - 1):
		k = abs(a[i + 1] - a[i])
		if stable:
			if k != 0 and (not (k == ans or k == ans * 2)):
				print(-1)
				return
		elif k != 0 and k != ans:
			print(-1)
			return
	print(ans)
solve()


bisa = True
n = int(input())
angka = list(map(int, input().split()))
(kecil, besar) = (min(angka), max(angka))
jml = besar + kecil
tengah = jml // 2
d = tengah - kecil
if jml % 2 == 0:
	for idx in range(n):
		if angka[idx] < tengah:
			angka[idx] += d
			if angka[idx] > tengah:
				bisa = False
				break
		elif angka[idx] > tengah:
			angka[idx] -= d
			if angka[idx] < tengah:
				bisa = False
				break
		else:
			continue
elif len(set(angka)) == 2:
	d = besar - kecil
else:
	bisa = False
print(d if bisa else -1)


import sys
T = int(input())
l = list(map(int, input().split()))
p = sorted(list(set(l)))
X = []
if len(p) > 1:
	temp = abs(p[0] - p[1])
else:
	print(0)
	sys.exit(0)
count = 0
alpha = 0
for i in range(len(p) - 1):
	if abs(p[i] - p[i + 1]) == temp:
		if p[i] - p[i + 1] < 0:
			count += 1
	else:
		alpha = -1
		print(-1)
		break
	if count == 3:
		alpha = -1
		print(-1)
		break
if alpha != -1:
	if len(p) == 2:
		if temp % 2 == 0:
			print(temp // 2)
		else:
			print(temp)
	else:
		print(temp)


import sys
input = sys.stdin.readline

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

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

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

def li():
	return list(input().rstrip())
n = ii()
a = lmi()
seta = set(a)
if len(seta) == 3:
	D = (max(seta) - min(seta)) // 2
	if seta == {min(seta), min(seta) + D, min(seta) + 2 * D}:
		print(D)
	else:
		print(-1)
elif len(seta) == 2:
	if (max(seta) - min(seta)) % 2 == 0:
		print((max(seta) - min(seta)) // 2)
	else:
		print(max(seta) - min(seta))
elif len(seta) == 1:
	print(0)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1] - a[0]
y = x // 2 if x % 2 == 0 else x
ex = y + a[0]
wrong = False
for i in a[1:]:
	if i + y != ex and i - y != ex and (i != ex):
		wrong = True
		break
if wrong:
	print(-1)
elif x % 2 == 0:
	print(x // 2)
else:
	print(x)


n = int(input())
u = list(map(int, input().split()))
u.sort()
p = [u[0]]
for i in range(1, n):
	if u[i] != u[i - 1]:
		p.append(u[i])
		if len(p) == 4:
			print(-1)
			exit()
if len(p) == 1:
	print(0)
elif len(p) == 2:
	if abs(p[1] - p[0]) % 2 == 0:
		print(abs(p[1] - p[0]) // 2)
	else:
		print(abs(p[1] - p[0]))
elif p[1] - p[0] == p[2] - p[1]:
	print(p[2] - p[1])
else:
	print(-1)


n = int(input())
m = list(map(int, input().split()))
s = 0
d = {}
for i in range(n):
	if m[i] not in d.keys():
		d[m[i]] = 1
t = len(d.keys())
if t > 3:
	print(-1)
elif t == 1:
	print(0)
elif t == 2:
	l = list(d.keys())
	l.sort()
	a = l[0]
	b = l[1]
	x = a + b
	if x % 2 == 0:
		d = int((b - a) / 2)
		print(d)
	else:
		print(b - a)
else:
	l = list(d.keys())
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	x = a + c
	if x % 2 == 0:
		if int(x / 2) == b:
			print(b - a)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
xs = [int(elm) for elm in input().split(' ')]
xs2 = sorted(list(set(xs)))
xs = xs2
len_xs2 = len(xs2)
if len_xs2 == 1:
	out = 0
elif len_xs2 == 2:
	out = xs[1] - xs[0]
	if out % 2 == 0:
		out //= 2
elif len_xs2 == 3:
	if xs[1] - xs[0] == xs[2] - xs[1]:
		out = xs[1] - xs[0]
	else:
		out = -1
else:
	out = -1
print(out)


input()
x = list(map(int, input().split()))
s = set(x)
m = max(s)
n = min(s)
y = len(s)
z = abs(m - n)
if y == 3:
	if z % 2 != 0:
		print('-1')
	else:
		s.remove(m)
		s.remove(n)
		l = s.pop()
		if m - l == l - n:
			print(f'{m - l}')
		else:
			print('-1')
elif y == 2:
	if (m - n) % 2 == 0:
		print(f'{(m - n) // 2}')
	else:
		print(f'{m - n}')
elif y == 1:
	print('0')
else:
	print('-1')


n = int(input())
a = [int(i) for i in input().split()]
uniq = sorted(list(set(a)))
if len(uniq) == 1:
	print(0)
elif len(uniq) == 2:
	diff = uniq[1] - uniq[0]
	print('%d' % (diff // 2 if diff % 2 == 0 else diff))
elif len(uniq) == 3:
	diff = uniq[2] - uniq[0]
	if diff % 2 == 0:
		if uniq[0] + diff // 2 == uniq[1]:
			print(diff // 2)
		else:
			print(-1)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
A = [int(i) for i in input().split()]
if len(set(A)) > 3:
	print(-1)
elif len(set(A)) == 3:
	A = sorted(list(set(A)))
	if A[1] + A[1] - A[0] == A[2]:
		print(A[1] - A[0])
	else:
		print(-1)
elif len(set(A)) == 2:
	A = sorted(list(set(A)))
	ans = max(A) - min(A)
	if (A[1] - A[0]) % 2 == 0:
		ans = min(ans, (A[1] - A[0]) // 2)
	print(ans)
else:
	print(0)


_ = input()
numbers = list(map(int, input().strip().split()))
numbers = sorted(list(set(numbers)))
if len(numbers) == 1:
	print(0)
elif len(numbers) == 2:
	med = sum(numbers) / 2
	if med.is_integer():
		print(int(med) - min(numbers))
	else:
		print(max(numbers) - min(numbers))
elif len(numbers) == 3:
	if numbers[1] - numbers[0] == numbers[2] - numbers[1]:
		print(numbers[1] - numbers[0])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
arr = input().split()
for i in range(n):
	arr[i] = int(arr[i])
arr = list(set(arr))
if len(arr) == 1:
	print(0)
elif len(arr) == 2:
	if abs((arr[0] - arr[1]) / 2) == abs((arr[0] - arr[1]) // 2):
		print(int(abs((arr[0] - arr[1]) / 2)))
	else:
		print(abs(arr[0] - arr[1]))
elif len(arr) == 3:
	ma = max(arr)
	mi = min(arr)
	arr.remove(ma)
	arr.remove(mi)
	if arr[0] == (ma + mi) / 2:
		print(int((ma - mi) / 2))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
s = set(map(int, input().split()))
l = len(s)
if l > 3:
	print(-1)
if l == 1:
	print(0)
(M, m) = (max(s), min(s))
if l == 2:
	if M % 2 == m % 2:
		print((M - m) // 2)
	else:
		print(M - m)
if l == 3:
	if M % 2 == m % 2:
		if (M + m) // 2 in s:
			print((M - m) // 2)
		else:
			print(-1)
	else:
		print(-1)


def func():
	n = int(input())
	nums = [int(i) for i in input().split(' ')]
	mx = max(nums)
	mn = min(nums)
	md = (mx + mn) / 2
	res = (mx - mn) // 2
	count = dict()
	for i in nums:
		if not count.get(i):
			count[i] = 0
		count[i] += 1
	if len(count) == 2:
		if md == int(md):
			return int(res)
		s = list(count.items())
		return int(abs(s[0][0] - s[1][0]))
	if md != int(md):
		return -1
	for i in nums:
		if i != mn and i != mx and (i != md):
			return -1
	return res
print(func())


a = input()
lst = [int(i) for i in input().split()]
lst = list(set(lst))
if len(lst) == 2:
	if (lst[1] - lst[0]) % 2 == 1:
		print(int(abs(lst[1] - lst[0])))
	else:
		print(int(abs(lst[1] - lst[0]) / 2))
elif len(lst) == 1:
	print(0)
elif len(lst) > 3:
	print(-1)
elif max(lst) + min(lst) == 2 * (sum(lst) - max(lst) - min(lst)):
	print(int((max(lst) - min(lst)) / 2))
else:
	print(-1)


def isValid(arr, k):
	d = []
	for i in arr:
		if i != k:
			d.append(abs(k - i))
	return (len(set(d)) == 1, d[0])
n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr.sort()
if n == 1 or arr[0] == arr[-1]:
	print(0)
else:
	ans = 999999999
	for i in range(arr[0], arr[-1] + 1):
		(isPos, d) = isValid(arr, i)
		if isPos:
			if d < ans:
				ans = d
	print(-1 if ans == 999999999 else ans)


input()
inp = {int(c) for c in input().split()}
if len(inp) > 3:
	print(-1)
elif len(inp) == 1:
	print(0)
elif len(inp) == 2:
	a = abs(inp.pop() - inp.pop())
	if a % 2 == 0:
		print(a // 2)
	else:
		print(a)
else:
	a = [i for i in inp]
	a.sort()
	if a[1] - a[0] != a[2] - a[1]:
		print(-1)
	else:
		print(a[2] - a[1])


n = int(input())
a = list(map(int, input().split()))
c = list(set(a))
if len(c) == 1:
	print(0)
	exit()
if len(c) == 2:
	if abs(c[0] - c[1]) % 2 == 0:
		print(abs(c[0] - c[1]) // 2)
		exit()
	else:
		print(abs(c[0] - c[1]))
		exit()
if len(c) == 3:
	c = sorted(c)
	if abs(c[0] - c[1]) == abs(c[2] - c[1]):
		print(abs(c[0] - c[1]))
		exit()
	else:
		print(-1)
		exit()
print(-1)


n = int(input())
arr = [int(i) for i in input().split()]
max_ = max(arr)
min_ = min(arr)

def solve():
	d = (max_ - min_) // 2
	if 2 * d != max_ - min_:
		for i in arr:
			if i != max_ and i != min_:
				print(-1)
				return
		print(max_ - min_)
		return
	for i in arr:
		if i == max_ or i == min_ or i == min_ + d:
			continue
		else:
			print(-1)
			return
	print(d)
solve()


n = int(input())
a = set()
s = [int(i) for i in input().split()]
for i in s:
	a.add(i)
if len(a) == 1:
	print(0)
elif len(a) == 2:
	temp = list(a)
	if sum(temp) % 2 == 0:
		print(sum(temp) // 2 - min(temp))
	else:
		print(max(temp) - min(temp))
elif len(a) == 3:
	temp = list(a)
	temp.sort()
	if (temp[-1] + temp[0]) / 2 == temp[1]:
		print(temp[-1] - temp[1])
	else:
		print(-1)
else:
	print(-1)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
s = list(set(arr))
s.sort()
if len(s) > 3:
	print(-1)
elif len(s) == 3:
	if s[1] - s[0] == s[2] - s[1]:
		print(s[1] - s[0])
	else:
		print(-1)
elif len(s) == 2:
	if (s[1] - s[0]) % 2 == 0:
		print((s[1] - s[0]) // 2)
	else:
		print(s[1] - s[0])
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = (l[-1] - l[0]) / 2
m = l[0] + c
if int(c) == c:
	flag = True
	c = int(c)
	for i in range(len(l)):
		if l[i] < m:
			if l[i] + c != m:
				flag = False
				break
		elif l[i] > m:
			if l[i] - c != m:
				flag = False
				break
		else:
			pass
	if flag:
		print(c)
	else:
		print(-1)
else:
	c = l[-1] - l[0]
	if len(set(l)) == 2:
		print(c)
	else:
		print(-1)


def main():
	input()
	s = set([int(x) for x in input().split()])
	n = len(s)
	if n == 2 or n == 3:
		s = list(s)
		s.sort()
		if n == 3:
			if (s[2] - s[0]) % 2 == 0:
				if (s[2] - s[0]) // 2 + s[0] == s[1] and s[2] - (s[2] - s[0]) // 2 == s[1]:
					print((s[2] - s[0]) // 2)
				else:
					print(-1)
			else:
				print(-1)
		elif (s[1] - s[0]) % 2 == 0:
			print((s[1] - s[0]) // 2)
		else:
			print(s[1] - s[0])
	elif n == 1:
		print(0)
	else:
		print(-1)
main()


x = int(input())
n = list(map(int, input().split()))
n = list(dict.fromkeys(n))
n.sort()
a = min(n)
b = max(n)
c = a + b
d = c // 2 - a
f = 0
if len(n) == 1:
	print(0)
	f = 2
elif c % 2 != 0 and len(n) == 2:
	print(b - a)
	f = 2
else:
	for i in range(len(n)):
		if n[i] + d == c // 2 or n[i] - d == c // 2 or n[i] == c // 2:
			pass
		else:
			f = 1
if f == 0 and f != 2:
	print(d)
elif f == 1:
	print(-1)


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce
n = [int(val) for val in sys.stdin.readline().split()][0]
a = list(set([int(val) for val in sys.stdin.readline().split()]))
best = float('inf')
for med in range(101):
	val = float('inf')
	diffs = set([abs(val - med) for val in a])
	if len(diffs) == 1:
		val = list(diffs)[0]
	elif len(diffs) == 2 and 0 in diffs:
		diffs.remove(0)
		val = list(diffs)[0]
	best = min(val, best)
if best == float('inf'):
	print(-1)
else:
	print(best)


import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
n = int(input())
x = set()
for i in input().split():
	x.add(int(i))
m = len(x)
if m == 1:
	ans = 0
elif m == 2:
	aa = abs(x.pop() - x.pop())
	if aa % 2 == 1:
		ans = aa
	else:
		ans = aa // 2
elif m == 3:
	(s, t, u) = (x.pop(), x.pop(), x.pop())
	(s, t, u) = (max(s, t, u), s + t + u - max(s, t, u) - min(s, t, u), min(s, t, u))
	if abs(s - t) == abs(t - u):
		ans = abs(s - t)
	else:
		ans = -1
else:
	ans = -1
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
from math import *
mini = min(arr)
maxi = max(arr)
if mini == maxi:
	print(0)
else:
	d = {}
	for key in arr:
		if key in d:
			d[key] += 1
		else:
			d[key] = 1
	if len(d) == 2:
		add = mini + maxi
		if ceil(add / 2) == floor(add / 2):
			print(add // 2 - mini)
		else:
			print(maxi - mini)
	elif len(d) == 3:
		items = list(d.keys())
		items.sort()
		add = mini + maxi
		if ceil(add / 2) == floor(add / 2) and add // 2 == items[1]:
			print(items[1] - items[0])
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
lst = sorted(list(set(map(int, input().split()))))
if len(lst) >= 4:
	print(-1)
elif len(lst) == 1:
	print(0)
elif len(lst) == 2:
	bet = (lst[1] + lst[0]) // 2
	if bet - lst[0] == lst[1] - bet:
		print(bet - lst[0])
	else:
		print(lst[1] - lst[0])
elif lst[2] - lst[1] == lst[1] - lst[0]:
	print(lst[1] - lst[0])
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a = set(a)
a = list(a)
a.sort()
if len(a) == 1:
	print(0)
elif len(a) > 3:
	print(-1)
else:
	ans = a[1] - a[0]
	for i in range(len(a) - 1):
		d = a[i + 1] - a[i]
		if d != ans:
			ans = -1
			break
	if len(a) == 2 and ans % 2 == 0:
		print(ans // 2)
	else:
		print(ans)


n = int(input())
a = list(map(int, input().split()))
m = 101
for i in range(min(a), max(a) + 1):
	d = 0
	for j in a:
		if j != i:
			d = abs(j - i)
			break
	for j in a:
		if j != i and abs(j - i) != d:
			break
	else:
		m = min(m, d)
print(-1 if m == 101 else m)


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
d = a[n - 1] - a[0]
if d % 2 == 0:
	d //= 2
ok = True
for i in range(1, n):
	if a[i] - a[i - 1] != d and a[i] - a[i - 1] != 0 and (a[i] - a[i - 1] != 2 * d):
		ok = False
		break
if ok:
	print(d)
else:
	print(-1)


input()
a = list(set(list(map(int, input().split()))))
if len(a) == 1:
	print(0)
	exit()
a = sorted(a)
x = a[1] - a[0]
if len(a) > 3:
	print(-1)
elif len(a) == 2:
	print(x // 2 if x % 2 == 0 else x)
elif a[2] - a[1] == x:
	print(x)
else:
	print(-1)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	S = set()
	for el in arr:
		S.add(el)
	if len(S) > 3:
		print(-1)
		return
	els = []
	for e in S:
		els.append(e)
	els = sorted(els)
	if len(els) == 3:
		if els[1] - els[0] != els[2] - els[1]:
			print(-1)
			return
		else:
			print(els[1] - els[0])
			return
	if len(els) == 2:
		if (els[1] - els[0]) % 2 == 0:
			print(min(abs(els[1] - els[0]), (els[1] - els[0]) // 2))
		else:
			print(els[1] - els[0])
		return
	else:
		print(0)
main()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if len(arr) == 1:
	print(0)
else:
	arr1 = [arr[0]]
	flag = 0
	for i in range(1, n):
		if arr[i] != arr1[-1]:
			arr1.append(arr[i])
	if len(arr1) == 1:
		print(0)
	else:
		diff = arr1[1] - arr1[0]
		for i in range(2, len(arr1)):
			if arr1[i] - arr1[i - 1] != diff:
				flag = 1
				break
		if flag == 1 or len(arr1) > 3:
			print(-1)
		else:
			if diff % 2 == 0 and len(arr1) == 2:
				diff = diff // 2
			print(diff)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	res = set(a)
	if len(res) == 1:
		return print(0)
	if len(res) > 3:
		return print(-1)
	if len(res) == 2:
		first = res.pop()
		second = res.pop()
		div = max(first, second) - min(first, second)
		return print(div // 2 if div % 2 == 0 else div)
	res = sorted(list(res))
	div = (res[-1] + res[0]) / 2
	if div - int(div) > 0:
		return print(-1)
	return print(-1 if int(div) != res[1] else res[1] - res[0])
main()


n = int(input())
arr = list(map(int, input().split(' ')))
unique = list(set(arr))
unique.sort()
if len(unique) == 3:
	if unique[1] == (unique[0] + unique[2]) / 2:
		print(int(unique[1] - unique[0]))
		exit()
	else:
		print(-1)
		exit()
elif len(unique) == 2:
	if (unique[0] + unique[1]) / 2 == int((unique[0] + unique[1]) / 2):
		a = int((unique[1] - unique[0]) / 2)
		b = int(unique[1] - unique[0])
		print(min(a, b))
		exit()
	else:
		print(int(unique[1] - unique[0]))
		exit()
elif len(unique) == 1:
	print(0)
else:
	print(-1)
	exit()


a = int(input())
lam = list(map(int, input().split()))
lam = list(set(lam))
lam.sort()
if len(lam) == 1:
	print(0)
elif len(lam) == 2:
	ham = lam[0] + lam[1]
	if ham % 2 == 0:
		hg = ham // 2
		nam = hg - lam[0]
	else:
		nam = 5555555
	print(min(nam, lam[1] - lam[0]))
elif len(lam) == 3:
	jam = lam[1] - lam[0]
	kam = lam[2] - lam[1]
	if jam == kam:
		print(jam)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ansexist = False
ans = -1
if len(set(l)) <= 2:
	ansexist = True
	ans = l[-1] - l[0]
if (l[0] + l[-1]) % 2 != 0 and (not ansexist):
	print(-1)
else:
	avg = int((l[0] + l[-1]) / 2)
	D = int(abs(l[-1] - avg))
	for i in range(len(l)):
		if l[i] > avg:
			l[i] = l[i] - D
		elif l[i] < avg:
			l[i] = l[i] + D
	a = l[0]
	val = True
	for i in range(1, len(l)):
		if l[i] != a:
			val = False
			break
	if ansexist:
		if val:
			D = min(D, ans)
		else:
			D = ans
			val = True
	print(D if val else -1)


n = int(input())
d = list(set(list(map(int, input().split()))))
ans = 10 ** 9
for i in range(1000):
	dif = []
	for j in range(len(d)):
		if abs(d[j] - i) != 0:
			dif.append(abs(d[j] - i))
	if len(dif) != 0:
		dif.sort()
		if dif[0] == dif[-1]:
			ans = min(dif[0], ans)
	else:
		ans = min(0, ans)
if ans != 10 ** 9:
	print(ans)
else:
	print(-1)


n = int(input())
line = input().split(' ')
ints = [int(i) for i in line]
mx = max(ints)
mn = min(ints)
md = int((mx - mn) / 2)
med = mn + (mx - mn) / 2
ans = False
if mn == mx:
	print(0)
	ans = True
if not ans:
	ans = True
	for i in ints:
		if i != mx and i != mn:
			ans = False
			break
	if ans:
		if ((mx - mn) / 2).is_integer():
			print(int((mx - mn) / 2))
		else:
			print(int(mx - mn))
if not ans:
	if not med.is_integer():
		print(-1)
		ans = True
med = int(med)
if not ans:
	ans = True
	for i in ints:
		if not (i > med and i - md == med or (i < med and i + md == med) or i == med):
			ans = False
			break
	if ans:
		print(int((mx - mn) / 2))
	else:
		print(-1)


n = int(input())
x = [int(q) for q in input().split()]
y = sorted(list(set(map(int, x))))
a = len(sorted(list(set(map(int, x)))))
if a == 1:
	print(0)
elif a == 2:
	if abs(y[0] - y[1]) % 2 == 0:
		print(abs(y[0] - y[1]) // 2)
	else:
		print(abs(y[0] - y[1]))
elif a == 3:
	if (y[0] + y[2]) / 2 == y[1]:
		print(abs(y[1] - y[0]))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
if len(a) > 3:
	print(-1)
elif len(a) == 3:
	maxx = max(a)
	minn = min(a)
	av = sum(a) - maxx - minn
	if av - minn == maxx - av:
		print(av - minn)
	else:
		print(-1)
elif len(a) == 2:
	maxx = max(a)
	minn = min(a)
	if (maxx - minn) % 2 == 0:
		print((maxx - minn) // 2)
	else:
		print(maxx - minn)
else:
	print(0)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
set2 = set(a)
set1 = list(set2)
set1.sort()
if len(set1) == 1:
	print('0')
else:
	d = set1[1] - set1[0]
	c = 0
	if len(set1) == 2:
		if d % 2 == 0:
			print(d // 2)
		else:
			print(d)
	elif len(set1) == 3:
		if set1[1] - set1[0] == set1[2] - set1[1]:
			print(set1[1] - set1[0])
		else:
			print('-1')
	else:
		print('-1')


import sys
import math
import re
import io

def solve(my_set):
	n = len(my_set)
	my_list = sorted(list(my_set))
	if n == 1:
		return 0
	if n == 2:
		a = my_list[0]
		b = my_list[1]
		if (b - a) % 2 == 0:
			return (b - a) // 2
		else:
			return b - a
	if n == 3:
		a = my_list[0]
		b = my_list[1]
		c = my_list[2]
		if c - b == b - a:
			return c - b
	return -1

def main():
	input()
	my_set = set()
	for a in map(int, input().split()):
		my_set.add(a)
	ans = solve(my_set)
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
res = []
for pos in range(101):
	for d in range(101):
		k = 0
		for j in range(n):
			if a[j] == pos:
				k += 1
			elif a[j] + d == pos:
				k += 1
			elif a[j] - d == pos:
				k += 1
		if k == n:
			res.append(d)
if len(res) == 0:
	print(-1)
else:
	print(min(res))


n = int(input())
l = list(map(int, input().rstrip().split(' ')))
l.sort()
z = list(set(l))
lz = len(z)
if lz == 1:
	print(0)
elif lz == 2:
	if abs(z[1] - z[0]) % 2:
		print(abs(z[1] - z[0]))
	else:
		print(abs(z[1] - z[0]) // 2)
elif lz > 3:
	print(-1)
elif abs(z[0] - z[1]) == abs(z[1] - z[2]):
	print(abs(z[0] - z[1]))
else:
	print(-1)


n = int(input())
numbers = map(int, input().split())
s = set()
for i in numbers:
	s.add(i)
if len(s) == 1:
	print(0)
elif len(s) == 2:
	s2 = list(s)
	if abs(s2[1] - s2[0]) % 2:
		print(abs(s2[1] - s2[0]))
	else:
		print(abs(s2[1] - s2[0]) // 2)
elif len(s) == 3:
	s2 = sorted(list(s))
	if s2[1] - s2[0] == s2[2] - s2[1]:
		print(s2[1] - s2[0])
	else:
		print(-1)
else:
	print(-1)


import math
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a)):
	if not a[i] in b:
		b.append(a[i])
b.sort()
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	hieu1 = b[1] - b[0]
	hieu2 = b[2] - b[1]
	if hieu1 == hieu2:
		print(hieu1)
	else:
		print(-1)
elif len(b) == 2:
	ave = (b[1] - b[0]) / 2
	cave = math.floor(ave)
	if ave == cave:
		print(int(ave))
	else:
		print(b[1] - b[0])
else:
	print(0)


T = int(input())
lst = list(map(int, input().split()))
x = sum(lst) // T
if T == 1:
	print(0)
else:
	s = set(lst)
	fucked = []
	for i in s:
		fucked.append(i)
	fucked.sort()
	if len(fucked) == 1:
		print(0)
	elif len(fucked) == 2:
		zee = abs(fucked[1] - fucked[0])
		if zee & 1 != 0:
			print(abs(zee))
		else:
			print(zee // 2)
	elif len(fucked) == 3:
		if fucked[1] - fucked[0] == fucked[2] - fucked[1]:
			print(abs(fucked[1] - fucked[0]))
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
A = set(list(map(int, input().split())))
sum = sum(A)
n = len(A)
if sum % n == 0:
	D = 0
	for a in A:
		if D == -1 or D == 0:
			D = abs(sum // n - a)
		if abs(sum // n - a) != D and abs(sum // n - a) != 0:
			print(-1)
			break
	else:
		print(D)
elif n == 2:
	L = list(A)
	print(abs(L[1] - L[0]))
else:
	print(-1)


from sys import stdin
A = int(stdin.readline())
B = set(list(map(int, stdin.readline().split())))
if len(B) > 3:
	print(-1)
elif len(B) == 2:
	B = list(B)
	if (B[0] - B[1]) % 2 == 0:
		print(int(min(abs((B[0] - B[1]) / 2), abs(B[0] - B[1]))))
	else:
		print(abs(B[0] - B[1]))
elif len(B) == 3:
	B = list(B)
	B.sort()
	if B[0] + (B[2] - B[0]) / 2 == B[1]:
		print(int((B[2] - B[0]) / 2))
	else:
		print(-1)
else:
	print(0)


import sys
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n == 1:
	print(0)
	sys.exit(0)
flag = False
for i in range(100):
	k = l[:]
	for j in range(n):
		if j == 0:
			k[j] += i
		elif k[j] < k[0]:
			k[j] += i
		elif k[j] > k[0]:
			k[j] -= i
		else:
			pass
	for j in range(n - 1):
		if k[j] == k[j + 1]:
			flag = True
		else:
			flag = False
			break
	if flag:
		print(i)
		sys.exit()
	for j in range(n):
		if j == 0:
			k[j] -= i
		elif k[j] < k[0]:
			k[j] += i
		elif k[j] > k[0]:
			k[j] -= i
		else:
			pass
	for j in range(n - 1):
		if k[j] == k[j + 1]:
			flag = True
		else:
			flag = False
			break
	if flag:
		print(i)
		sys.exit()
print(-1)


input()
nums = set(map(int, input().split(' ')))
if len(nums) == 1:
	print(0)
	exit(0)
elif len(nums) == 2:
	(a, b) = sorted(list(nums))
	if (b - a) % 2 == 0:
		print((b - a) // 2)
	else:
		print(b - a)
	exit(0)
elif len(nums) == 3:
	(a, b, c) = sorted(list(nums))
	if c - b == b - a:
		print(b - a)
		exit(0)
print(-1)


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

def check(t, i):
	tt = [x for x in t]
	mm = max(tt)
	mn = min(tt)
	for j in range(len(tt)):
		if tt[j] == mn:
			tt[j] += i
		if tt[j] == mm:
			tt[j] -= i
	if len(set(tt)) == 1:
		return i
	return -1

def cc():
	for i in range(0, 100):
		ans = check(vals, i)
		if ans != -1:
			print(ans)
			return
	print(-1)
cc()


n = int(input())
a = list(map(int, input().split()))
s = []
for k in a:
	if not k in s:
		s.append(k)
if len(s) > 3:
	print(-1)
	raise SystemExit
if len(s) == 1:
	print(0)
	raise SystemExit
s.sort()
if len(s) == 2:
	d = (s[0] + s[1]) // 2 - s[0]
	if d + s[0] == s[1] - d:
		print(d)
	else:
		print(s[1] - s[0])
	raise SystemExit
if s[1] - s[0] == s[2] - s[1]:
	print(s[1] - s[0])
else:
	print(-1)


input()
a = sorted(set(map(lambda x: int(x), input().split())))
if len(a) > 3:
	print(-1)
elif len(a) == 1:
	print(0)
elif len(a) == 2:
	dif = a[1] - a[0]
	print(dif // 2 if dif & 1 == 0 else dif)
else:
	dif1 = a[1] - a[0]
	dif2 = a[2] - a[1]
	if dif1 == dif2:
		print(dif1)
	else:
		print(-1)


def get_answer(input_numbers):
	norm_list = sorted(list(set(input_numbers)))
	if len(norm_list) > 3:
		return -1
	elif len(norm_list) == 1:
		return 0
	elif len(norm_list) == 2:
		if (norm_list[1] - norm_list[0]) % 2 == 0:
			return (norm_list[1] - norm_list[0]) / 2
		else:
			return norm_list[1] - norm_list[0]
	else:
		d = (norm_list[2] - norm_list[0]) / 2
		if norm_list[1] + d == norm_list[2]:
			return d
		return -1
chert = int(input())
input_numbers = list(map(int, input().split()))
print(int(get_answer(input_numbers)))


n = int(input())
l = [int(n) for n in set(input().split())]
x = 1011
l = sorted(l)
if len(l) > 3:
	print('-1')
elif len(l) == 3:
	if (l[0] + l[2]) % 2 == 0 and (l[0] + l[2]) // 2 == l[1]:
		print((l[0] + l[2]) // 2 - l[0])
	else:
		print('-1')
elif len(l) == 2:
	if (l[0] + l[1]) % 2 == 0:
		x = (l[0] + l[1]) // 2
	print(min(x - l[0], l[1] - l[0]))
elif len(l) == 1:
	print('0')


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
n = inp()
x = ip()
x = sorted(set(x))
if len(x) > 3:
	print(-1)
elif len(x) == 3:
	(d1, d2) = (x[2] - x[1], x[1] - x[0])
	if d1 == d2:
		print(d1)
	else:
		print(-1)
elif len(x) == 2:
	d = x[1] - x[0]
	if d & 1:
		print(d)
	else:
		print(d // 2)
else:
	print(0)


n = int(input())
a = sorted(list(set(map(int, input().split()))))
min_a = min(a)
max_a = max(a)
if len(a) == 1:
	print(0)
elif len(a) == 2:
	if (a[1] - a[0]) % 2 == 0:
		print((a[1] - a[0]) // 2)
	else:
		print(a[1] - a[0])
elif len(a) == 3:
	if int(a[1]) - int(a[0]) == int(a[2]) - int(a[1]):
		print(a[2] - a[1])
	else:
		print(-1)
else:
	print(-1)


input()
array = {int(i) for i in input().split(' ')}
array = list(array)
array = sorted(array)
if len(array) == 0:
	print(-1)
	exit()
if len(array) == 1:
	print(0)
	exit()
if len(array) == 2:
	d = (array[1] - array[0]) / 2
	if int(d) == d and d > 0:
		print(int(d))
		exit()
	d = array[1] - array[0]
	if int(d) == d and d > 0:
		print(int(d))
		exit()
if len(array) == 3:
	d = array[2] - array[1]
	if d == array[1] - array[0] and d > 0 and (int(d) == d):
		print(d)
		exit()
print(-1)


n = int(input())
p = input().rstrip().split(' ')
x = list(set(p))
x.sort(key=int)
if len(x) == 1:
	print(0)
elif len(x) == 2:
	if (int(x[1]) - int(x[0])) % 2 == 0:
		print((int(x[1]) - int(x[0])) // 2)
	else:
		print(int(x[1]) - int(x[0]))
elif len(x) == 3:
	if int(x[1]) - int(x[0]) == int(x[2]) - int(x[1]):
		print(int(x[1]) - int(x[0]))
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
if mn == mx:
	print('0')
	exit()
d = mx - mn
for i in a:
	if i == mx:
		continue
	elif i == mn:
		continue
	elif i == (mx + mn) / 2:
		d = (mx + mn) // 2 - mn
		continue
	else:
		print('-1')
		exit()
if d == (mx + mn) // 2 - mn:
	print(d)
elif d % 2 == 0:
	print(d // 2)
elif d % 2 == 1:
	print(d)


import sys
input()
digits = list(sorted(set([int(x) for x in input().split()])))
if len(digits) > 3:
	print(-1)
elif len(digits) == 3:
	if digits[2] - digits[1] == digits[1] - digits[0]:
		print(digits[2] - digits[1])
	else:
		print(-1)
elif len(digits) == 2:
	diff = digits[1] - digits[0]
	print(diff if diff % 2 else diff // 2)
else:
	print(0)


n = int(input())
arr = list(map(int, input().rstrip().split(' ')))
setArr = sorted(list(set(arr)))
answer = -1
if len(setArr) == 3:
	if setArr[2] - setArr[1] == setArr[1] - setArr[0]:
		answer = setArr[2] - setArr[1]
elif len(setArr) == 2:
	answer = setArr[1] - setArr[0]
	if answer % 2 == 0:
		answer = answer // 2
elif len(setArr) == 1:
	answer = 0
print(answer)


from fractions import gcd
from collections import Counter

def main():
	n = int(input())
	A = [int(s) for s in input().split(' ')]
	while len(A) < n:
		A.extend([int(s) for s in input().split(' ')])
	A = A[:n]
	c = Counter(A)
	B = sorted(list(c.keys()))
	if len(B) > 3:
		print(-1)
		return
	if len(B) == 3:
		if B[0] + B[2] == B[1] + B[1]:
			print(B[1] - B[0])
			return
		else:
			print(-1)
			return
	if len(c) == 2:
		if (B[1] - B[0]) % 2 == 0:
			print((B[1] - B[0]) // 2)
			return
		else:
			print(B[1] - B[0])
			return
	if len(c) == 1:
		print(0)
		return
main()


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
d = Counter(l)
k = list(d.keys())
a = min(k)
b = max(k)
if len(k) == 2 and a + b & 1:
	print(b - a)
elif len(k) == 2:
	print((b - a) // 2)
elif len(k) <= 3:
	if a + b & 1:
		print(-1)
	elif (a + b) // 2 in k:
		print((b - a) // 2)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = sorted(list(set([int(i) for i in input().split()])))
if len(a) > 3:
	print(-1)
	exit(0)
if len(a) == 1:
	print(0)
	exit(0)
if len(a) == 2:
	if abs(a[0] - a[1]) % 2 == 0:
		print(int((max(a) - min(a)) / 2))
	else:
		print(max(a) - min(a))
	exit(0)
d = sum(a) / len(a)
if a[1] - a[0] != a[2] - a[1]:
	print(-1)
	exit(0)
print(int(d - min(a)))


from math import gcd
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
d = []
for i in arr:
	if not i in d:
		d.append(i)
if len(d) > 3:
	print(-1)
elif len(d) <= 2:
	if len(d) == 2:
		if (d[1] - d[0]) % 2 == 0:
			print((d[1] - d[0]) // 2)
		else:
			print(d[1] - d[0])
	else:
		print(0)
elif d[2] - d[1] == d[1] - d[0]:
	print(d[2] - d[1])
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
if len(set(a)) == 2:
	f = list(set(a))[0]
	s = list(set(a))[1]
	dd = (f + s) // 2
	ans1 = float('inf')
	if float(dd) == (f + s) / 2:
		ans1 = dd - min(f, s)
	ans2 = abs(f - s)
	print(min(ans1, ans2))
elif len(set(a)) == 1:
	print(0)
else:
	f = min(a)
	s = max(a)
	dd = (f + s) // 2
	if float(dd) != (f + s) / 2:
		print(-1)
		raise SystemExit
	for i in range(n):
		if a[i] != f and a[i] != s and (a[i] != dd):
			print(-1)
			raise SystemExit
	print(dd - f)


T = int(input())
K = list(map(int, input().strip().split()))[:T]
N = []
for k in range(0, T):
	if K[k] not in N:
		N.append(K[k])
N.sort()
if len(N) > 3:
	print(-1)
elif len(N) == 3:
	if N[0] + N[2] == 2 * N[1]:
		print(N[1] - N[0])
	else:
		print(-1)
elif len(N) == 2:
	a = N[1] - N[0]
	if a % 2 == 1:
		print(a)
	else:
		print(a // 2)
elif len(N) == 1:
	print(0)


a1 = int(input())
a = [i for i in map(int, input().split())]
av = 0
b = list(set(a))
for i in b:
	av += i
av1 = av / len(b)
b.sort()
c = sorted(b)
if len(b) > 3:
	print(-1)
elif len(b) == 3:
	if c[1] == av1:
		print(int(abs(av1 - c[0])))
	else:
		print(-1)
elif len(b) == 2:
	if abs(av1 - c[0]) - int(abs(av1 - c[0])) == 0:
		print(int(abs(av1 - c[0])))
	else:
		print(int(2 * abs(av1 - c[0])))
elif len(b) == 1:
	print(0)


from collections import defaultdict
from sys import stdin
from bisect import bisect_left as bl, bisect_right as br, insort
import heapq
from collections import deque
import math
n = int(input())
a = list(map(int, input().rstrip().split()))
diff = []
b = []
b = b + a
b = set(b)
b = list(b)
b.sort()
if len(b) == 1:
	print(0)
elif len(b) == 2:
	if (b[1] - b[0]) % 2 == 0:
		print((b[1] - b[0]) // 2)
	else:
		print(b[1] - b[0])
elif len(b) == 3:
	if b[2] - b[1] == b[1] - b[0]:
		print(b[2] - b[1])
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print(0)
else:
	l = list(set(a))
	l.sort()
	m1 = l[0]
	m2 = l[-1]
	if len(l) == 2:
		if (m1 + m2) / 2 - int((m1 + m2) / 2) == 0:
			print(int((m1 + m2) / 2) - m1)
		else:
			print(m2 - m1)
	elif len(l) == 3:
		if l[-1] - l[1] == l[1] - l[0]:
			print(l[1] - l[0])
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
l = list(map(int, input().split()))
s = set(l)
if len(s) == 1:
	print(0)
	exit()
s = list(s)
s = sorted(s)
if s[-1] - s[-2] + s[0] == s[1] and len(s) <= 3:
	v = s[-1] - s[-2]
	if len(s) == 2:
		if v % 2 == 0:
			print(v // 2)
			exit()
	print(v)
	exit()
print(-1)


n = int(input())
maior = 0
menor = 101
lista = []
entrada = input().split(' ')
for i in range(n):
	lista.append(int(entrada[i]))
	if maior < lista[i]:
		maior = lista[i]
	if menor > lista[i]:
		menor = lista[i]
dif = maior - menor
if dif % 2 == 0:
	dif = dif / 2
teste = False
for i in range(n):
	for j in range(n):
		if lista[i] != lista[j] and lista[i] + dif != lista[j] and (lista[i] - dif != lista[j]) and (lista[i] != lista[j] + dif) and (lista[i] + dif != lista[j] + dif) and (lista[i] - dif != lista[j] + dif) and (lista[i] != lista[j] - dif) and (lista[i] + dif != lista[j] - dif) and (lista[i] - dif != lista[j] - dif):
			teste = True
			break
	if teste:
		break
if teste == False:
	print(int(dif))
else:
	print('-1')


def equal(num):
	if len(num) == 0 or len(num) == 1:
		return 0
	elif len(num) == 2:
		value = int(num[1]) - int(num[0])
		if value % 2 == 0:
			value = int(value / 2)
		return value
	elif len(num) == 3 and int(num[2]) - int(num[1]) == int(num[1]) - int(num[0]):
		return int(num[2] - num[1])
	else:
		return -1

def main():
	l = input()
	temp_list = input().split(' ')
	temp_list = list(dict.fromkeys(temp_list))
	num = []
	for i in range(len(temp_list)):
		num.append(int(temp_list[i]))
	num.sort()
	result = equal(num)
	print(result)
main()


def solve(array):
	nandu = sorted(set(array))
	if len(nandu) == 1:
		print('0')
	elif len(nandu) == 2:
		if (nandu[1] - nandu[0]) % 2 == 0:
			print(int((nandu[1] - nandu[0]) / 2))
		else:
			print(nandu[1] - nandu[0])
	elif len(nandu) == 3:
		if nandu[2] - nandu[1] == nandu[1] - nandu[0]:
			X = nandu[2] - nandu[1]
			print(X)
		else:
			print('-1')
	else:
		print('-1')
n = int(input())
li = input()
array = li.split(' ')
array = [int(x) for x in array]
solve(array)


n = int(input())
a = [int(x) for x in input().split()]
if max(a) == min(a):
	print(0)
	exit()

def remove(duplicate):
	final_list = []
	for num in duplicate:
		if num not in final_list:
			final_list.append(num)
	return final_list
raw = []
for i in range(1, max(a) + 1):
	for j in range(len(a)):
		raw.append(a[j] - i)
		raw.append(a[j])
		raw.append(a[j] + i)
	unique = remove(raw)
	for k in range(len(unique)):
		occurences = raw.count(unique[k])
		if occurences == n:
			print(i)
			exit()
	raw.clear()
	unique.clear()
print(-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
maxx = a[-1]
ans = False
for i in range(1, maxx + 1):
	g = -1
	cnt = 0
	for j in a:
		if g == -1:
			cnt += 1
			g = abs(i + j)
			continue
		if abs(i - j) == g or abs(i + j) == g or j == g:
			cnt += 1
	if cnt == n:
		ans = True
		maxx = i
		break
if a[0] == a[-1]:
	ans = True
	maxx = 0
if ans:
	print(maxx)
else:
	print(-1)


n = int(input())
a = set(list(map(int, input().split())))
arr = list(a)
arr.sort()
ans = -1
if len(arr) == 1:
	print(0)
elif len(arr) == 2:
	num = arr[1] - arr[0]
	if num % 2 == 0:
		print(num // 2)
	else:
		print(num)
else:
	check = 0
	need = len(arr) - 1
	for i in range(0, 101):
		if check:
			break
		mark = [[] for _ in range(101)]
		for j in range(len(arr)):
			mark[abs(i - arr[j])].append(arr[j])
		for k in range(101):
			if len(mark[k]) == need and i in arr:
				ans = k
				check = 1
				break
	print(ans)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
diff = set(arr)
if len(diff) > 3:
	print(-1)
	exit()
if len(diff) == 3:
	arr = list(diff)
	arr.sort()
	if abs(arr[0] - arr[1]) != abs(arr[1] - arr[2]):
		print(-1)
	else:
		print((arr[2] - arr[0]) // 2)
if len(diff) == 2:
	arr = list(diff)
	arr.sort()
	if arr[0] + abs(arr[0] - arr[1]) / 2 != arr[1] - abs(arr[0] - arr[1]) // 2:
		print(arr[1] - arr[0])
	else:
		print((arr[1] - arr[0]) // 2)
if len(diff) == 1:
	print(0)


def makeequal():
	num_elements = int(input())
	a = input().split()
	list_elements = []
	for element in a:
		list_elements.append(int(element))
	new_list = []
	for i in range(0, len(list_elements)):
		if list_elements[i] not in new_list:
			new_list.append(list_elements[i])
	new_list = sorted(new_list, reverse=True)
	if len(new_list) == 1:
		print(0)
	elif len(new_list) == 2:
		k = new_list[0] - new_list[1]
		if k % 2 == 0:
			print(int(k / 2))
		else:
			print(k)
	elif len(new_list) == 3:
		minus = []
		for i in range(0, len(new_list) - 1):
			minus.append(new_list[i] - new_list[i + 1])
		if max(minus) - min(minus) == 0:
			print(minus[0])
		else:
			print(-1)
	else:
		print(-1)
makeequal()


n = int(input())
a = [int(x) for x in input().split()]
if len(set(a)) > 3:
	print(-1)
	exit()
if len(set(a)) == 2:
	if (max(a) - min(a)) % 2 == 0:
		print((max(a) - min(a)) // 2)
		exit()
	else:
		print(max(a) - min(a))
		exit()
	exit()
if len(set(a)) == 1:
	print(0)
	exit()
mn = [min(set(a))]
mx = [max(set(a))]
av = list(set(a) - set(mn) - set(mx))
if abs(mn[0] - av[0]) == abs(mx[0] - av[0]):
	print(abs(mx[0] - av[0]))
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
l1 = list(set(l))
l = sorted(l)
l1 = sorted(l1)
x = -1
y = -1
if len(l1) == 1:
	print(0)
elif len(l1) == 2:
	x = l[-1] - l[0]
	y = (l[-1] + l[0]) / 2
	if int(y) == y:
		print(int(min(x, y - l[0])))
	else:
		print(x)
elif len(l1) == 3:
	a = l1[0]
	b = l1[1]
	c = l1[2]
	if c - b == b - a:
		x = c - b
	if x == -1:
		print(-1)
	else:
		print(x)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
cnts = []
for i in range(1, 101):
	cur = -1
	mb = True
	for j in range(n):
		if i == l[j]:
			continue
		elif cur == -1:
			cur = abs(i - l[j])
		elif cur != abs(i - l[j]):
			mb = False
	if mb:
		if cur == -1:
			cnts.append(0)
		else:
			cnts.append(cur)
if len(cnts) == 0:
	print(-1)
else:
	print(min(cnts))


def f(v, d, target):
	for vi in v:
		if vi != target and vi + d != target and (vi - d != target):
			return False
	return True
N = int(input())
v = [int(i) for i in input().strip().split()]
max_v = max(v)
min_v = min(v)
(d1, d2) = ((max_v - min_v) // 2, max_v - min_v)
if f(v, d1, min_v + d1) or f(v, d1, min_v):
	print(d1)
elif f(v, d2, min_v + d2) or f(v, d2, min_v):
	print(d2)
else:
	print(-1)


from sys import stdin
import math
n = int(stdin.readline())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
d = -1
for i in range(len(nums) - 1):
	for j in range(i + 1, len(nums)):
		t = abs(nums[i] - nums[j])
		if t == 0:
			continue
		if t != 0 and d == -1:
			d = t
		elif d != -1 and t != d and (max(d, t) / 2 != min(d, t)):
			print(-1)
			exit()
s = set(nums)
if (max(s) - min(s)) % 2 == 0:
	print((max(s) - min(s)) // 2)
elif len(s) == 1:
	print(0)
else:
	print(d)


input()
s = set(map(int, input().split()))
if len(s) == 1:
	D = 0
elif len(s) == 2:
	D = max(s) - min(s)
	if D % 2 == 0:
		D = D // 2
elif len(s) == 3:
	lst = list(s)
	lst.sort()
	if lst[2] - lst[1] == lst[1] - lst[0]:
		D = lst[2] - lst[1]
	else:
		D = -1
else:
	D = -1
print(D)


def mod(x):
	if x < 0:
		return -x
	else:
		return x
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a = set(a)
a = list(a)
m = sum(a) / len(a)
m1 = a[0]
d = []
if len(a) == 1:
	print(0)
elif len(a) >= 4:
	print(-1)
elif len(a) == 3:
	a = sorted(a)
	(s, d, f) = (a[0], a[1], a[2])
	if s + f == 2 * d:
		print(f - d)
	else:
		print(-1)
elif (a[0] + a[1]) % 2 == 0:
	print(mod(int((a[1] + a[0]) / 2) - a[0]))
else:
	print(mod(a[0] - a[1]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[n - 1] - a[0]
y = x // 2
ans = a[0] + x
ans2 = a[0] + y
t = 0
for i in a:
	if i != ans2 and i + y != ans2 and (i - y != ans2):
		t = -1
		break
if t == 0:
	print(y)
	exit()
t = 0
for i in a:
	if i - x != ans and i + x != ans and (i != ans):
		t = -1
		break
if t == 0:
	print(x)
	exit()
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
s = set(a)
d = max(a) - min(a)
if len(s) < 3:
	if d % 2:
		print(d)
	else:
		print(d // 2)
elif d % 2 or len(s) > 3:
	print(-1)
else:
	d //= 2
	if min(a) + d in s:
		print(d)
	else:
		print(-1)


N = int(input())
lst = [int(i) for i in input().split(' ')]
lst.sort()
countDifValue = 1
temp = lst[0]
D = 0
for i in range(N):
	if lst[i] != temp:
		countDifValue = countDifValue + 1
		temp = lst[i]
if countDifValue == 1:
	D = 0
elif countDifValue == 2:
	D = temp - lst[0]
	if D % 2 == 0:
		D = D / 2
		D = int(D)
elif countDifValue > 3:
	D = -1
else:
	for i in range(N):
		if lst[i] != lst[0] and lst[i] != temp:
			if lst[i] - lst[0] == temp - lst[i]:
				D = lst[i] - lst[0]
			else:
				D = -1
print(D)


import math
n = int(input())
arr = list(map(int, input().split()))
s = set()
for i in arr:
	s.add(i)
if len(s) > 3:
	print(-1)
	exit()
tt = list(s)
tt.sort()
if len(s) == 1:
	print(0)
	exit()
if len(s) == 2:
	if (tt[1] - tt[0]) % 2 != 0:
		print(tt[1] - tt[0])
	else:
		print((tt[1] - tt[0]) // 2)
	exit()
if tt[2] - tt[1] == tt[1] - tt[0]:
	print(tt[1] - tt[0])
else:
	print(-1)


import sys
import math

def main(args):
	input()
	ar = sorted(set(map(int, input().split())))
	if len(ar) == 1:
		print('0')
	elif len(ar) == 2:
		print(ar[1] - ar[0] if (ar[1] - ar[0]) % 2 else ar[1] - ar[0] >> 1)
	elif len(ar) == 3:
		print('-1' if ar[1] - ar[0] != ar[2] - ar[1] else ar[1] - ar[0])
	else:
		print('-1')
sys.exit(main(sys.argv))


import math
n = int(input())
a = list(map(int, input().split()))
amax = int(1)
amin = int(101)
for i in range(0, n):
	if a[i] > amax:
		amax = a[i]
	if a[i] < amin:
		amin = a[i]
c = int((amax - amin) / 2)
ok = 1
for i in range(0, n):
	if abs(amax - c - a[i]) != c and abs(amax - c - a[i]) != 0:
		ok = 0
if ok == 1:
	print(c)
	exit()
c = int(amax - amin)
ok = 1
for i in range(0, n):
	if abs(amax - c - a[i]) != c and abs(amax - c - a[i]) != 0:
		ok = 0
if ok == 1:
	print(c)
	exit()
print(-1)


k = 1
d = 0
n = int(input())
a = []
K = [0] * 101
str = input().split()[:n]
for i in range(n):
	x = int(str[i])
	if K[x] == 0:
		a.append(x)
		K[x] = 1
k = sum(K)
if k > 3:
	d = -1
else:
	if k == 1:
		d = 0
	if k == 2:
		d = abs(a[1] - a[0]) / 2
		if not d.is_integer():
			d = abs(a[1] - a[0])
		d = int(d)
	if k == 3:
		a.sort()
		if a[2] - a[1] == a[1] - a[0]:
			d = a[1] - a[0]
		else:
			d = -1
print(d)


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
S = set(A)
if len(S) >= 4:
	print(-1)
elif len(S) == 3:
	mn = min(S)
	mx = max(S)
	S.remove(mn)
	S.remove(mx)
	mid = list(S)[0]
	if (mn + mx) / 2 == mid:
		print(mx - mid)
	else:
		print(-1)
elif len(S) == 2:
	mn = min(S)
	mx = max(S)
	if (mn + mx) % 2 == 0:
		print(mx - (mn + mx) // 2)
	else:
		print(mx - mn)
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
a.sort()
plus = (a[len(a) - 1] - a[0]) // 2
equel = a[len(a) - 1] - a[0]
p = 0
q = 0
for i in range(len(a)):
	if ((a[i] != a[0] and a[i] + plus != a[0]) and a[i] - plus != a[0]) and ((a[i] != a[0] + plus and a[i] + plus != a[0] + plus) and a[i] - plus != a[0] + plus):
		p = -1
	if ((a[i] != a[0] and a[i] + equel != a[0]) and a[i] - equel != a[0]) and ((a[i] != a[0] + equel and a[i] + equel != a[0] + equel) and a[i] - equel != a[0] + equel):
		q = -1
if p == 0:
	print(plus)
elif q == 0:
	print(equel)
else:
	print(-1)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
s = set(l)
if len(s) == 1:
	print(0)
elif len(s) == 2:
	(ma, mi) = (max(s), min(s))
	print(ma - mi if (ma - mi) % 2 else (ma - mi) // 2)
elif len(s) == 3:
	(ma, mi) = (max(s), min(s))
	k = list(s - set([ma, mi]))[0]
	print((ma - mi) // 2 if (ma - mi) % 2 == 0 and mi + (ma - mi) // 2 == k else -1)
else:
	print(-1)


n = int(input())
a = set(list(map(int, input().split())))
a = sorted(a, key=lambda x: x)
if len(a) > 3:
	print('-1')
elif len(a) == 3:
	if a[1] - a[0] == a[2] - a[1]:
		print(a[1] - a[0])
	else:
		print('-1')
elif len(a) == 2:
	if a[1] - a[0] & 1:
		print(a[1] - a[0])
	else:
		print((a[1] - a[0]) // 2)
else:
	print('0')


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
import re
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 9

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
		if meh < 0:
			meh = 0
	return msf

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))
n = int(input())
a = list(numIN())
for i in range(101):
	d = i
	for j in range(1, 101):
		x = j
		temp = list(a)
		for k in range(n):
			if temp[k] != x and abs(temp[k] - x) == d:
				temp[k] = x
		if len(set(temp)) == 1:
			print(d)
			exit(0)
print(-1)


def solve():
	n = input()
	words = input().split()
	nums = [int(i) for i in words]
	unum = set(nums)
	if len(unum) == 1:
		print('0')
	elif len(unum) == 2:
		nums = list(unum)
		if (nums[0] + nums[1]) % 2 == 0:
			print(abs(nums[0] - nums[1]) // 2)
		else:
			print(abs(nums[0] - nums[1]))
	elif len(unum) > 3:
		print('-1')
	else:
		unum = sorted(list(unum))
		if unum[1] * 2 != unum[0] + unum[2]:
			print('-1')
		else:
			print(unum[1] - unum[0])
solve()


import math as mt
import collections as cc
import sys
I = lambda : set(map(int, input().split()))
(n,) = I()
l = sorted(I())
if len(l) == 1:
	print(0)
elif len(l) == 2:
	t = abs(l[0] - l[-1])
	d = abs(l[0] - l[-1])
	tt = t + 1
	if d % 2 == 0:
		tt = d // 2
	print(min(d, tt))
elif len(l) == 3:
	d = l[1] - l[0]
	dd = l[2] - l[1]
	if d == dd:
		print(d)
	else:
		print(-1)
else:
	print(-1)


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

def solve():
	if len(set(a)) == 1:
		return 0
	INF = 1 << 30
	ret = INF
	for target in range(1, 101):
		delta = INF
		for num in a:
			if num > target:
				if delta == INF:
					delta = num - target
				elif delta != num - target:
					delta = INF
					break
			elif num < target:
				if delta == INF:
					delta = target - num
				elif delta != target - num:
					delta = INF
					break
		ret = min(ret, delta)
	return ret if ret != INF else -1
print(solve())


n = input()
l = [int(x) for x in input().split()]
s = set(l)
length = len(s)
if length > 3:
	print(-1)
elif length is 1:
	print(0)
elif length is 3:
	l2 = list(s)
	l2.sort()
	(a0, a1, a2) = l2
	if a2 + a0 == 2 * a1:
		print(a1 - a0)
	else:
		print(-1)
else:
	l2 = list(s)
	l2.sort()
	(x, y) = l2
	a = y - x
	if (x + y) % 2 is 0:
		b = (x + y) // 2 - l2[0]
	else:
		b = a
	print(min(a, b))


n = int(input())
ar = list(map(int, input().split()))
max_val = max(ar)
min_val = min(ar)
d = (max_val - min_val) / 2
mid_val = int(min_val + d)
if all([x == max_val or x == min_val or x == mid_val for x in ar]) and d - int(d) == 0:
	print(int(d))
else:
	mid_val = max(ar)
	d = mid_val - min_val
	max_val = mid_val + d
	if all([x == max_val or x == min_val or x == mid_val for x in ar]):
		print(d)
	else:
		print(-1)


n = int(input())
num = list(map(int, input().split()))
numtype = sorted(list(dict.fromkeys(num)), reverse=True)
if len(numtype) == 3 and numtype[0] - numtype[1] == numtype[1] - numtype[2]:
	print(numtype[0] - numtype[1])
elif len(numtype) == 2:
	a = numtype[0] - numtype[1]
	if a % 2 == 0:
		print(int(a / 2))
	else:
		print(a)
elif len(numtype) == 1:
	print(0)
else:
	print(-1)


from sys import stdin

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

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

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

def si():
	return stdin.readline()
n = ii()
a = li()
q = min(a)
p = max(a)
if (p + q) % 2:
	m = q
else:
	m = (p + q) // 2
for i in a:
	if i != p and i != q and (i != m):
		print(-1)
		exit()
print(p - m)


n = int(input())
arr = list(map(int, input().split()))
cnt = [0] * 101
ans = []
for i in range(n):
	cnt[arr[i]] += 1
if cnt.count(0) < 98:
	print(-1)
else:
	for i in range(201):
		for j in range(101):
			cnt2 = 0
			for k in range(n):
				if i == arr[k] or i == arr[k] + j or i == arr[k] - j:
					cnt2 += 1
			if cnt2 == n:
				ans.append(j)
	if len(ans) == 0:
		print(-1)
	else:
		ans = sorted(ans)
		print(ans[0])


def solve():
	n = int(input())
	lst = [int(i) for i in input().split()]
	arr = sorted(set(lst))
	if len(arr) == 1:
		print(0)
		return
	elif len(arr) == 2:
		if abs(arr[0] - arr[1]) & 1:
			print(abs(arr[0] - arr[1]))
		else:
			print(abs(arr[0] - arr[1]) // 2)
	elif len(arr) == 3:
		if abs(arr[0] - arr[1]) == abs(arr[1] - arr[2]):
			print(abs(arr[0] - arr[1]))
		else:
			print(-1)
	else:
		print(-1)
solve()


def solve():
	n = int(input())
	a = list((int(i) for i in input().split()))
	query = list(set(a))
	if len(query) == 1:
		print(0)
	elif len(query) == 2:
		tp = max(query) + min(query)
		if tp % 2 == 0:
			print(tp // 2 - min(query))
		else:
			print(max(query) - min(query))
	elif len(query) == 3:
		query.sort()
		minimum = query[0]
		medium = query[1]
		maximum = query[2]
		if maximum - medium == medium - minimum:
			print(maximum - medium)
		else:
			print(-1)
	else:
		print(-1)
		exit()
solve()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	a.sort()
	for x in a:
		if x not in s:
			s.add(x)
	s = list(s)
	if len(s) > 3:
		print(-1)
	elif len(s) == 3:
		if s[1] - s[0] == s[2] - s[1]:
			print(s[1] - s[0])
		else:
			print(-1)
	elif len(s) == 2:
		if (s[1] - s[0]) % 2 == 0:
			print((s[1] - s[0]) // 2)
		else:
			print(s[1] - s[0])
	elif len(s) == 1:
		print(0)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	c = collections.Counter(LI())
	if len(c) == 1:
		return 0
	if len(c) > 3:
		return -1
	a = sorted(c.keys())
	r = a[1] - a[0]
	if len(a) == 2:
		if r % 2 == 0:
			return r // 2
		return r
	if a[2] - a[1] != r:
		return -1
	return r
print(main())


n = int(input())
a = map(int, input().split())
s = set(a)
if len(s) > 3:
	print(-1)
elif len(s) == 3:
	if abs(min(s) - max(s)) % 2 == 0 and abs(min(s) - max(s)) // 2 + min(s) in s:
		print(abs(min(s) - max(s)) // 2)
	else:
		print(-1)
elif len(s) == 2:
	r = [abs(min(s) - max(s))]
	if abs(min(s) - max(s)) % 2 == 0:
		r.append(abs(min(s) - max(s)) // 2)
	t = filter(lambda x: x > 0, r)
	print(min(t))
elif len(s) == 1:
	print(0)


import math as m
n = int(input())
l = list(map(int, input().split()))
l = set(l)
l = list(l)
l.sort()
if len(l) > 3:
	print(-1)
elif len(l) == 2 and (min(l) + max(l)) % 2 == 0 or (len(l) == 3 and m.ceil((l[0] + l[2]) / 2) == l[1] and ((l[0] + l[2]) // 2 == l[1])):
	print((max(l) - min(l)) // 2)
elif len(l) == 1:
	print(0)
elif len(l) == 2 and (min(l) + max(l)) % 2 != 0:
	print(max(l) - min(l))
else:
	print(-1)


N = int(input())
a = list(map(int, input().split()))
s = sorted(list(set(a)))
if len(s) == 3:
	d = s[1] - s[0]
	if s[2] - s[1] == d:
		print(d)
	else:
		print(-1)
elif len(s) == 2:
	d = s[1] - s[0]
	if d & 1:
		print(d)
	else:
		print(d >> 1)
elif len(s) == 1:
	print(0)
else:
	print(-1)