Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.

Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.

Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.


-----Input-----

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — elements of the array.


-----Output-----

If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).


-----Examples-----
Input
5
1 3 3 2 1

Output
YES

Input
5
1 2 3 4 5

Output
NO



-----Note-----

In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Implementation


Solutions:
n = int(input())
a = [int(x) for x in input().split()]
temp = sum(a) / n
a = list(set(a))
n = len(a)
if n == 1 or n == 2:
	print('YES')
elif n >= 4:
	print('NO')
else:
	a.sort()
	if 2 * a[1] == a[0] + a[2]:
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
ans = 'YES'
s = set()
for i in range(n):
	s.add(a[i])
x = len(s)
if x > 3:
	ans = 'NO'
elif x == 3:
	m = 0
	mi = min(s)
	ma = max(s)
	s.discard(mi)
	s.discard(ma)
	for c in s:
		m = c
	if m != (mi + ma) / 2:
		ans = 'NO'
print(ans)


n = int(input())
a = sorted(set(map(int, input().split())))
if len(a) < 3 or (len(a) == 3 and a[0] + a[2] == 2 * a[1]):
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
cnt = 1
a.sort()
b = [a[0]]
for i in range(1, n):
	if a[i - 1] != a[i]:
		cnt += 1
		b.append(a[i])
if cnt != 3 and cnt != 2 and (cnt != 1):
	print('NO')
elif cnt == 1 or cnt == 2:
	print('YES')
elif b[1] - b[0] == b[2] - b[1]:
	print('YES')
else:
	print('NO')


def main():
	input()
	arr = [int(x) for x in input().strip().split()]
	numbers = set()
	for elem in arr:
		numbers.add(elem)
		if len(numbers) > 3:
			return 'NO'
	if len(numbers) < 3:
		return 'YES'
	(a, b, c) = sorted(numbers)
	if a - b == b - c:
		return 'YES'
	return 'NO'
print(main())


import sys
n = int(input())
a = [int(x) for x in input().split()]
aa = list(set(a))
aa.sort()
if len(aa) > 3:
	print('NO')
	return
if len(aa) < 3:
	print('YES')
	return
if (aa[0] + aa[2]) % 2 != 0:
	print('NO')
	return
if 2 * aa[1] == aa[0] + aa[2]:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
s = set(a)
if len(s) > 3:
	print('NO')
else:
	a = list(s)
	a.sort()
	if len(a) == 1:
		print('YES')
		exit()
	if len(a) == 2:
		print('YES')
		exit()
	ans = abs(a[0] - a[1])
	for i in range(1, len(a) - 1):
		if a[i + 1] - a[i] != ans:
			print('NO')
			exit()
	print('YES')


num = int(input())
lst = list(map(int, input().split()))
s = sorted(set(lst))
if len(s) <= 2:
	print('YES')
elif len(s) > 3:
	print('NO')
elif s[0] + s[2] == s[1] * 2:
	print('YES')
else:
	print('NO')


def if_equal(n, l):
	if len(l) > 3:
		return 'NO'
	elif len(l) < 3:
		return 'YES'
	else:
		l.sort()
		if l[1] - l[0] == l[2] - l[1]:
			return 'YES'
		else:
			return 'NO'
n = int(input())
l = list(set(list(map(int, input().split()))))
print(if_equal(n, l))


n = int(input())
l = sorted(set([int(x) for x in input().split()]))
print('YES' if len(l) <= 2 or (l[2] - l[1] == l[1] - l[0] and len(l) == 3) else 'NO')


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
a = Counter(l)
if len(a) < 3:
	print('YES')
elif len(a) > 3:
	print('NO')
else:
	a = sorted(a)
	if a[1] * 2 == a[0] + a[2]:
		print('YES')
	else:
		print('NO')


x = int(input())
lista = list(map(int, input().split()))
s = sorted(set(lista))
if len(s) <= 2 or (len(s) == 3 and s[0] + s[2] == s[1] * 2):
	print('YES')
else:
	print('NO')


n = int(input())
li = list(map(int, input().split()))
s = set(li)
l = len(s)
if l == 3:
	s = list(s)
	s.sort()
	if s[1] - s[0] == s[2] - s[1]:
		print('YES')
	else:
		print('NO')
elif l == 2 or l == 1:
	print('YES')
else:
	print('NO')


(n,) = map(int, input().split())
a = list(map(int, input().split()))
hist = set()
for i in range(n):
	hist.add(a[i])
k = len(hist)
if k <= 2:
	print('YES')
elif k > 3:
	print('NO')
else:
	l = sorted(list(hist))
	if l[2] - l[1] == l[1] - l[0]:
		print('YES')
	else:
		print('NO')


n = input()
m = list(set(map(int, input().split())))
if len(m) < 3:
	print('YES')
elif len(m) > 3:
	print('NO')
elif m[0] + m[2] == m[1] * 2 or m[1] + m[2] == m[0] * 2 or m[1] + m[0] == m[2] * 2:
	print('YES')
else:
	print('NO')


input()
b = sorted(set(map(int, input().split())))
z = set()
a = len(b)
for i in range(1, a):
	z.add(b[i] - b[i - 1])
if len(z) <= 1 and a <= 3:
	print('YES')
else:
	print('NO')


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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def binary_search(lb, ub, val, cnt):
	mid = (lb + ub) // 2
	if val < mid:
		ub = mid - 1
		binary_search(lb, ub, val, cnt - 1)
	elif val > mid:
		lb = mid + 1
		binary_search(lb, ub, val, cnt - 1)
	else:
		print(cnt)

def abs(x):
	return x if x >= 0 else -x
for t in range(1):
	n = int(input())
	nums = list(map(int, input().split()))
	diffs = set()
	for i in range(n):
		diffs.add(nums[i])
	li = list(diffs)
	if len(diffs) <= 2:
		print('YES')
	elif len(diffs) == 3:
		li.sort()
		if li[1] * 2 == li[0] + li[-1]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


n = int(input())
nums = [int(x) for x in input().split()]
maxValue = max(nums)
minValue = min(nums)
ave = (maxValue + minValue) // 2
tmp = [0, 0, 0]
check1 = True
check2 = True
check3 = True
for i in range(n):
	if nums[i] - minValue != 0:
		tmp[0] = nums[i] - minValue
	if abs(nums[i] - maxValue) != 0:
		tmp[1] = abs(nums[i] - maxValue)
	if abs(nums[i] - ave) != 0:
		tmp[2] = abs(nums[i] - ave)
for i in range(n):
	if abs(nums[i] - minValue) != 0 and abs(nums[i] - minValue) != tmp[0]:
		check1 = False
	if abs(nums[i] - maxValue) != 0 and abs(nums[i] - maxValue) != tmp[1]:
		check2 = False
	if abs(nums[i] - ave) != 0 and abs(nums[i] - ave) != tmp[2]:
		check3 = False
if check1 or check2 or check3:
	print('YES')
else:
	print('NO')


n = int(input())
l = list(set([int(x) for x in input().split()]))
l.sort()
print('YES' if len(l) <= 2 else 'YES' if l[2] - l[1] == l[1] - l[0] and len(l) == 3 else 'NO')


read = lambda : list(map(int, input().split()))
n = int(input())
a = list(read())
s = set()
for i in a:
	s.add(i)
f1 = len(s) < 3
f2 = len(s) == 3 and max(s) + min(s) == 2 * sorted(s)[1]
print('YES' if f1 or f2 else 'NO')


nums = set()
input()
t = input().split()
t = (int(x) for x in t)
t = sorted(t)
for x in t:
	nums.add(x)
	if len(nums) > 3:
		print('NO')
		break
else:
	if len(nums) < 3:
		print('YES')
	else:
		nums = sorted(nums)
		print('YES' if nums[2] - nums[1] == nums[1] - nums[0] else 'NO')


n = int(input())
arr = list(map(int, input().split()))
arr = list(set(arr))
arr.sort()
if len(arr) <= 2 or (len(arr) == 3 and arr[1] - arr[0] == arr[2] - arr[1]):
	print('YES')
else:
	print('NO')


from sys import *
n = int(input())
c = [int(z) for z in input().split()]
ee = []
for i in c:
	if i not in ee:
		ee.append(i)
	if len(ee) > 3:
		print('NO')
		exit(0)
ee.sort()
if len(ee) < 3 or ee[0] + ee[2] == 2 * ee[1]:
	print('YES')
else:
	print('NO')


n = int(input())
w = list(set(map(int, input().split())))
w.sort()
if len(w) <= 2:
	print('YES')
elif len(w) == 3 and w[1] - w[0] == w[2] - w[1]:
	print('YES')
else:
	print('NO')


n = int(input())
nums = input().split()
different = []
loop = True
i = 0
count = 0
while loop:
	if i == n or count > 3:
		loop = False
	else:
		if nums[i] not in different:
			different.append(nums[i])
			count += 1
		i += 1
if count > 3:
	print('NO')
elif count < 3:
	print('YES')
else:
	a = int(different[0])
	b = int(different[1])
	c = int(different[2])
	if (max(a, b, c) + min(a, b, c)) / 2 == a + b + c - max(a, b, c) - min(a, b, c):
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
x = set(a)
if len(x) > 3:
	print('NO')
else:
	c = sorted(list(x))
	yes = False
	if len(c) == 3:
		if (c[0] + c[2]) / 2 == c[1]:
			yes = True
	else:
		yes = True
	if yes:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if len(set(a)) > 3:
		print('NO')
		return
	if len(set(a)) <= 2:
		print('YES')
		return
	s = sorted(list(set(a)))
	if s[1] - s[0] == s[2] - s[1]:
		print('YES')
		return
	print('NO')
	return
main()


n = int(input())
arr = list(map(int, input().split()))
mn = min(arr)
mx = max(arr)
diffs = set()
for i in range(n):
	res = abs(arr[i] - mn)
	res1 = abs(arr[i] - mx)
	diffs.add(res)
	diffs.add(res1)
if len(diffs) <= 3:
	print('YES')
else:
	print('NO')


import math
from collections import defaultdict

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

def solve():
	n = int(input())
	a = input_ints()
	a = list(set(a))
	a.sort()
	if len(a) <= 2 or (len(a) == 3 and a[1] - a[0] == a[2] - a[1]):
		print('YES')
	else:
		print('NO')
