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

Difficulty: introductory

Starter code:

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

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

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


N = int(input())
A = sorted(list(set([int(a) for a 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:
    if A[2]+A[0] == A[1] * 2:
        print(A[2]-A[1])
    else:
        print(-1)
else:
    print(-1)


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

if len(arr) == 1:
    print(0)
elif len(arr) == 2:
    if arr[1] % 2 == arr[0] % 2:
        print((arr[1] - arr[0]) // 2)
    else:
        print(arr[1] - arr[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)


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


n=int(input())
A=list(map(int,input().split()))
A=sorted(set(A))

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])%2==1:
        print(A[1]-A[0])
    else:
        print((A[1]-A[0])//2)

elif len(A)==1:
    print(0)
    



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)


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)

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


IN = input
rint = lambda: int(IN())
rmint = lambda: list(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)
else:
    if b[1]-b[0] == b[-1]-b[1]:
        print(b[1]-b[0])
    else:
        print(-1)


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)


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)

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

if len(set(a)) > 3:
    print(-1)
    return
    
if len(set(a)) == 1:
    print(0)
    return
    
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)
    return
    
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.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)

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


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)


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)
            return
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]))
else:
    if p[1] - p[0] == p[2] - p[1]:
        print(p[2] - p[1])
    else:
        print(-1)


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)

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



n = int(input())

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

arr = sorted(arr)

ans = 10000000000

for k in range(200):
    d = -1
    fl = 0
    #print("->",k)
    for i in range(n):
        c = abs(arr[i]-k)
        #print(c)
        if d==-1:
            d = c
        else:
            if d!=c and c>0:
                fl= 1
    if fl==0:
        ans = min(ans,d)
if ans==10000000000:
    print(-1)
else:
    print(ans)


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

def __starting_point():
    main()
__starting_point()