I found an interesting problem on https://codeforces.com/problemset/problem/488/B:
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x_1, x_2, x_3, x_4} (x_1 ≤ x_2 ≤ x_3 ≤ x_4) arithmetic mean is $\frac{x_{1} + x_{2} + x_{3} + x_{4}}{4}$, median is $\frac{x_{2} + x_{3}}{2}$ and range is x_4 - x_1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.

For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.

Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains a_{i} candies.

Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?


-----Input-----

The first line of input contains an only integer n (0 ≤ n ≤ 4).

The next n lines contain integers a_{i}, denoting the number of candies in the i-th box (1 ≤ a_{i} ≤ 500).


-----Output-----

In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution.

If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box.

All your numbers b must satisfy inequality 1 ≤ b ≤ 10^6. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them.

Given numbers a_{i} may follow in any order in the input, not necessary in non-decreasing.

a_{i} may have stood at any positions in the original set, not necessary on lowest n first...

I tried it in Python, but could not do it. Can you solve it?
n = int(input())

ar = [int(input()) for x in range(n)]

ar.sort()

foobar = 1

def out(*g):
	g = list(g)
	g.sort()
	print("YES")
	for x in g:
		print(x)

def check(x1,x2,x3,x4):
	l = [x1,x2,x3,x4]
	s = sum(l) /4
	if s != int(s):
		return False
	l.sort()
	m = (l[1]+l[2])/2
	if m != int(m):
		return False
	d = l[3] - l[0]
	
	if not (s==m==d):
		return False
	return True

def _0():
	print('YES')
	print(1)
	print(1)
	print(3)
	print(3)

def _1():
	x = ar[0]
	print("YES")
#	print(x)
	print(x)
	print(3*x)
	print(3*x)

def _2():
	x,y = ar
	if x*3 < y:
		print("NO")
	else:
		
		print('YES')
#		print(x)
#		print(y)
		print(4*x-y)
		print(3*x)
def _3():
	x = ar[0]
	y = ar[1]
	z = ar[2]
	if x*3 < z:
		print("NO")
	else:
		print('YES')
#		print(x)
#		print(y)
#		print(z)
		print(3*x)

def _3():
	ar.sort()
	m = (max(ar)+10)*10
	for x in range(1, m):
		if check(x, *ar):
			out(x)
			return
			
	print("NO")


def _4():
	r = check(*ar)
	if r == False:
		print('NO')
	else:
		print("YES")
#		for x in ar:  print(x)


vars()['_' + str(n)]()