solve()


answer1 = int(input())
sett1 = sorted(set(map(int, input().split())))
length = len(sett1)
if length < 3 or (length == 3 and sett1[1] - sett1[0] == sett1[2] - sett1[1]):
	print('YES')
else:
	print('NO')


n = int(input())
nums = set(map(int, input().split()))
mid = sum(nums) / len(nums)
ans = 'NO'
for num in nums:
	if num != mid:
		dif = abs(num - mid)
		break
else:
	dif = 0
for num in nums:
	if abs(num - mid) != dif and num != mid:
		break
else:
	ans = 'YES'
if len(nums) <= 2:
	ans = 'YES'
print(ans)


def main(n, a):
	s = set(a)
	if len(s) < 3:
		return True
	if len(s) > 3:
		return False
	mi = min(a)
	ma = max(a)
	diff = (ma - mi) // 2
	for i in range(n):
		if a[i] == mi:
			a[i] += diff
		elif a[i] == ma:
			a[i] -= diff
	return len(set(a)) == 1
print('YES' if main(int(input()), list(map(int, input().split(' ')))) else 'NO')


n = int(input())
nums = list(map(int, input().split()))
setofnums = set()
for i in nums:
	setofnums.add(i)
if len(setofnums) > 3:
	print('NO')
elif len(setofnums) == 3:
	temp = list(setofnums)
	temp.sort()
	if temp[2] - temp[1] == temp[1] - temp[0]:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
a = [int(x) for x in input().split()]
s = set()
for x in a:
	s.add(x)
thelist = list(s)
if len(thelist) == 1 or len(thelist) == 2:
	print('YES')
elif len(thelist) > 3:
	print('NO')
else:
	a = min(thelist)
	c = max(thelist)
	b = sum(thelist) - a - c
	if (a + c) / 2 == b:
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
b = sorted(set(a))
x = list(b)
if len(x) % 2 == 1:
	a = x[len(x) // 2]
else:
	a = x[(len(x) + 1) // 2]
b = a - x[0]
canModify = True
for i in x:
	if i + b != a and i - b != a and (i != a):
		canModify = False
		break
if canModify:
	print('YES')
else:
	print('NO')


from sys import stdin
size = int(input())
lista = list(map(int, stdin.readline().split(' ')))
conocidos = list()
for n in range(size):
	if lista[n] not in conocidos:
		conocidos.append(lista[n])
	if len(conocidos) > 3:
		break
if len(conocidos) < 3:
	print('YES')
elif len(conocidos) > 3:
	print('NO')
else:
	conocidos = sorted(conocidos)
	if (conocidos[-1] + conocidos[0]) / 2 == conocidos[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
array = sorted(list(set(list(map(int, input().split())))))
if len(array) <= 2:
	print('YES')
elif len(array) == 3:
	if array[1] - array[0] == array[2] - array[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
inp = list(map(int, input().split(' ')))
inp = list(set(inp))
if len(inp) <= 2:
	print('YES')
elif len(inp) >= 4:
	print('NO')
else:
	inp.sort()
	if inp[1] * 2 == inp[0] + inp[2]:
		print('YES')
	else:
		print('NO')


n = int(input())
arr1 = list(map(int, input().split()))
if len(set(arr1)) >= 4:
	print('NO')
elif len(set(arr1)) <= 2:
	print('YES')
elif len(set(arr1)) == 3:
	t = sorted(list(set(arr1)))
	if 2 * t[1] == t[0] + t[2]:
		print('YES')
	else:
		print('NO')


num = int(input())
a = [int(n) for n in input().split()]
b = set(a)
c = list(b)
c.sort()
if len(b) > 3:
	print('NO')
elif len(b) < 3:
	print('YES')
elif c[0] + c[2] == 2 * c[1]:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
D = {}
for i in range(n):
	if a[i] in D:
		D[a[i]] += 1
	else:
		D[a[i]] = 1
if len(D) <= 2:
	print('YES')
elif len(D) == 3:
	T = sorted(list(D.keys()))
	if (T[-1] - T[0]) % 2 == 0 and T[0] + (T[-1] - T[0]) // 2 == T[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
l = set(l)
if len(l) > 3:
	print('NO')
else:
	l = list(sorted(l))
	if l[len(l) // 2] - min(l) == max(l) - l[len(l) // 2] and len(l) == 3:
		print('YES')
	elif len(l) == 2 or len(l) == 1:
		print('YES')
	else:
		print('NO')


import sys, math
n = int(input())
z = list(map(int, input().split()))
a = max(z)
b = min(z)
y = (a + b) // 2
x1 = a - y
x2 = a - b
flag = [0, 0, 0]
for i in range(n):
	if z[i] == y:
		flag[0] += 1
	else:
		if z[i] < y and z[i] + x1 == y:
			flag[0] += 1
		elif z[i] - x1 == y:
			flag[0] += 1
		if z[i] + x2 == a or z[i] == a:
			flag[1] += 1
		if z[i] - x2 == b or z[i] == b:
			flag[2] += 1
if flag.count(n) >= 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
r = set(a)
if len(r) <= 3:
	r = list(r)
	r.sort()
	if len(r) == 1 or len(r) == 2 or r[1] - r[0] == r[2] - r[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
q = set()
for x in a:
	if x not in q:
		q.add(x)
if len(q) > 3:
	print('NO')
elif len(q) < 3:
	print('YES')
else:
	(x, y, z) = q
	for it in range(3):
		if x > y:
			tmp = x
			x = y
			y = tmp
		if y > z:
			tmp = y
			y = z
			z = tmp
	if y - x == z - y:
		print('YES')
	else:
		print('NO')


t = int(input())
dum = set(map(int, input().split()))
if len(dum) < 3:
	print('YES')
elif len(dum) == 3:
	num = sorted(list(dum))
	if num[2] - num[1] == num[1] - num[0]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import sys

def readnlines(f_in):
	n = int(f_in.readline().strip())
	s = set()
	content = f_in.readline().strip()
	for (i, line) in zip(range(n), content.split(' ')):
		if line.isdigit():
			s.add(int(line))
		else:
			s.add(line)
	return s

def print_args():
	print('Recieved {} arguments = {}.'.format(len(sys.argv), sys.argv))

def intersect(l1, r1, l2, r2):
	left = max(l1, l2)
	right = min(r1, r2)
	return (left, right, max(0, right - left + 1))

def solve():
	m = readnlines(sys.stdin)
	uniques = sorted(m)
	if len(uniques) > 3:
		return 'NO'
	elif len(uniques) == 3:
		if uniques[2] + uniques[0] == 2 * uniques[1]:
			return 'YES'
		return 'NO'
	else:
		return 'YES'
ans = solve()
print(ans)


n = int(input())
l = [int(i) for i in input().split(' ')]
l = sorted(list(set(l)))
ans = 'NO'
if len(l) == 3:
	if l[1] - l[0] == l[2] - l[1]:
		ans = 'YES'
elif len(l) < 3:
	ans = 'YES'
print(ans)


def solve():
	input()
	a = map(int, input().split())
	nums = set()
	for n in a:
		nums.add(n)
	if len(nums) <= 2:
		print('YES')
		return
	if len(nums) == 3:
		ma = max(nums)
		mi = min(nums)
		nums.remove(ma)
		nums.remove(mi)
		mid = nums.pop()
		if ma - mid == mid - mi:
			print('YES')
			return
	print('NO')

def main():
	solve()
main()


n = int(input())
arr = [int(x) for x in input().split()]
trr = []
for x in arr:
	if trr.count(x) == 0:
		trr.append(x)
	if len(trr) > 3:
		print('NO')
		exit()
		break
trr.sort()
if len(trr) == 1:
	print('YES')
elif len(trr) == 3:
	if trr[0] + trr[2] == trr[1] * 2:
		print('YES')
	else:
		print('NO')
elif len(trr) == 2:
	print('YES')
else:
	print('NO')


n = int(input())
a = set(map(int, input().split()))
if len(a) < 3:
	print('YES')
elif len(a) > 3:
	print('NO')
else:
	aa = list(a)
	aa.sort()
	if 2 * aa[1] == aa[0] + aa[2]:
		print('YES')
	else:
		print('NO')


from sys import stdin

def main():
	(x,) = stdin_get_ints_from_line()
	a = stdin_get_ints_list_from_line()
	minn = min(a)
	maxx = max(a)
	mid = (maxx + minn) / 2
	for n in a:
		if n not in (minn, maxx, mid):
			return 'NO'
	return 'YES'

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()
print(main())


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
frq = {}
csnt = {}
frq[arr[0]] = 1
for i in range(1, len(arr)):
	if arr[i] in frq:
		frq[arr[i]] += 1
	else:
		frq[arr[i]] = 1
	if arr[i] - arr[i - 1] in csnt:
		csnt[arr[i] - arr[i - 1]] += 1
	elif arr[i] - arr[i - 1] > 0:
		csnt[arr[i] - arr[i - 1]] = 1
print('YES' if len(frq) < 4 and len(csnt) < 2 else 'NO')


n = int(input())
a = list(map(int, input().split()))
s = set(a)
if len(s) > 3:
	print('NO')
	exit()
if len(s) < 3:
	print('YES')
	exit()
m = min(s)
M = max(s)
mid = sum(s) - M - m
if M - mid == mid - m:
	print('YES')
else:
	print('NO')


n = int(input())
list1 = list(map(int, input().strip().split(' ')))
list2 = []
for i in range(n):
	if list1[i] not in list2:
		list2.append(list1[i])
	if len(list2) > 3:
		break
if len(list2) != 3:
	if len(list2) == 2 or len(list2) == 1:
		print('YES')
	else:
		print('NO')
else:
	list2.sort()
	if (list2[2] + list2[0]) / 2 == list2[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
s = set()
L = [int(x) for x in input().split()]
for i in L:
	s.add(i)
if len(s) > 3:
	print('NO')
elif len(s) == 1 or len(s) == 2:
	print('YES')
else:
	L = []
	for i in s:
		L.append(i)
	L.sort()
	(a, b, c) = (L[0], L[1], L[2])
	if b - a == c - b:
		print('YES')
	else:
		print('NO')


n = int(input())
a = [int(x) for x in input().split()]
b = set(a)
b = sorted(b)
l = len(b)
if l == 3:
	m = b[1]
	if m - b[0] == b[2] - m:
		print('YES')
	else:
		print('NO')
elif l < 3:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
a = [int(i) for i in input().split()]
tek = []
tek.append(a[0])
for i in range(1, n):
	x = len(tek)
	if x == 1:
		if a[i] != tek[0]:
			tek.append(a[i])
	elif x == 2:
		if (a[i] != tek[0]) & (a[i] != tek[1]):
			tek.append(a[i])
	elif x == 3:
		if (a[i] != tek[0]) & (a[i] != tek[1]) & (a[i] != tek[2]):
			print('NO')
			sys.exit()
tek.sort()
summ = 0
if len(tek) == 3:
	if tek[1] - tek[0] == tek[2] - tek[1]:
		print('YES')
		sys.exit()
elif len(tek) == 2:
	print('YES')
	sys.exit()
if len(tek) == 1:
	print('YES')
	sys.exit()
print('NO')


n = int(input())
s = set(map(int, input().split()))
if len(s) <= 2:
	print('YES')
else:
	l = list(s)
	c = True
	p = abs(l[0] - l[1])
	for x in range(0, len(l)):
		c = True
		for y in range(0, len(l)):
			if x == y:
				continue
			if abs(l[x] - l[y]) != p:
				if x != len(l) - 1:
					p = abs(l[x + 1] - l[x])
				c = False
				break
		if c:
			print('YES')
			break
	if not c:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
dic = {}
for x in a:
	if x in dic:
		dic[x] += 1
	else:
		dic[x] = 1
l = len(dic)
if l <= 2:
	print('YES')
	exit(0)
elif l == 3:
	b = []
	for (x, y) in dic.items():
		b.append(x)
	b.sort()
	if b[0] - b[1] == b[1] - b[2]:
		print('YES')
		exit(0)
print('NO')
exit(0)


n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)))
print(('NO', 'YES')[len(b) == 3 and b[2] - b[1] == b[1] - b[0] or len(b) <= 2])


n = int(input())
arr = sorted(list(set(list(map(int, input().split())))))
flag = True
if len(arr) == 1 or len(arr) == 2:
	print('YES')
elif len(arr) == 3:
	if arr[1] - arr[0] == arr[2] - arr[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


from itertools import combinations
n = input()
nums = {int(s) for s in input().split()}
res = set()
if len(nums) > 3:
	print('NO')
else:
	for (a, b) in combinations(nums, 2):
		res.add(abs(a - b))
	if len(res) <= 2:
		print('YES')
	else:
		print('NO')


n = int(input())
A = set(map(int, input().split()))
if len(A) < 3:
	print('YES')
elif len(A) > 3:
	print('NO')
else:
	B = list(A)
	B.sort()
	if 2 * B[1] == B[0] + B[2]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
se = set()
for i in range(n):
	if len(se) <= 3:
		se.add(arr[i])
if len(se) <= 2:
	print('YES')
elif len(se) == 3:
	arr = list(se)
	arr = sorted(arr)
	if abs(arr[0] - arr[1]) == abs(arr[1] - arr[2]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
dis = []
for i in a:
	if i not in dis:
		dis.append(i)
		if len(dis) > 3:
			print('NO')
			exit()
if len(dis) == 2 or len(dis) == 1:
	print('YES')
else:
	dis.sort()
	if abs(dis[0] - dis[1]) == abs(dis[2] - dis[1]):
		print('YES')
	else:
		print('NO')


from math import ceil
n = int(input())
arr = [int(i) for i in input().strip().split()]
arr.sort()
k = (arr[-1] - arr[0]) / 2
p = (arr[-1] + arr[0]) / 2
b = True
for i in arr:
	if i == p or i + k == p or i - k == p:
		continue
	b = False
if b:
	print('YES')
else:
	print('NO')


a = sorted({*map(int, [*open(0)][1].split())})
print('YNEOS'[len(a) == 3 and a[1] - a[0] != a[2] - a[1] or len(a) > 3::2])


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
n = ii()
l = sorted(list(set(il())))
sz = len(l)
if sz < 4:
	if sz == 3 and 2 * l[1] == l[0] + l[2] or sz == 1 or sz == 2:
		exit(print('YES'))
print('NO')


n = int(input())
l = input().split()
f = []
c = 0
for i in l:
	if not i in f:
		if c == 3:
			print('NO')
			quit()
		else:
			c += 1
			f.append(i)
if len(f) < 3:
	print('YES')
	quit()
f = list(map(lambda x: int(x), f))
f.sort()
if f[0] - f[1] == f[1] - f[2]:
	print('YES')
else:
	print('NO')


n = int(input())
a = map(int, input().split())
b = set(a)
if len(b) <= 2:
	print('YES')
elif len(b) > 3:
	print('NO')
else:
	a = []
	for i in b:
		a.append(i)
	a.sort()
	if a[1] - a[0] == a[2] - a[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
a = [int(x) for x in input().split()]
mi = min(a)
mx = max(a)
delta = (mx - mi) / 2
flag = 0
for i in range(len(a)):
	if a[i] < mi + delta:
		a[i] += delta
	if a[i] > mi + delta:
		a[i] -= delta
	if a[i] != mi + delta:
		flag = 1
if flag:
	print('No')
else:
	print('Yes')


n = int(input())
l = list(map(int, input().split()))
l1 = set(l)
l1 = sorted(l1)
if len(l1) <= 2:
	print('YES')
elif len(l1) == 3 and abs(l1[0] - l1[1]) == abs(l1[1] - l1[2]):
	print('YES')
else:
	print('NO')


n = input()
x = list(map(int, input().split()))
a = []
flag = True
for i in x:
	if i not in a:
		a += [i]
	if len(a) > 3:
		flag = False
		break
if flag:
	a.sort()
	if len(a) == 1 or len(a) == 2:
		print('YES')
	elif a[1] - a[0] == a[2] - a[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	if not a[i] in l:
		l.append(a[i])
	if len(l) > 3:
		print('NO')
		raise SystemExit
if len(l) == 3 and sum(l) / 3 in l or len(l) < 3:
	print('YES')
else:
	print('NO')


N = int(input())
X = sorted(list(set(list(map(int, input().split())))))
if len(X) > 3:
	print('NO')
	exit()
print('YES' if len(X) <= 2 or X[1] - X[0] == X[2] - X[1] else 'NO')


k = int(input())
s = [int(i) for i in input().split()]
a = -1
b = -1
c = -1
ans = '1'
for i in range(len(s)):
	if a < 0:
		a = s[i]
	if s[i] != a:
		if b < 0:
			b = s[i]
	if s[i] != a:
		if s[i] != b:
			if c < 0:
				c = s[i]
	if s[i] != a:
		if s[i] != b:
			if s[i] != c:
				ans = '2'
				print('NO')
				break
r1 = abs(a - b)
r2 = abs(a - c)
r3 = abs(b - c)
if r1 == r2:
	if ans == '1':
		print('YES')
elif r1 == r3:
	if ans == '1':
		print('YES')
elif r2 == r3:
	if ans == '1':
		print('YES')
elif c == -1:
	if ans == '1':
		print('YES')
elif ans == '1':
	print('NO')


n = int(input())
a = list(map(int, input().split()))
a = sorted(list(set(a)))
n = len(a)
if len(a) <= 2:
	print('YES')
	exit()
if len(a) % 2 != 0:
	d = set()
	for i in range(len(a)):
		if i != n // 2:
			d.add(abs(a[n // 2] - a[i]))
	if len(d) == 1:
		print('YES')
	else:
		print('NO')
elif a[n // 2] != a[n // 2 + 1]:
	print('NO')
else:
	for i in range(len(a)):
		if i != n // 2 and i != n // 2 + 1:
			d.add(abs(a[n // 2] - a[i]))
	if len(d) == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
s = set()
for el in a:
	s.add(el)
	if len(s) > 3:
		break
if len(s) <= 2:
	print('YES')
elif len(s) > 3:
	print('NO')
else:
	sl = sorted(list(s))
	print('YES' if sl[0] + sl[2] == 2 * sl[1] else 'NO')


n = int(input())
a = map(int, input().split())
vals = set()
for i in a:
	vals.add(i)
	if len(vals) > 3:
		break
if len(vals) < 3:
	print('YES')
elif len(vals) == 3:
	sorted_vals = list(vals)
	sorted_vals.sort()
	if sorted_vals[0] + sorted_vals[2] == sorted_vals[1] * 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
s = sorted(map(int, input().split()))
d = sorted(set(s))
if len(d) <= 2:
	print('YES')
	exit(0)
if len(d) > 3:
	print('NO')
	exit(0)
if d[2] - d[1] == d[1] - d[0]:
	print('YES')
else:
	print('NO')


n = int(input())
s = input().split(' ')
a = []
for i in range(n):
	a.append(int(s[i]))
a.sort()
current = a[0]
k = 1
sum = a[0]
for i in range(n):
	if current != a[i]:
		k += 1
		sum += a[i]
		current = a[i]
ans = True
if k != 2:
	if sum % k == 0:
		avg = sum / k
		delta = abs(avg - a[0])
		for i in range(n):
			if a[i] != avg:
				if delta != abs(avg - a[i]):
					ans = False
	else:
		ans = False
else:
	ans = True
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
a = input().split()
b = list(set(a))
if len(b) > 3:
	print('NO')
elif len(b) < 3:
	print('YES')
elif (abs(int(b[0]) - int(b[1])) == abs(int(b[1]) - int(b[2]))) | (abs(int(b[2]) - int(b[1])) == abs(int(b[0]) - int(b[2]))) | (abs(int(b[0]) - int(b[1])) == abs(int(b[0]) - int(b[2]))):
	print('YES')
else:
	print('NO')


n = int(input())
arr = list(map(int, input().split()))
a = set()
for i in arr:
	a.add(i)
if len(a) == 1 or len(a) == 2:
	print('YES')
elif len(a) == 3:
	a = list(a)
	a.sort()
	if 2 * a[1] == a[0] + a[2]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


from sys import exit
n = int(input())
data = [int(x) for x in input().split()]
data.sort()
if n <= 2:
	print('YES')
else:
	dif = abs(data[0] - data[len(data) - 1])
	example = data[0] + dif
	flag = True
	for i in range(1, n):
		if data[i] + dif != example and data[i] != example:
			flag = False
			break
	if not flag:
		dif = int(dif / 2)
		example = data[0] + dif
		for i in range(1, n):
			if data[i] + dif != example and data[i] != example and (data[i] - dif != example):
				print('NO')
				exit()
		print('YES')
		exit()
	print('YES')


n = int(input())
A = list(map(int, input().split()))
d = set(A)
if len(d) > 3:
	print('NO')
else:
	D = list(d)
	D.sort()
	if len(d) == 3:
		if D[1] - D[0] != D[2] - D[1]:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


n = int(input())
a = [int(i) for i in input().split()]
x = a[0]
y = -1
z = -1
w = -1
j = 0
f = 0
for i in range(1, n):
	if x != a[i]:
		y = a[i]
		j = i
		break
for i in range(j, n):
	if x != a[i] and y != a[i]:
		z = a[i]
		f = i
		break
for i in range(f, n):
	if x != a[i] and y != a[i] and (z != a[i]):
		w = a[i]
		break
s = 0
if z == -1:
	s = 1
if w != -1:
	s = -1
if z != -1 and w == -1:
	mx = max(z, y, x)
	mn = min(z, y, x)
	md = z + y + x - mx - mn
	if mx - md == md - mn:
		s = 2
print(['NO', 'YES'][s > 0])


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) <= 3:
	if len(set(a)) == 3:
		if (max(a) + min(a)) % 2 == 0 and (max(a) + min(a)) // 2 in a:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
else:
	print('NO')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = set(array())
if len(a) < 3:
	print('YES')
elif len(a) == 3:
	(a, b, c) = sorted(a)
	if b - a == c - b:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
s = set()
for i in l:
	s.add(i)
l = list(s)
l.sort()
if len(l) > 3:
	print('NO')
if len(l) == 3:
	if (l[0] + l[2]) / 2 == l[1]:
		print('YES')
	else:
		print('NO')
if len(l) <= 2:
	print('YES')


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(set(list(map(int, input().split(' ')))))
	n = len(a)
	a.sort()
	if n == 1 or n == 2:
		print('YES')
	elif n == 3:
		if a[1] - a[0] == a[2] - a[1]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
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')
main()


n = int(input())
s = set(map(int, input().split()))
if len(s) > 3:
	print('NO')
elif len(s) < 3:
	print('YES')
else:
	l = sorted(list(s))
	t = set()
	ans = 'YES'
	for i in range(1, len(l)):
		if i == 0:
			t.add(l[i])
		else:
			t.add(l[i] - l[i - 1])
		if len(t) > 1:
			ans = 'NO'
			break
	print(ans)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = sorted(list(set(iia())))
if len(arr) <= 2:
	print('YES')
elif len(arr) == 3 and arr[1] - arr[0] == arr[2] - arr[1]:
	print('YES')
else:
	print('NO')


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) > 3:
		return 'NO'
	if len(c) < 3:
		return 'YES'
	k = sorted(c.keys())
	if k[1] - k[0] == k[2] - k[1]:
		return 'YES'
	return 'NO'
print(main())


r = lambda : int(input())
ra = lambda : [*map(int, input().split())]
p = lambda a: print('{:.6f}'.format(a))
n = r()
a = ra()
d = sorted(list(set(a)))
if len(set(a)) == 1:
	print('YES')
elif len(set(a)) > 3:
	print('NO')
elif len(set(a)) == 2:
	print('YES')
elif (max(d) + min(d)) / 2 == float(d[len(d) // 2]):
	print('YES')
else:
	print('NO')


def check(arr, n):
	distinct = 1
	ptr = arr[0]
	diff = [arr[0]]
	for i in range(1, n):
		if ptr == arr[i]:
			continue
		distinct += 1
		ptr = arr[i]
		diff.append(ptr)
	if distinct == 1:
		return 'YES'
	elif distinct == 2:
		return 'YES'
	elif distinct == 3:
		if 2 * diff[1] == diff[0] + diff[2]:
			return 'YES'
	return 'NO'
n = int(input())
arr = sorted(list(map(int, input().split())))
print(check(arr, n))


import math
n = int(input())
a = set(map(int, input().split()))
ans = 'NO'
if len(a) <= 2:
	ans = 'YES'
elif len(a) % 2 != 0:
	a = list(a)
	a.sort()
	mid = len(a) // 2
	x = abs(a[mid] - a[0])
	x2 = abs(a[mid] - a[0])
	for i in range(len(a)):
		if i != mid:
			x2 = abs(a[mid] - a[i])
		if x != x2:
			break
		if i < mid:
			a[i] += abs(a[mid] - a[i])
		elif i > mid:
			a[i] -= abs(a[i] - a[mid])
	a = set(a)
	if len(a) == 1:
		ans = 'YES'
print(ans)


n = int(input())
string = input()
numbers = sorted(set(map(int, string.split())))
results = 'NO'
if len(numbers) < 3:
	results = 'YES'
elif len(numbers) == 3 and numbers[2] - numbers[1] == numbers[1] - numbers[0]:
	results = 'YES'
print(results)


n = int(input())
a = [int(i) for i in input().split()]
p = set([])
for i in a:
	p.add(i)
z = len(p)
if z > 3:
	print('NO')
elif z < 3:
	print('YES')
elif (max(p) + min(p)) / 2 in p:
	print('YES')
else:
	print('NO')


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

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

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
n = int(input())
li = set(get_list())
sz = len(li)
if sz < 3:
	print('YES')
elif sz == 3:
	li = sorted(list(li))
	if li[1] - li[0] == li[2] - li[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = []
bb = True
for i in range(n):
	if a[i] not in b:
		b.append(a[i])
	if len(b) > 3:
		bb = False
		break
if bb:
	x = len(b)
	if x == 1 or x == 2:
		print('YES')
	else:
		(m, n, k) = (min(b), sum(b) - max(b) - min(b), max(b))
		if (m + k) / 2 == n:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
ma = min(a)
a = [(i - ma) * 2 for i in a]
print('YES' if sum([a.count(i) for i in set([0, max(a) // 2, max(a)])]) == len(a) else 'NO')


input()
l = list(map(int, input().split()))
maxx = max(l)
minn = min(l)
m = l.count(maxx) + l.count(minn) + l.count((maxx + minn) / 2)
if (maxx + minn) % 2 == 0 and len(l) == m:
	print('YES')
elif l.count(maxx) + l.count(minn) == len(l):
	print('YES')
elif minn == maxx:
	print('YES')
else:
	print('NO')


n = input()
t = input().split()
t = [int(x) for x in t]
t = list(set(t))
t.sort()
if len(t) == 3:
	if t[1] - t[0] == abs(t[2] - t[1]):
		print('YES')
	else:
		print('NO')
elif len(t) <= 2:
	print('YES')
else:
	print('NO')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	for i in a:
		s.add(i)
	if len(s) > 3:
		print('NO')
	elif len(s) <= 2:
		print('YES')
	else:
		a = s.pop()
		b = s.pop()
		c = s.pop()
		if 2 * a == b + c or 2 * b == a + c or 2 * c == b + a:
			print('YES')
		else:
			print('NO')
solve()


n = int(input())
a = [int(s) for s in input().split()]
c = set()
for v in a:
	c.add(v)
if len(c) <= 2:
	print('YES')
elif len(c) > 3:
	print('NO')
else:
	e = list(c)
	e.sort()
	if abs(e[2] - e[1]) == abs(e[0] - e[1]):
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
count = 0
a_distinct = [None] * 3
for i in a:
	if i not in a_distinct:
		if count == 3:
			print('NO')
			exit()
		a_distinct[count] = i
		count += 1
if count < 3:
	print('YES')
	exit()
sum = a_distinct[0] + a_distinct[1] + a_distinct[2]
if sum % 3 != 0:
	print('NO')
	exit()
avg = sum // 3
if avg == a_distinct[0] or avg == a_distinct[1] or avg == a_distinct[2]:
	print('YES')
	exit()
print('NO')


x = int(input())
un = sorted(set(map(int, input().split())))
if len(un) == 3:
	if abs(un[0] - un[1]) == abs(un[1] - un[2]):
		print('YES')
	else:
		print('NO')
elif len(un) < 3:
	print('YES')
else:
	print('NO')


n = int(input())
A = [int(a) for a in input().split()]
m = max(A)
D = [0] * n
for i in range(n):
	D[i] = m - A[i]
flag = False
D = set(D)
l = len(D)
if l <= 2:
	flag = True
elif l == 3:
	D = list(D)
	D.sort()
	(a, b, c) = (D[0], D[1], D[2])
	flag = D[0] + D[2] == 2 * D[1]
print('YES' if flag else 'NO')


n = int(input())
s = input().split()
for i in range(0, n):
	s[i] = int(s[i])
num = 0
a = []
ans = 'YES'
for x in s:
	if x not in a:
		a.append(x)
		num += 1
		if num >= 4:
			ans = 'NO'
			break
if len(a) <= 2:
	ans = 'YES'
elif len(a) == 3:
	if a[0] + a[1] == 2 * a[2] or a[1] + a[2] == 2 * a[0] or a[2] + a[0] == 2 * a[1]:
		ans = 'YES'
	else:
		ans = 'NO'
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = [0] * 4
k = 0
A.sort()
B[0] = A[0]
for i in range(1, n):
	if A[i] > A[i - 1]:
		k += 1
		B[k] = A[i]
		if k > 2:
			print('NO')
			break
if k == 0 or k == 1:
	print('YES')
elif k == 2:
	if B[1] - B[0] == B[2] - B[1]:
		print('YES')
	else:
		print('NO')


import sys
n = int(input())
arr = sorted(list(map(int, input().split())))
if len(set(arr)) <= 2:
	print('YES')
elif len(set(arr)) >= 4:
	print('NO')
else:
	arr2 = sorted(list(set(arr)))
	if arr2[1] - arr2[0] == arr2[2] - arr2[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
l = list(map(int, input().split()))
s = set(l)
if len(s) > 3:
	print('NO')
	exit(0)
d = list(s)
d.sort()
if len(d) <= 2:
	print('YES')
elif len(d) == 3:
	if d[1] - d[0] == d[2] - d[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
L = list(map(int, input().split()))
e = set()
for x in L:
	e.add(x)
if len(e) > 3:
	print('NO')
elif len(e) == 3:
	A = sorted(e)
	if abs(A[1] - A[0]) == abs(A[2] - A[1]):
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
lis = [int(x) for x in input().split()]
k = set(lis)
temp = list(k)
temp.sort()
if len(temp) <= 2:
	print('YES')
elif len(temp) == 3:
	if temp[0] + temp[2] == 2 * temp[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
arr = [int(x) for x in input().split()]
ls = []
for i in range(n):
	if len(ls) >= 4:
		break
	elif arr[i] in ls:
		continue
	else:
		ls.append(arr[i])
if len(ls) < 4:
	if len(ls) == 1 or len(ls) == 2:
		print('YES')
	else:
		ls.sort()
		(a, b, c) = (ls[0], ls[1], ls[2])
		if b - a == c - b:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


temp = input()
temp = input().split()
arr = [int(k) for k in temp]
s = sorted(list(set(arr)))
if len(s) > 3:
	print('NO')
elif len(s) < 3:
	print('YES')
elif s[2] + s[0] == 2 * s[1]:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
s = list(set(a))
if len(s) == 3 and sum(s) % 3 == 0 and (sum(s) / 3 in s) or len(s) < 3:
	print('YES')
else:
	print('NO')


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
reline = list(set(line))
size = len(reline)
reline.sort()
if size < 3:
	print('YES')
elif size == 3:
	if reline[2] + reline[0] == 2 * reline[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import sys
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr2 = []
a = 0
b = -1
for i in range(n):
	a = arr[i]
	if a != b:
		arr2.append(a)
	b = arr[i]
m = len(arr2)
if m < 3:
	print('YES')
elif m == 3:
	for i in range(len(arr2)):
		if arr2[i + 1] - arr2[i] == arr2[i + 2] - arr2[i + 1]:
			print('YES')
		else:
			print('NO')
		break
else:
	print('NO')


def filya_and_homework():
	no_elements = int(input())
	elements = set([int(x) for x in input().split(' ')])
	if len(elements) >= 4:
		print('NO')
	elif len(elements) == 1 or len(elements) == 2:
		print('YES')
	else:
		elements = sorted(list(elements))
		if 2 * elements[1] == elements[0] + elements[2]:
			print('YES')
		else:
			print('NO')
filya_and_homework()


n = int(input())
l = list(map(int, input().split()))
minx = min(l)
maxn = max(l)
f = abs(maxn - minx) // 2
ok1 = True
ok2 = True
ok3 = True
f1 = maxn - minx
for i in l:
	if i + f != maxn - f:
		if i - f != maxn - f:
			if i != maxn - f:
				ok1 = False
	if i - f1 != minx:
		if i != minx:
			ok2 = False
	if i + f1 != maxn:
		if i != maxn:
			ok3 = False
if ok1 or ok2 or ok3:
	print('YES')
else:
	print('NO')


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('NO')
	else:
		print('YES')
else:
	for item in a:
		if not (item == maxi or item == mini):
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
a = [int(x) for x in input().split()]
min_a = min(a)
max_a = max(a)
if len(set(a)) <= 2:
	print('YES')
elif (max_a - min_a) % 2:
	print('NO')
else:
	ok = True
	x = (max_a - min_a) // 2
	mid = min_a + x
	for num in a:
		if num == mid:
			continue
		elif num < mid and num + x != mid or (num > mid and num - x != mid):
			ok = False
			break
	print('YES' if ok else 'NO')


def ispossible(numbers):
	lst = sorted(list(numbers))
	if lst[1] - lst[0] == lst[2] - lst[1]:
		return True
	else:
		return False
c = int(input())
lst = [int(i) for i in input().split()]
numbers = set()
for i in lst:
	numbers.add(i)
if len(numbers) <= 2:
	print('YES')
elif len(numbers) == 3 and ispossible(numbers):
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
c = set(a)
if len(c) > 3:
	print('no')
elif len(c) == 2 or len(c) == 1:
	print('yes')
else:
	l = list(c)
	d = max(l)
	l.remove(d)
	if max(l) - min(l) == d - max(l):
		print('yes')
	else:
		print('no')


a = int(input())
b = list(set(map(int, input().split())))
b.sort()
if len(b) <= 2:
	print('yes')
elif b[2] - b[1] == b[1] - b[0] and len(b) == 3:
	print('yes')
else:
	print('no')


n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in range(n):
	if d.get(a[i]) == None:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
b = [x for x in d.keys()]
b.sort()
if len(d.keys()) > 3:
	print('NO')
elif len(d.keys()) == 3:
	if b[0] + b[2] == 2 * b[1]:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


from collections import defaultdict
import sys, os, math

def __starting_point():
	n = int(input())
	arr = list(map(int, input().split()))
	temp = []
	for num in arr:
		if num not in temp:
			temp.append(num)
		if len(temp) > 3:
			print('NO')
			return
	temp.sort()
	if len(temp) < 3 or temp[0] + temp[2] == 2 * temp[1]:
		print('YES')
	else:
		print('NO')
__starting_point()


n = int(input())
a = list(map(int, input().split()))
st = sorted(set(a))
l = []
if len(list(st)) == 2 or len(list(st)) == 1:
	print('YES')
	exit()
elif len(list(st)) > 3:
	print('NO')
	exit()
else:
	for i in st:
		l.append(i)
	if abs(l[0] - l[1]) == abs(l[1] - l[2]):
		print('YES')
	else:
		print('NO')
		exit()


n = int(input())
s = set(map(int, input().split()))
if len(s) <= 3:
	if len(s) <= 2:
		print('YES')
	else:
		L = []
		for each in s:
			L.append(each)
		L.sort()
		if (L[0] + L[2]) // 2 == L[1] and (L[0] + L[2]) % 2 == 0:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


def main():
	input()
	l = sorted(set(map(int, input().split())))
	print(('NO', 'YES')[len(l) < 3 or (len(l) == 3 and sum(l) == l[1] * 3)])
main()


n = int(input())
line = input()
numbers = line.split()
distinct = []
for num in numbers:
	num = int(num)
	if num not in distinct:
		distinct.append(num)
	if len(distinct) >= 4:
		print('NO')
		break
if len(distinct) == 2:
	print('YES')
elif len(distinct) == 3:
	distinct.sort()
	if distinct[1] * 2 == distinct[0] + distinct[2]:
		print('YES')
	else:
		print('NO')
elif len(distinct) == 1:
	print('YES')


n = int(input())
m = list(set(map(int, input().split())))
lens = len(m)
if lens <= 3:
	if lens == 3:
		m.sort()
		if m[1] - m[0] == m[2] - m[1]:
			print('YES')
		else:
			print('NO')
		exit()
	print('YES')
else:
	print('NO')


from sys import stdin
n = int(stdin.readline())
numbers = set((int(x) for x in stdin.readline().split()))
if len(numbers) > 3:
	print('NO')
elif len(numbers) < 3:
	print('YES')
else:
	s = sorted(numbers)
	if s[2] - s[1] == s[1] - s[0]:
		print('YES')
	else:
		print('NO')


def arr_inp():
	return [int(x) for x in input().split()]
(n, a) = (int(input()), arr_inp())
a_dis = sorted(list(set(a)))
sz = len(a_dis)
exp = sz == 3 and a_dis[2] - a_dis[1] == a_dis[1] - a_dis[0] or sz < 3
if exp:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
	s.add(i)
if len(s) == 1 or len(s) == 2:
	print('YES')
elif len(s) == 3:
	for i in s:
		if i != max(s) and i != min(s):
			num = i
	if max(s) + min(s) == 2 * num:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = map(int, input().split())
b = set(a)
if len(b) >= 4:
	print('NO')
else:
	x = list(b)
	x.sort()
	if len(x) == 1:
		print('YES')
	elif len(x) == 2:
		print('YES')
	elif x[1] * 2 == x[0] + x[2]:
		print('YES')
	else:
		print('NO')


n = int(input())
l = list(map(int, input().split()))
l1 = list(set(l))
l1.sort()
if len(l1) == 1 or len(l1) == 2:
	print('YES')
elif len(l1) == 3:
	if abs(l1[0] - l1[1]) == abs(l1[1] - l1[2]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
s = list(set(l))
s.sort()
if len(s) > 3:
	print('NO')
elif len(s) == 3:
	a = s[0]
	b = s[1]
	c = s[2]
	if abs(a - b) == abs(b - c):
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
a = sorted(list(set(list(map(int, input().split())))))
n = len(a)
if n > 3:
	print('NO')
	exit()
Set = set()
for i in range(1, n):
	Set.add(a[i] - a[i - 1])
print('YES' if len(Set) < 2 else 'NO')


from sys import stdout
n = int(input())
s = [int(i) for i in input().split()]
a = s[0]
b = -1
c = -1
for i in s[1:]:
	if i != a and i != b and (i != c):
		if b < 0:
			b = i
		elif c < 0:
			c = i
		else:
			print('NO')
			break
else:
	if c == -1:
		print('YES')
	else:
		r = (max(a, b, c) - min(a, b, c)) / 2 + min(a, b, c)
		if a == r or b == r or c == r:
			print('YES')
		else:
			print('NO')


n = int(input())
arr = list(map(int, input().split()))
s = set()
for el in arr:
	s.add(el)
if len(s) == 1:
	print('YES')
elif len(s) == 2:
	print('YES')
elif len(s) == 3:
	l = sorted(s)
	print('YES' if l[1] - l[0] == l[2] - l[1] else 'NO')
else:
	print('NO')


N = int(input())
A = sorted(list(set(map(int, input().split()))))
if len(A) <= 2:
	print('YES')
elif len(A) == 3 and A[0] + A[2] == 2 * A[1]:
	print('YES')
else:
	print('NO')


def solution():
	n = int(input())
	if n == 1:
		return True
	x = [float(x) for x in input().split(' ')]
	_min = min(x)
	_max = max(x)
	val = (_max - _min) / 2
	centre = _max - val
	for _x in x:
		if not (_x == centre or _x + val == centre or _x - val == centre):
			return False
	return True
print('YES' if solution() else 'NO')


def solve():
	n = int(input())
	ls = set(map(int, input().split()))
	if len(ls) > 3:
		print('NO')
	elif len(ls) != 3:
		print('YES')
	else:
		ls = list(ls)
		ls.sort()
		diff1 = abs(ls[0] - ls[1])
		diff2 = abs(ls[1] - ls[2])
		if diff1 == diff2:
			print('YES')
		else:
			print('NO')
solve()


a = int(input())
b = list(map(int, input().split()))
c = set(b)
d = sorted(list(c))
if len(c) > 3:
	print('NO')
elif len(c) == 3:
	if d[2] + d[0] == 2 * d[1]:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
A = list(map(int, input().split()))
B = []
l = 0
for i in A:
	if i not in B:
		B.append(i)
		l += 1
	if l > 3:
		print('NO')
		return
B.sort()
if l < 3:
	print('YES')
elif B[0] + B[2] == 2 * B[1]:
	print('YES')
else:
	print('NO')


from math import *
n = int(input())
A = list(map(int, input().split()))
ans = set()
for i in range(n):
	ans.add(A[i])
t = len(ans)
if t == 1:
	print('YES')
elif t == 2:
	print('YES')
elif t == 3:
	per1 = ans.pop()
	per2 = ans.pop()
	per3 = ans.pop()
	s1 = max(per1, per2, per3)
	s3 = min(per1, per2, per3)
	s2 = per1 + per2 + per3 - s1 - s3
	if s1 - s2 == s2 - s3:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

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 Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
C = list(set(A))
if len(C) >= 4:
	Y(0)
else:
	C.sort()
	if len(C) <= 2:
		Y(1)
	elif C[1] - C[0] == C[2] - C[1]:
		Y(1)
	else:
		Y(0)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
n = ii()
a = li()
seta = set(a)
if len(seta) < 3:
	print('YES')
elif len(seta) == 3:
	lsa = sorted(seta)
	if lsa[0] + lsa[2] == 2 * lsa[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = set(map(int, input().split()))
m = 'NO'
if len(a) < 4:
	a = sorted(a)
	if len(a) < 3 or a[1] - a[0] == a[2] - a[1]:
		m = 'YES'
print(m)


def if_equal(n, s):
	return ['NO', 'YES'][len(s) < 3 or (len(s) == 3 and s[0] + s[2] == s[1] * 2)]
n = int(input())
s = sorted(list(set(list(map(int, input().split())))))
print(if_equal(n, s))


n = int(input())
s = sorted(map(int, input().split()))
d = sorted(set(s))
if len(d) <= 2:
	print('Yes')
	exit()
if len(d) > 3:
	print('No')
	exit()
if d[2] - d[1] == d[1] - d[0]:
	print('Yes')
else:
	print('No')


n = int(input())
A = list(map(int, input().split()))
tf = False
ma = max(A)
mi = min(A)
sr = (ma + mi) / 2
for i in A:
	if i == ma or i == mi or i == sr:
		tf = True
	else:
		print('NO')
		exit()
if tf:
	print('YES')


import sys
import math
import bisect
import math
from itertools import accumulate
input = sys.stdin.readline

def inpit():
	return int(input())

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

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

def inpspit():
	return map(int, input().split())
pow = math.pow
fl = math.floor
ceil = math.ceil
dis = math.hypot

def lcm(a):
	return abs(math.prod(a)) // math.gcd(*a)

def cumulativeSum(input):
	return list(accumulate(input))
n = inpit()
lt = inplt()
mn = min(lt)
mx = max(lt)
x = mx - mn
if x % 2 == 0:
	x = int(x / 2)
p = mn + x
for i in lt[1:]:
	if i + x == p or i - x == p or i == p:
		continue
	else:
		print('NO')
		exit()
print('YES')


def run():
	input()
	nums = [int(i) for i in input().split(' ')]
	seen = set()
	unique_nums = [i for i in nums if not (i in seen or seen.add(i))]
	max_num = max(unique_nums)
	min_num = min(unique_nums)
	modifier = max_num - min_num
	modifier = modifier / 2 if modifier % 2 == 0 else modifier
	goal = max_num - modifier
	nums_modified = [i + modifier if i < goal else i - modifier if i > goal else i for i in nums]
	print('NO' if len([num for num in nums_modified if num != goal]) > 0 else 'YES')
run()


n = int(input())
a = set(map(int, input().split()))
if len(a) == 1 or len(a) == 2:
	print('YES')
elif len(a) > 3:
	print('NO')
else:
	(mi, md, mx) = sorted(a)
	print('YES' if md - mi == mx - md else 'NO')


n = int(input())
a = [int(i) for i in input().split()]
d = sorted(set(a))
if len(d) <= 2 or (len(d) == 3 and d[0] + d[2] == 2 * d[1]):
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(s) for s in input().split()]
b = [0] * (n - 1)
c1 = 0
c2 = 0
c3 = 0
k = 0
i = 0
a = sorted(a)
while i != n:
	if k == 0:
		c1 = a[i]
		k = 1
	elif k == 1 and a[i] != c1:
		c2 = a[i]
		k = 2
	elif k == 2 and a[i] != c1 and (a[i] != c2):
		k = 3
		c3 = a[i]
	elif k >= 3:
		if a[i] != c1 and a[i] != c2 and (a[i] != c3):
			print('NO')
			break
	i += 1
else:
	if k == 0 or k == 1 or k == 2:
		print('YES')
	elif c3 - c2 == c2 - c1:
		print('YES')
	else:
		print('NO')


n = int(input())
A = sorted(set(map(int, input().split())))
sz = len(A)
print(['NO', 'YES'][sz < 3 or (sz == 3 and A[0] + A[2] == 2 * A[1])])


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
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 = inp()
a = inlist()
b = set(a)
if len(b) > 3:
	print('NO')
else:
	c = list(b)
	if len(c) < 3:
		print('YES')
	else:
		c = sorted(c)
		if c[1] - c[0] == c[2] - c[1]:
			print('YES')
		else:
			print('NO')


n = input()
s = set(map(int, input().split()))
if len(s) > 3:
	print('NO')
elif len(s) <= 2:
	print('YES')
else:
	l = sorted(list(s))
	mid = 3 // 2
	if abs(l[0] - l[mid]) == abs(l[2] - l[mid]):
		print('YES')
	else:
		print('NO')


input()
al = list(map(int, input().split()))
ans = 0
amin = min(al)
amax = max(al)
sa = set(al)
if len(sa) < 3:
	ans = 1
elif (amin + amax) % 2 == 0:
	sa = set(al)
	sa.remove(amin)
	sa.remove(amax)
	sa.add((amin + amax) // 2)
	if len(sa) == 1:
		ans = 1
print(['NO', 'YES'][ans])


n = input()
x = list(map(int, input().split()))
s = set(x)
if len(s) <= 2:
	print('Yes')
elif len(s) > 3:
	print('No')
else:
	(a, b, c) = sorted(s)
	if b * 2 == a + c:
		print('Yes')
	else:
		print('No')


l = input()
a = [int(x) for x in input().split(' ')]
ma = max(a)
mi = min(a)
f = True
for i in a:
	if i != ma and i != mi and (i != (mi + ma) / 2):
		f = False
if f:
	print('YES')
else:
	print('NO')


I = input
I()
s = sorted(set(map(int, I().split())))
t = len(s)
print(['NO', 'YES'][t < 3 or (t == 3 and s[0] + s[2] == s[1] * 2)])


from collections import Counter
import string
import math
import sys
sys.setrecursionlimit(10 ** 6)

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
n = vary(1)
num = array_int()
num.sort()
r = (num[-1] - num[0]) / 2
z = num[0] + r
for i in range(n):
	if num[i] + r == z or num[i] - r == z or num[i] == z:
		continue
	else:
		print('NO')
		break
else:
	print('YES')


_ = input()
a = [int(x) for x in input().split(' ')]
a_set = set(a)
if len(a_set) > 3:
	print('NO')
elif len(a_set) == 3:
	middle = list(a_set.difference([max(a_set), min(a_set)]))[0]
	if 2 * middle == max(a_set) + min(a_set):
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
data = list(map(int, input().split()))
nums = set(data)
if len(nums) <= 2:
	print('YES')
elif len(nums) == 3:
	tmp = list(sorted(list(nums)))
	if tmp[1] - tmp[0] == tmp[2] - tmp[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = set(map(int, input().split()))
if len(a) <= 2:
	print('YES')
else:
	a = list(a)
	a.sort()
	if len(a) == 3 and abs(a[1] - a[0]) == abs(a[1] - a[2]):
		print('YES')
	else:
		print('NO')


n = input()
f = input().split()
for i in range(len(f)):
	f[i] = int(f[i])
f = list(set(f))
f.sort()
if len(f) == 3:
	if f[1] - f[0] == abs(f[2] - f[1]):
		print('YES')
	else:
		print('NO')
elif len(f) <= 2:
	print('YES')
else:
	print('NO')


_ = input()
distinct_values = set(map(int, input().split()))
if len(distinct_values) == 3:
	(a, b, c) = sorted(list(distinct_values))
	ans = 'YES' if a + c == 2 * b else 'NO'
else:
	ans = 'YES' if len(distinct_values) < 3 else 'NO'
print(ans)


n = int(input())
lst = list(map(int, input().split()))
st = set(lst)
lst = list(st)
lst.sort()
a = False
if len(lst) == 3:
	if lst[2] - lst[1] == lst[1] - lst[0]:
		a = True
if len(lst) == 2 or len(lst) == 1:
	a = True
if a:
	print('YES')
else:
	print('NO')


n = int(input())
lista = list(map(int, input().split()))
lista.sort()
countDiff = 1
diff = []
for i in range(n - 1):
	if lista[i] != lista[i + 1]:
		countDiff += 1
		value = lista[i + 1] - lista[i]
		diff.append(value)
if countDiff < 3:
	print('YES')
elif countDiff > 3:
	print('NO')
elif diff[0] == diff[1]:
	print('YES')
else:
	print('NO')


n = int(input())
ip = list(map(int, input().split()))
count = 0
used = []
for i in ip:
	if i not in used and count < 5:
		used.append(i)
		count += 1
if count <= 2:
	print('YES')
elif count > 3:
	print('NO')
else:
	used = sorted(used)
	if used[1] - used[0] == used[2] - used[1]:
		print('YES')
	else:
		print('NO')


import sys
n = int(input())
numbers = [int(n) for n in input().split()]
assert n == len(numbers)
items = set()
for x in numbers:
	items.add(x)
if len(items) > 3:
	print('NO')
	quit()
if len(items) <= 2:
	print('YES')
	quit()
if len(items) == 3:
	arr = [0, 0, 0]
	id = 0
	for e in items:
		arr[id] = e
		id += 1
	arr.sort()
	if arr[0] - arr[1] == arr[1] - arr[2]:
		print('YES')
	else:
		print('NO')
	quit()
assert True


import sys
n = int(input())
s = set(input().split())
s = [i for i in s]
if len(s) < 3:
	print('YES')
	sys.exit(0)
a = int(s[0])
b = int(s[1])
c = int(s[2])
if len(s) <= 3 and ((a + b) // 2 == c and (a + b) % 2 == 0 or ((a + c) // 2 == b and (a + c) % 2 == 0) or ((b + c) // 2 == a and (b + c) % 2 == 0)):
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
t1 = -1
t2 = -1
t3 = -1
flag = 0
res = 0
for i in a:
	if t1 == -1:
		t1 = i
	elif t1 == i:
		continue
	elif t2 == -1:
		t2 = i
	elif t2 == i:
		continue
	elif t3 == -1:
		t3 = i
	elif t3 == i:
		continue
	else:
		flag = -1
if flag == 0:
	if t2 == -1:
		res = 0
	elif t3 == -1:
		res = abs(t1 - t2)
	else:
		temp = [t1, t2, t3]
		temp.sort()
		if temp[1] != (temp[0] + temp[2]) / 2:
			flag = -1
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
arr = list(map(int, input().split()))
sarr = list(set(arr))
l = len(sarr)
if l > 3:
	print('NO')
else:
	sarr = sorted(sarr)
	if l < 3:
		print('YES')
	elif sarr[1] - sarr[0] == sarr[2] - sarr[1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from bisect import bisect

def solve():
	n = int(input())
	a = set(read_tuple(int))
	if len(a) > 3:
		print('NO')
	elif len(a) <= 2:
		print('YES')
	else:
		(i, j, k) = tuple(sorted(a))
		if j - i == k - j:
			print('YES')
		else:
			print('NO')
solve()


n = int(input())
ar = list(map(int, input().split()))
l = len(set(ar))
if l > 3:
	print('NO')
elif l == 1:
	print('YES')
elif l == 2:
	print('YES')
else:
	k = sorted(list(set(ar)))
	if k[1] - k[0] == k[2] - k[1]:
		print('YES')
	else:
		print('NO')


from sys import stdin
n = int(input())
arr = list(map(int, stdin.readline().split()))
d = {}
for i in arr:
	if i not in d:
		d[i] = i
l = len(d.keys())
if l <= 2:
	print('YES')
elif l > 3:
	print('NO')
else:
	a = []
	for i in d:
		a.append(i)
	a.sort()
	if a[1] - a[0] == a[2] - a[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
l = list(map(int, input().split()))
a = list(set(l))
a.sort()
if len(a) == 3 and (a[2] + a[0]) / 2 == a[1]:
	res = 'YES'
elif len(a) <= 2:
	res = 'YES'
else:
	res = 'NO'
print(res)


n = int(input())
a = set(map(int, input().split()))
if len(a) > 3:
	print('NO')
	exit()
elif len(a) == 1 or len(a) == 2:
	print('YES')
	exit()
b = sorted(a)
if b[1] - b[0] == b[2] - b[1]:
	print('YES')
else:
	print('NO')


n = int(input())
l = input().split()
s = set()
for i in l:
	s.add(int(i))
s = list(s)
qtd = len(s)
s.sort()
s.sort()
if qtd == 3:
	aux = (s[2] - s[0]) // 2
if qtd == 1 or qtd == 2 or (qtd == 3 and s[1] - s[0] == s[2] - s[1]):
	print('YES')
else:
	print('NO')


n = input()
inp = input()
arr = set(map(int, inp.split()))
if len(arr) <= 2:
	print('YES')
	exit()
if len(arr) > 3:
	print('NO')
	exit()
arr = list(arr)
arr.sort()
if abs(arr[0] - arr[1]) == abs(arr[2] - arr[1]):
	print('YES')
else:
	print('NO')


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())))
l1 = len(l)
if l1 in [1, 2]:
	print('YES')
elif l1 > 3:
	print('NO')
else:
	print('YNEOS'[l[2] - l[1] != l[1] - l[0]::2])


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
(t1, n) = (sum(set(a)), len(set(a)))

def fn(a, t1):
	if len(set(a)) < 3:
		return 'YES'
	elif t1 % n != 0:
		return 'NO'
	else:
		(t2, x) = (t1 // n, abs(a[0] - t1 // n))
		for i in a:
			if i != t2 and x != abs(i - t2):
				return 'NO'
		return 'YES'
print(fn(a, t1))


input()
a = list(map(int, input().split()))
a = sorted(set(a))
if len(a) >= 4:
	print('NO')
elif len(a) <= 2:
	print('YES')
elif a[1] - a[0] == a[2] - a[1]:
	print('YES')
else:
	print('NO')


__author__ = 'Alexander'
import sys
n = int(sys.stdin.readline().strip())
A = set(map(int, sys.stdin.readline().split()))
if len(A) > 3:
	sys.stdout.write('NO')
elif len(A) == 3:
	a1 = min(A)
	a3 = max(A)
	a2 = min(A - set([a1, a3]))
	if a2 - a1 == a3 - a2:
		sys.stdout.write('YES')
	else:
		sys.stdout.write('NO')
else:
	sys.stdout.write('YES')


import sys
from functools import lru_cache

def main(arr):
	arr = set(arr)
	if len(arr) in (1, 2):
		print('YES')
	elif len(arr) == 3:
		arr = list(arr)
		arr.sort()
		if arr[1] - arr[0] == arr[2] - arr[1]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
for (e, line) in enumerate(sys.stdin.readlines()):
	inp = map(int, line.strip().split())
	if e == 0:
		continue
	arr = list(inp)
main(arr)


n = int(input())
ll = list(map(int, input().split()))
minn = min(ll)
maxx = max(ll)
t = maxx - minn
if t % 2 == 0:
	nor = (minn + maxx) // 2
	t = True
	l = [minn, nor, maxx]
	for i in ll:
		if i not in l:
			t = False
			break
	if t == True:
		print('YES')
	else:
		print('NO')
else:
	t = True
	l = [minn, maxx]
	for i in ll:
		if i not in l:
			t = False
			break
	if t == True:
		print('YES')
	else:
		print('NO')


N = int(input())
A = set(list(map(int, input().split())))
if len(A) == 1:
	print('YES')
elif len(A) == 2:
	print('YES')
elif len(A) == 3:
	A = list(A)
	max_v = max(A)
	min_v = min(A)
	md_v = sum(A) - max_v - min_v
	if md_v * 2 == max_v + min_v:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


from itertools import product
from math import ceil, gcd, sqrt
import string
from decimal import Decimal

def binary_table(string_with_all_characters, length_to_make):
	return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)]

def all_possible_substrings(string):
	return [int(string[i:j]) for i in range(len(string)) for j in range(i + 1, len(string) + 1)]

def number_of_substrings(length):
	return int(length * (length + 1) / 2)
num_of_nums = int(input())
array = set(map(int, input().split()))
if len(array) == 1 or len(array) == 2:
	print('YES')
	exit()
elif len(array) == 3:
	min_ar = min(array)
	middle_ar = 0
	max_ar = max(array)
	for i in array:
		if i != min_ar and i != max_ar:
			middle_ar = i
	divide_and_conquer = middle_ar - min_ar
	max_ar -= divide_and_conquer
	min_ar += divide_and_conquer
	if min_ar == max_ar and min_ar == middle_ar:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import sys
from itertools import product
n = int(input())
A = input().split()
A = {int(x) for x in A}
if len(A) > 5:
	print('NO')
	sys.exit()
A = list(A)
for nabor in product('+-=', repeat=len(A)):
	for (x1, x2) in product(A, repeat=2):
		dx = abs(x1 - x2)
		B = A.copy()
		for (idx, operation) in enumerate(nabor):
			if operation == '-':
				B[idx] -= dx
			elif operation == '+':
				B[idx] += dx
			elif operation == '=':
				pass
		if len(set(B)) == 1:
			print('YES')
			sys.exit()
		dx = abs(x1 - x2) // 2
		B = A.copy()
		for (idx, operation) in enumerate(nabor):
			if operation == '-':
				B[idx] -= dx
			elif operation == '+':
				B[idx] += dx
			elif operation == '=':
				pass
		if len(set(B)) == 1:
			print('YES')
			sys.exit()
print('NO')


import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
d = collections.Counter(a)
if len(d) == 1 or len(d) == 2:
	print('YES')
elif len(d) > 3:
	print('NO')
else:
	flag = 0
	b = list(d.keys())
	if b[1] - b[0] == b[2] - b[1]:
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
x = min(a)
y = max(a)
z = -1
for i in a:
	if i not in [x, y]:
		z = i
		break
if z == -1:
	f = True
elif a.count(x) + a.count(y) + a.count(z) != len(a):
	f = False
elif y - z == z - x:
	f = True
else:
	f = False
if f:
	print('YES')
else:
	print('NO')


n = int(input())
lista = list(set(map(int, input().split())))
if len(lista) == 1:
	print('YES')
elif len(lista) == 2:
	print('YES')
elif len(lista) == 3:
	lista.sort()
	(a, b, c) = lista
	b -= a
	c -= a
	if 2 * b == c:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
u = set(a)
if len(u) != 3 and len(u) != 1 and (len(u) != 2):
	print('NO')
elif len(u) == 1:
	print('YES')
elif len(u) == 3:
	v = list(u)
	v.sort()
	if v[1] - v[0] == v[2] - v[1]:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


input()
s = 'YES'
a = []
for i in list(map(int, input().split())):
	if not i in a:
		if len(a) < 4:
			a = a + [i]
		else:
			s = 'NO'
			break
a.sort()
if len(a) == 3:
	if a[1] - a[0] == a[2] - a[1]:
		print(s)
	else:
		print('NO')
elif len(a) == 2:
	print('YES')
elif len(a) == 1:
	print('YES')
else:
	print('NO')


import sys

def input():
	return sys.stdin.readline().strip()
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
distinct = []
i = 0
while i < n:
	distinct.append(a[i])
	i += 1
	while i < n and a[i] == a[i - 1]:
		i += 1
if len(distinct) > 3:
	print('NO')
elif len(distinct) <= 2:
	print('YES')
elif (distinct[2] + distinct[0]) / 2 == distinct[1]:
	print('YES')
else:
	print('NO')


n = input()
arr = input().split()
arr = list(map(int, arr))
s = set(arr)
if len(s) < 3:
	print('YES')
elif len(s) == 3:
	a = min(s)
	c = max(s)
	s.remove(a)
	b = min(s)
	if b - a == c - b:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


a = input()
b = [int(x) for x in input().split()]
c = set(b)
keep = 0
d = sorted(list(c))
keep = -1
if len(d) == 3 and d[2] - d[1] == d[1] - d[0]:
	print('YES')
elif len(d) == 2 or len(d) == 1:
	print('YES')
else:
	print('NO')


input()
items = {x for x in map(int, input().split())}
if len(items) > 3:
	print('NO')
elif len(items) <= 2:
	print('YES')
else:
	le = sorted(list(items))
	print(('NO', 'YES')[le[2] - le[1] == le[1] - le[0]])


input()
a = [int(i) for i in input().split()]
a.sort()
b = [i for i in a if i != a[0] and i != a[-1]]
if a[0] == a[-1] or a.count(a[0]) + a.count(a[-1]) == len(a):
	print('YES')
elif b[0] == b[-1] and (a[0] + a[-1]) / 2 == b[0]:
	print('YES')
else:
	print('NO')


n = int(input())
s = set()
for x in list(map(int, input().split())):
	s.add(x)
	if len(s) == 4:
		print('NO')
		exit()
if len(s) < 3:
	print('YES')
	exit()
a = sorted(list(s))
(x, y, z) = (a[0], a[1], a[2])
print('YES' if 2 * y == x + z else 'NO')


n = int(input())
arr = list(map(int, input().split()))
lst = []
count = 0
for i in arr:
	if i not in lst:
		lst.append(i)
		count += 1
	if count == 4:
		break
if len(lst) == 3:
	lst.sort()
	if lst[1] - lst[0] == lst[2] - lst[1]:
		print('YES')
	else:
		print('NO')
elif len(lst) < 3:
	print('YES')
else:
	print('NO')


def mi():
	return map(int, input().split())
n = list(mi())[0]
a = set(list(mi()))
if len(a) <= 2:
	print('YES')
elif len(a) > 3:
	print('NO')
else:
	s = []
	for i in a:
		s.append(i)
	s.sort()
	if 2 * s[1] == s[0] + s[2]:
		print('YES')
	else:
		print('NO')


n = int(input())
a = list(set((int(x) for x in input().split())))
a.sort()
lena = len(a)
if lena == 1 or lena == 2 or (lena == 3 and a[0] + a[2] == 2 * a[1]):
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
min = a[0]
max = a[n - 1]
mid = (max + min) / 2
x = mid - min
bool = True
for i in a:
	if i > min and i != mid:
		if i - x != mid:
			bool = False
			break
if bool:
	print('YES')
else:
	print('NO')


n = int(input())
l = sorted(set(map(int, input().split())))
s = len(l)
print(['NO', 'YES'][s < 3 or (s == 3 and l[0] + l[2] == l[1] * 2)])


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


n = int(input())
l = input()
l = [int(i) for i in l.split()]
if len(set(l)) > 3:
	print('NO')
else:
	b = sorted(set(l))
	if len(b) == 1 or len(b) == 2:
		print('YES')
	elif n == 2:
		print('YES')
	elif abs(b[0] - b[1]) == abs(b[1] - b[2]):
		print('YES')
	else:
		print('NO')


n = int(input())
sp = list(map(int, input().split()))
t = []
if n > 2:
	for el in sp:
		if not el in t:
			t.append(el)
		if len(t) > 3:
			print('NO')
			break
	else:
		if len(t) == 3:
			t.sort()
			if t[1] - t[0] == t[2] - t[1]:
				print('YES')
			else:
				print('NO')
		elif len(t) <= 2:
			print('YES')
else:
	print('YES')


import sys
from math import *

def ints_input():
	return [int(i) for i in sys.stdin.readline().strip('\n').split(' ')]

def print_list(arr):
	sys.stdout.writelines((str(x) + ' ' for x in arr))
	sys.stdout.write('\n')

def fast_input(type=str):
	return type(sys.stdin.readline().strip('\n'))
n = fast_input(int)
arr = ints_input()
ans = (max(arr) - min(arr)) / 2
e = min(arr) + ans
b = type(ans) == int
for i in range(n):
	if arr[i] > e:
		arr[i] -= ans if b else ceil(ans)
	elif arr[i] < e:
		arr[i] += ans if b else floor(ans)
if all((int(x) == arr[0] for x in arr)):
	print('YES')
else:
	print('NO')


def FilyasHW(n, arr):
	S = list(set(arr))
	S.sort()
	if n < 3 or len(S) < 3:
		return True
	if len(S) > 3:
		return False
	D = {}
	for i in arr:
		D[i] = D.get(i, 0) + 1
	if S[1] - S[0] == S[2] - S[1]:
		return True
	else:
		return False
n = int(input())
arr = [int(i) for i in input().split()]
if FilyasHW(n, arr):
	print('YES')
else:
	print('NO')


n = int(input())
l_n = list(map(int, input().split()))
h = max(l_n)
l = min(l_n)
for n in l_n:
	if n != h and n != l:
		if abs(n - h) != abs(n - l):
			print('NO')
			quit()
print('YES')


import sys
import math
from collections import defaultdict
import itertools
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInt():
	return int(sys.stdin.readline().rstrip())

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	sys.stdout.write()
	pass

def solve(ans):
	pass

def readinput():
	_ = getInt()
	lst = list(getInts())
	st = set(lst)
	if len(st) > 3:
		print('NO')
	elif len(st) == 3:
		k = sorted(st)
		if abs(k[1] - k[0]) == abs(k[2] - k[1]):
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
readinput()


n = int(input())
s = list(set(list(map(int, input().split()))))
s.sort()
ans = 'YES' if len(s) < 3 or (len(s) == 3 and abs(s[1] - s[0]) == abs(s[2] - s[1])) else 'NO'
print(ans)


n = int(input())
num = list(map(int, input().split()))
num.sort()
x = num[n - 1] - num[0]
dem = 0
for j in range(len(num) - 1):
	i = num[j]
	if i + x == num[n - 1] - x or i == num[n - 1] - x or i == num[n - 1]:
		dem += 1
if dem == n - 1:
	print('YES')
elif x % 2 == 0:
	x = int(x / 2)
	dem = 0
	for j in range(len(num)):
		i = num[j]
		if i + x == num[n - 1] - x or i - x == num[n - 1] - x or i == num[n - 1] - x:
			dem += 1
	if dem == n:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
numDistinct = 1
b = [a[0]]
for i in range(0, n - 1):
	if a[i] != a[i + 1]:
		numDistinct = numDistinct + 1
		b.append(a[i + 1])
if numDistinct < 4:
	if numDistinct != 3:
		print('YES')
	elif b[0] + b[2] == 2 * b[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def li():
	l = input().split()
	return [int(l[k]) for k in range(len(l))]

def test(l, x):
	for k in range(1, len(l)):
		if l[k] not in [m, m + x, m + 2 * x]:
			return False
	return True
n = int(input())
l = li()
l = list(set(l))
(m, M) = (min(l), max(l))
if m < M:
	t = [0, M - m]
	if (M - m) % 2 == 0:
		t.append((M - m) // 2)
	a = True
	for x in t:
		if test(l, x):
			print('YES')
			a = False
			break
	if a:
		print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print('YES')
	exit()
elif len(set(a)) == 2:
	print('YES')
	exit()
m = max(a)
s = min(a)
if (m - s) % 2 == 1:
	print('NO')
else:
	q = (m - s) // 2
	p = s + q
	for i in range(n):
		if a[i] < p and a[i] + q != p:
			print('NO')
			exit()
		elif a[i] > p and a[i] - q != p:
			print('NO')
			exit()
	print('YES')


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
mp = defaultdict(int)
for i in a:
	mp[i] += 1
st = set(a)
if len(st) > 3:
	print('NO')
elif len(st) < 3 or (len(st) == 3 and max(st) + min(st) == 2 * (sum(st) - min(st) - max(st))):
	print('YES')
else:
	print('NO')


n = int(input().strip())
arr = sorted(set(map(int, input().strip().split())))
if len(arr) <= 2:
	exit(print('YES'))
if len(arr) == 3:
	if arr[1] - arr[0] == arr[2] - arr[1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


num = int(input())
c = list(set(map(int, input().split())))
c.sort()
if len(c) > 3:
	print('NO')
elif len(c) < 3:
	print('YES')
elif c[1] - c[0] == c[2] - c[1]:
	print('YES')
else:
	print('NO')


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
counter = Counter(arr)
if len(counter) <= 2:
	print('YES')
elif len(counter) == 3:
	(a, b, c) = sorted(counter)
	if 2 * b == a + c:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


input()
A = tuple(map(int, input().split()))
l = min(A)
r = max(A)
m = r if 1 & r - l else l + r >> 1
for a in A:
	if l != a and m != a and (r != a):
		print('NO')
		break
else:
	print('YES')