Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.

Kirill has already made his measurements, and has got the following integer values: x_1, x_2, ..., x_{n}. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.

Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y_1, y_2, ..., y_{n} in her work, that the following conditions are met:  the average value of x_1, x_2, ..., x_{n} is equal to the average value of y_1, y_2, ..., y_{n}; all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. 

Help Anya to write such a set of measurements that the conditions above are met.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.

The second line contains a sequence of integers x_1, x_2, ..., x_{n} ( - 100 000 ≤ x_{i} ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x_1, x_2, ..., x_{n} does not exceed 2.


-----Output-----

In the first line print the minimum possible number of equal measurements.

In the second line print n integers y_1, y_2, ..., y_{n} — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.

If there are multiple answers, print any of them. 


-----Examples-----
Input
6
-1 1 1 0 0 -1

Output
2
0 0 0 0 0 0 

Input
3
100 100 101

Output
3
101 100 100 

Input
7
-10 -9 -10 -8 -10 -9 -9

Output
5
-10 -10 -9 -9 -9 -9 -9 



-----Note-----

In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.

In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.

In the third example the number of equal measurements is 5.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Mathematics

Implementation


Solutions:
n = int(input())
a = list(map(int, input().split()))
mx = -2000000000.0
mn = 2000000000.0
for i in range(0, n):
	mx = max(mx, a[i])
	mn = min(mn, a[i])
cntmx = 0
cntmn = 0
for i in range(0, n):
	if a[i] == mx:
		cntmx += 1
	elif a[i] == mn:
		cntmn += 1
if mx - mn < 2:
	print(n)
	ans = ''
	for i in range(0, n):
		ans += str(a[i]) + ' '
	print(ans)
else:
	cntmid = n - cntmx - cntmn
	c1 = min(cntmx, cntmn)
	c2 = cntmid // 2
	if n - c1 * 2 <= n - c2 * 2:
		pmx = 0
		pmn = 0
		ans = ''
		for i in range(0, n):
			if a[i] == mx and pmx < c1:
				pmx += 1
				a[i] -= 1
			elif a[i] == mn and pmn < c1:
				pmn += 1
				a[i] += 1
			ans += str(a[i]) + ' '
		print(n - c1 * 2)
		print(ans)
	else:
		pmid = 0
		ans = ''
		for i in range(0, n):
			if a[i] == mn + 1 and pmid < c2:
				a[i] += 1
				pmid += 1
			elif a[i] == mn + 1 and pmid < c2 * 2:
				a[i] -= 1
				pmid += 1
			ans += str(a[i]) + ' '
		print(n - c2 * 2)
		print(ans)


from collections import Counter
n = int(input())
izms = Counter(map(int, input().split()))
max_val = max(izms)
min_val = min(izms)
max_cnt = izms[max_val]
min_cnt = izms[min_val]
med_cnt = n - max_cnt - min_cnt
res = n
if max(izms) - min(izms) == 2:
	med_val = max(izms) - 1
	krainie = min(max_cnt, min_cnt)
	if krainie > med_cnt // 2:
		res -= 2 * krainie
		izms[max_val] -= krainie
		izms[min_val] -= krainie
		izms[med_val] += krainie * 2
	else:
		srednie = 2 * (med_cnt // 2)
		res -= srednie
		izms[med_val] -= srednie
		izms[max_val] += med_cnt // 2
		izms[min_val] += med_cnt // 2
print(res)
a = [' '.join([str(iz)] * izms[iz]) for iz in izms]
print(' '.join((k for k in a if len(k) > 0)))


n = int(input())
xs = [int(x) for x in input().split()]
plus = 0
minus = 0
null = 0
maxi = max(xs)
mini = min(xs)
mid = None
for i in range(n):
	if xs[i] == maxi:
		plus += 1
	elif xs[i] == mini:
		minus += 1
	else:
		null += 1
		mid = xs[i]
if maxi == mini:
	print(n)
	print(*xs)
elif mid == None and maxi - mini != 2:
	print(n)
	print(*xs)
else:
	if mid == None:
		mid = (maxi + mini) // 2
	min_plus = plus - min(plus, minus)
	min_null = null + min(plus, minus) * 2
	min_minus = minus - min(plus, minus)
	minimum = null + max(plus, minus) - min(plus, minus)
	plus_now = min_plus
	minus_now = min_minus
	null_now = min_null
	for null_now in range(null + min(plus, minus) * 2, null % 2 - 1, -2):
		cons_minus = min(minus_now, minus)
		cons_null = min(null_now, null)
		cons_plus = min(plus_now, plus)
		if cons_minus + cons_null + cons_plus <= minimum:
			minimum = cons_minus + cons_null + cons_plus
			min_plus = plus_now
			min_minus = minus_now
			min_null = null_now
		plus_now += 1
		minus_now += 1
	print(minimum)
	pk = 1
	nk = 1
	if min_plus == 0:
		pk = 0
	if min_null == 0:
		nk = 0
	print(*[maxi] * min_plus, end=' ' * pk)
	print(*[mid] * min_null, end=' ' * nk)
	print(*[mini] * min_minus)


n = int(input().strip())
l = [int(x) for x in input().strip().split()]
if len(set(l)) == 1:
	print(n)
	print(*l)
	exit(0)
l.sort()
f = [0] * 3
s = list(set(l))
s.sort()
if len(s) == 2 and s[1] - s[0] == 1:
	print(n)
	print(*l)
	exit(0)
if len(s) == 2:
	s.append(s[-1])
	s[1] = s[0] + 1
for i in range(3):
	f[i] = l.count(s[i])
if f[1] > min(f[0], f[2]) * 2:
	ans = f[1] - f[1] % 2
	ans = n - ans
	flag = 0
	if f[1] % 2 == 1:
		flag = 1
	f[0] += f[1] // 2
	f[2] += f[1] // 2
	f[1] = flag
	print(ans)
	for i in range(3):
		print((str(s[i]) + ' ') * f[i], end='')
else:
	ans = f[1] + max(f[0], f[2]) - min(f[0], f[2])
	f[1] += min(f[0], f[2]) * 2
	(f[0], f[2]) = (f[0] - min(f[0], f[2]), f[2] - min(f[0], f[2]))
	print(ans)
	for i in range(3):
		print((str(s[i]) + ' ') * f[i], end='')
	print('')


from collections import Counter
n = int(input())
ins = input()
x = Counter(map(int, ins.split()))
max_val = max(x.keys())
min_val = min(x.keys())
if max_val - min_val < 2:
	print(n)
	print(ins)
else:
	mid_val = (min_val + max_val) // 2
	(c1, c2, c3) = (x[min_val], x[mid_val], x[max_val])
	(t1, t2) = (c2 // 2, c2 % 2)
	t3 = min(c1, c3)
	res = min((c1 + t2 + c3, (c1 + t1, t2, c3 + t1)), (c1 + c2 + c3 - t3 * 2, (c1 - t3, c2 + t3 * 2, c3 - t3)))
	print(res[0])
	res2 = []
	for (k, v) in zip((min_val, mid_val, max_val), res[1]):
		res2.extend([k] * v)
	print(*res2)


n = int(input())
a = list(map(int, input().split()))
m = min(a)
a = list(map(lambda x: x - m, a))
if max(a) == 1:
	print(n)
	for i in a:
		print(i + m, end=' ')
else:
	(c0, c1, c2) = [0, 0, 0]
	for i in a:
		if i == 0:
			c0 += 1
		elif i == 1:
			c1 += 1
		else:
			c2 += 1
	(ac0, ac1, ac2) = (c0, c1, c2)
	(bc0, bc1, bc2) = (c0, c1, c2)
	t1 = min(ac0, ac2)
	ac1 += 2 * t1
	ac2 -= t1
	ac0 -= t1
	t2 = bc1 - bc1 % 2
	bc2 += t2 // 2
	bc0 += t2 // 2
	bc1 -= t2
	if min(ac1, c1) + min(ac2, c2) + min(ac0, c0) < min(bc1, c1) + min(bc2, c2) + min(bc0, c0):
		print(min(ac1, c1) + min(ac2, c2) + min(ac0, c0))
		out = ''
		for i in range(ac0):
			out += '0 '
		for i in range(ac1):
			out += '1 '
		for i in range(ac2):
			out += '2 '
		for i in out.split():
			print(int(i) + m, end=' ')
	else:
		print(min(bc1, c1) + min(bc2, c2) + min(bc0, c0))
		out = ''
		for i in range(bc0):
			out += '0 '
		for i in range(bc1):
			out += '1 '
		for i in range(bc2):
			out += '2 '
		for i in out.split():
			print(int(i) + m, end=' ')


R = lambda : map(int, input().split())
n = int(input())
v = list(R())
mn = min(v)
mx = max(v)
from collections import Counter
c = Counter(v)
if mn == mx or mn == mx - 1:
	print(len(v))
	print(' '.join(map(str, v)))
	exit()
if mn == mx - 2 and len(c) == 2:
	c[mn + 1] = 0
k = sorted(list(c.keys()))
ck0 = c[k[0]]
ck1 = c[k[1]]
ck2 = c[k[2]]
if 2 * min(ck0, ck2) <= 2 * (ck1 // 2):
	i = [i for i in range(len(v)) if v[i] == k[1]]
	for j in range(ck1 // 2):
		(v[i[2 * j]], v[i[2 * j + 1]]) = (v[i[2 * j]] - 1, v[i[2 * j + 1]] + 1)
	print(len(v) - 2 * (ck1 // 2))
	print(' '.join(map(str, v)))
else:
	mni = [i for i in range(len(v)) if v[i] == mn]
	mxi = [i for i in range(len(v)) if v[i] == mx]
	for i in range(min(ck0, ck2)):
		(v[mni[i]], v[mxi[i]]) = (v[mni[i]] + 1, v[mxi[i]] - 1)
	print(len(v) - 2 * min(ck0, ck2))
	print(' '.join(map(str, v)))


from collections import Counter
k = int(input())
str_data = input()
fd = Counter()
for i in str_data.split():
	fd[int(i)] += 1
d_min = min(fd.keys())
d_mid = d_min + 1
d_max = max(fd.keys())
if d_max - d_min <= 1:
	print(k)
	print(str_data)
else:
	if fd[d_mid] // 2 > min(fd[d_min], fd[d_max]):
		while fd[d_mid] > 1:
			fd[d_min] += 1
			fd[d_max] += 1
			fd[d_mid] -= 2
			k -= 2
	else:
		while fd[d_min] != 0 and fd[d_max] != 0:
			fd[d_min] -= 1
			fd[d_max] -= 1
			fd[d_mid] += 2
			k -= 2
	res = [str(d_min)] * fd[d_min] + [str(d_mid)] * fd[d_mid] + [str(d_max)] * fd[d_max]
	print(k)
	print(' '.join(res))


def main():
	n = int(input())
	measures = [int(x) for x in input().split()]
	m = min(measures)
	count = [measures.count(m + i) for i in range(3)]
	if count[2] == 0:
		print(n)
		print(' '.join([str(x) for x in measures]))
		return
	pairsOfOnesToSwap = min(count[0], count[2])
	pairsOfZerosToSwap = count[1] // 2
	if pairsOfOnesToSwap >= pairsOfZerosToSwap:
		count = (count[0] - pairsOfOnesToSwap, count[1] + 2 * pairsOfOnesToSwap, count[2] - pairsOfOnesToSwap)
		print(n - 2 * pairsOfOnesToSwap)
	else:
		count = (count[0] + pairsOfZerosToSwap, count[1] - 2 * pairsOfZerosToSwap, count[2] + pairsOfZerosToSwap)
		print(n - 2 * pairsOfZerosToSwap)
	count = [max(0, x) for x in count]
	print(' '.join([str(x) for x in count[0] * [m] + count[1] * [m + 1] + count[2] * [m + 2]]))
main()


n = int(input())
meas = [int(x) for x in input().split()]
max_m = int(max(meas))
min_m = int(min(meas))
mid_m = min_m + 1
normalized_meas = [x - min_m for x in meas]
c0 = normalized_meas.count(0)
c2 = normalized_meas.count(2)
c02_pairs = min(c0, c2)
c1 = normalized_meas.count(1)
c1_pairs = c1 // 2
if max_m - min_m < 2:
	print(n)
elif c1_pairs >= c02_pairs:
	print(n - c1 + c1 % 2)
	meas = list(filter(lambda x: x != mid_m, meas))
	meas += [min_m, max_m] * c1_pairs + [mid_m] * (c1 % 2)
else:
	print(n - 2 * c02_pairs)
	meas = list(filter(lambda x: x == mid_m, meas))
	meas += [min_m] * (c0 - c02_pairs) + [max_m] * (c2 - c02_pairs) + [mid_m] * 2 * c02_pairs
print(*meas)


n = int(input())
l = list(map(int, input().split(' ')))
s = sum(l) // len(l)
(mn, mx) = (min(l), max(l))
if mx - mn <= 1:
	print(n)
	for i in l:
		print(i, end=' ')
else:
	(a, b, c) = (l.count(mn), l.count(mn + 1), l.count(mx))
	(a1, b1, c1) = (a - min(a, c), b + 2 * min(a, c), c - min(a, c))
	(a2, b2, c2) = (a + b // 2, b % 2, c + b // 2)
	diff1 = min(a, a1) + min(b, b1) + min(c, c1)
	diff2 = min(a, a2) + min(b, b2) + min(c, c2)
	if diff1 <= diff2:
		print(diff1)
		s = (str(mn) + ' ') * a1 + (str(mn + 1) + ' ') * b1 + (str(mx) + ' ') * c1
		s = s[:-1]
		print(s)
	else:
		print(diff2)
		s = (str(mn) + ' ') * a2 + (str(mn + 1) + ' ') * b2 + (str(mx) + ' ') * c2
		s = s[:-1]
		print(s)


import math
n = int(input())
xs = [int(s) for s in input().split()]
max_x = -math.inf
min_x = +math.inf
for x in xs:
	max_x = max(max_x, x)
	min_x = min(min_x, x)
if max_x <= min_x + 1:
	print(n)
	print(' '.join((str(x) for x in xs)))
else:
	max_count = sum((x == max_x for x in xs))
	min_count = sum((x == min_x for x in xs))
	middle_count = n - max_count - min_count
	solution = [max_x] * (max_count - min_count) + [min_x] * (min_count - max_count)
	equal = len(solution)
	if middle_count <= (n - len(solution)) / 2:
		equal += middle_count
		solution += [max_x - 1] * (n - len(solution))
	else:
		equal += n - len(solution) - middle_count
		solution += [max_x, min_x] * ((n - len(solution)) // 2)
		if len(solution) != n:
			solution += [max_x - 1]
			equal += 1
	print(equal)
	print(' '.join((str(x) for x in solution)))


_ = input()
X = list(map(int, input().strip().split(' ')))
total = len(X)
dX = {}
for x in X:
	if x in dX:
		dX[x] += 1
	else:
		dX[x] = 1
minX = min(dX.keys())
maxX = max(dX.keys())
if maxX - minX == 2:
	midX = (maxX + minX) // 2
	if midX not in dX:
		dX[midX] = 0
	if min(dX[minX], dX[maxX]) >= dX[midX] // 2:
		rem = min(dX[minX], dX[maxX])
		dX[minX] -= rem
		dX[maxX] -= rem
		dX[midX] += rem * 2
		strikeoff = total - rem * 2
	else:
		rem = dX[midX] - dX[midX] % 2
		dX[midX] -= rem
		dX[maxX] += rem // 2
		dX[minX] += rem // 2
		strikeoff = total - rem
else:
	strikeoff = total
print(strikeoff)
for k in dX.keys():
	for i in range(dX[k]):
		print(k, end=' ')
print()


n = int(input())
xi = list(map(int, input().split()))
maxi = max(xi)
mini = min(xi)
mid = mini + (maxi - mini) // 2
if 2 > maxi - mini:
	print(n)
	for i in xi:
		print(i, end=' ')
else:
	temp = 0
	temp2 = 0
	temp3 = 0
	for i in xi:
		if i == mini:
			temp += 1
		elif i == mid:
			temp2 += 1
		else:
			temp3 += 1
	temp4 = maxi
	temp5 = temp3 - temp
	if temp > temp3:
		temp4 = mini
		temp5 = temp - temp3
		temp = temp3
	temp6 = temp2
	temp2 //= 2
	if temp > temp2:
		temp *= 2
		print(n - temp)
		for i in range(temp5):
			print(temp4, end=' ')
		for i in range(n - temp5):
			print(mid, end=' ')
	else:
		print(n - temp2 * 2)
		for i in range(temp6 % 2):
			print(mid, end=' ')
		for i in range(temp2 + temp):
			print(mini, maxi, end=' ')
		for i in range(temp5):
			print(temp4, end=' ')


from collections import Counter
n = int(input())
a = list(map(int, input().split()))

def get_mm(a):
	mmin = 1000000
	mmax = -1000000
	for el in a:
		if el > mmax:
			mmax = el
		if el < mmin:
			mmin = el
		if mmax - mmin == 2:
			break
	return (mmin, mmax)

def sol(a):
	b = []
	(mmin, mmax) = get_mm(a)
	if mmax - mmin != 2:
		return (len(a), a)
	mid_v = mmin + 1
	counter = Counter(a)
	if not counter.get(mmin + 1):
		counter[mmin + 1] = 0
	one = min(counter.get(mmin), counter.get(mmax))
	two = counter.get(mmin + 1) // 2
	if one > two:
		b.extend([mmin + 1] * (one * 2 + counter.get(mmin + 1)))
		b.extend([mmax] * (counter.get(mmax) - one))
		b.extend([mmin] * (counter.get(mmin) - one))
	else:
		b.extend([mmin + 1] * (counter.get(mmin + 1) - two * 2))
		b.extend([mmax] * (counter.get(mmax) + two))
		b.extend([mmin] * (counter.get(mmin) + two))
	return (len(a) - 2 * max(one, two), b)
(ans, mas) = sol(a)
print(ans)
print(' '.join(list(map(str, mas))))


n = int(input())
lst = [int(x) for x in input().split()]
lst.sort()
if lst[0] + 1 in lst:
	a = lst.index(lst[0] + 1)
elif lst[0] + 2 in lst:
	a = lst.index(lst[0] + 2)
	b = 0
else:
	a = len(lst)
	b = 0
	c = 0
if lst[0] + 2 in lst:
	b = lst.index(lst[0] + 2) - a
	c = len(lst) - b - a
else:
	b = len(lst) - a
	c = 0
if c == 0:
	print(n)
	for x in lst:
		print(x, end=' ')
if c != 0:
	if b // 2 >= a or b // 2 >= c:
		print(n - b // 2 * 2)
		for k in range(a + b // 2):
			print(lst[0], end=' ')
		if b % 2 == 1:
			print(lst[0] + 1, end=' ')
		for k in range(c + b // 2):
			print(lst[0] + 2, end=' ')
	elif c <= a:
		print(n - 2 * c)
		for k in range(a - c):
			print(lst[0], end=' ')
		for k in range(b + 2 * c):
			print(lst[0] + 1, end=' ')
	else:
		print(n - 2 * a)
		for k in range(c - a):
			print(lst[0] + 2, end=' ')
		for k in range(b + 2 * a):
			print(lst[0] + 1, end=' ')


n = int(input())
ls = list(map(int, input().split()))
m1 = min(ls)
m2 = max(ls)
if m2 - m1 <= 1:
	print(n)
	print(*ls)
else:
	occs = [0, 0, 0]
	for elem in ls:
		if elem == m1:
			occs[0] += 1
		elif elem == m2:
			occs[2] += 1
		else:
			occs[1] += 1
	if occs[1] // 2 > min(occs[0], occs[2]):
		ans = [m1] * (occs[0] + occs[1] // 2)
		ans.extend([m1 + 1] * (occs[1] - occs[1] // 2 * 2))
		ans.extend([m2] * (occs[2] + occs[1] // 2))
		print(n - occs[1] // 2 * 2)
	else:
		m = min(occs[0], occs[2])
		ans = [m1] * (occs[0] - m)
		ans.extend([m1 + 1] * (occs[1] + m * 2))
		ans.extend([m2] * (occs[2] - m))
		print(n - m * 2)
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
a1 = max(a)
a2 = min(a)
if a1 - a2 < 2:
	print(n)
	print(*a)
else:
	counta1 = 0
	counta2 = 0
	for i in range(n):
		if a[i] == a1:
			counta1 += 1
		elif a[i] == a2:
			counta2 += 1
	s1 = str(a1) + ' '
	s2 = str(a2) + ' '
	s3 = str(a2 + 1) + ' '
	if min(counta1, counta2) > (n - counta1 - counta2) // 2:
		print(n - 2 * min(counta1, counta2))
		print(s1 * (counta1 - min(counta1, counta2)) + s2 * (counta2 - min(counta1, counta2)) + s3 * (n - counta1 - counta2 + 2 * min(counta1, counta2)))
	else:
		x = n - counta1 - counta2
		print(n - x // 2 * 2)
		print(s1 * (counta1 + x // 2) + s2 * (counta2 + x // 2) + s3 * (x % 2))


n = int(input())
x = list(map(int, input().split()))
x.sort()
c = [0, 0, 0]
for i in x:
	c[i - x[0]] += 1
if max(x) - x[0] < 2:
	print(n)
	for i in x:
		print(i, end=' ')
elif 2 * min(c[0], c[2]) >= c[1]:
	print(n - 2 * min(c[0], c[2]))
	for i in range(c[0] - min(c[0], c[2])):
		print(x[0], end=' ')
	for i in range(c[1] + 2 * min(c[0], c[2])):
		print(x[0] + 1, end=' ')
	for i in range(c[2] - min(c[0], c[2])):
		print(x[0] + 2, end=' ')
else:
	print(n - c[1] // 2 * 2)
	for i in range(c[0] + c[1] // 2):
		print(x[0], end=' ')
	for i in range(c[1] - c[1] // 2 * 2):
		print(x[0] + 1, end=' ')
	for i in range(c[2] + c[1] // 2):
		print(x[0] + 2, end=' ')


import sys
n = int(sys.stdin.readline().strip())
xis = list(map(int, sys.stdin.readline().strip().split()))
xmin = min(xis)
xmax = max(xis)
if xmax - xmin != 2:
	print(n)
	print(' '.join(map(str, xis)))
	sys.exit(0)
xm = (xmin + xmax) // 2
a = xis.count(xmin)
b = xis.count(xm)
c = xis.count(xmax)
edg = min(a, c)
mid = b // 2
if edg > mid:
	k = -edg
else:
	k = mid
target = a + b + c - 2 * abs(k)
A = a + k
B = b - 2 * k
C = c + k
yis = [xmin] * A + [xm] * B + [xmax] * C
print(target)
print(' '.join(map(str, yis)))


n = int(input())
a = list(map(int, input().split()))
mm = max(a)
mmm = min(a)
if mmm != mm - 2:
	print(n)
	print(*a)
else:
	(q, w, e) = (0, 0, 0)
	for i in a:
		if i == mm:
			e += 1
		elif i == mmm:
			q += 1
		else:
			w += 1
	y = w % 2 + q + e
	p = max(q, e) - min(q, e)
	u = p + w
	if y < u:
		print(y)
		print(*[mm] * (e + w // 2) + [mmm] * (q + w // 2) + [mm - 1] * (w % 2))
	else:
		print(u)
		if q > e:
			print(*[mmm] * p + (n - p) * [mmm + 1])
		else:
			print(*[mm] * p + (n - p) * [mm - 1])


n = int(input())
x = input().split()
x = [int(k) for k in x]
rem = []
x.sort()
mn = x[0]
mx = x[-1]
if mx - mn <= 1:
	print(len(x))
	for k in x:
		print(k, end=' ')
	print()
else:
	avg = mn + 1
	expsum = avg * len(x)
	sm = 0
	countmn = 0
	countavg = 0
	countmx = 0
	for k in x:
		sm += k
	if sm - expsum > 0:
		rem = x[len(x) - (sm - expsum):len(x)]
		x = x[0:len(x) - (sm - expsum)]
	if sm - expsum < 0:
		rem = x[0:expsum - sm]
		x = x[expsum - sm:len(x)]
	if len(x) % 2 == 1:
		rem.append(avg)
		for i in range(len(x)):
			if x[i] == avg:
				x = x[0:i] + x[i + 1:len(x)]
				break
	for k in x:
		if k == mn:
			countmn += 1
		if k == avg:
			countavg += 1
		if k == mx:
			countmx += 1
	if countmn + countmx < countavg:
		print(countmn + countmx + len(rem))
		for i in range(int(len(x) / 2)):
			rem.append(mn)
			rem.append(mx)
	else:
		print(countavg + len(rem))
		for i in range(len(x)):
			rem.append(avg)
	for k in rem:
		print(k, end=' ')
	print()


from collections import defaultdict

def problem():

	def count_collisions(lows, mids, his):
		return min(xs_low, lows) + min(xs_mid, mids) + min(xs_hi, his)
	in1 = int(input())
	in2 = input()
	n = in1
	xs = list(map(int, in2.split()))
	d = defaultdict(int)
	for x in xs:
		d[x] += 1
	keys = sorted(list(d.keys()))
	if len(keys) == 1:
		return '{0}\n{1}'.format(n, in2)
	diff = keys[1] - keys[0]
	if len(keys) == 2 and diff == 1:
		return '{0}\n{1}'.format(n, in2)
	if len(keys) == 2 and diff == 2:
		keys.append(keys[0] + 1)
		keys.sort()
		d[keys[1]] = 0
	xs_low = d[keys[0]]
	xs_mid = d[keys[1]]
	xs_hi = d[keys[2]]
	total = -xs_low + xs_hi
	if total < 0:
		lows = abs(total)
		mids = n - lows
		his = 0
	if total > 0:
		lows = 0
		his = total
		mids = n - total
	if total == 0:
		lows = 0
		mids = n
		his = 0
	min_collisions = count_collisions(lows, mids, his)
	lo = lows
	md = mids
	hi = his
	while mids >= 2:
		lows = lows + 1
		mids = mids - 2
		his = his + 1
		collisions = count_collisions(lows, mids, his)
		if collisions < min_collisions:
			min_collisions = collisions
			lo = lows
			md = mids
			hi = his
	return '{0}\n{1} {2} {3}'.format(min_collisions, ' '.join(map(str, lo * [keys[0]])), ' '.join(map(str, md * [keys[1]])), ' '.join(map(str, hi * [keys[2]])))
print(problem())


n = int(input())
a = list(map(int, input().split()))
a_min = min(a)
a_max = max(a)
if a_max - a_min < 2:
	print('{}\n'.format(n), ' '.join(map(str, a)), sep='')
	quit()
a = sorted(list(map(lambda x: x - a_min, a)))
t = [0 for i in range(3)]
for i in a:
	t[i] += 1
c1 = t[1] - t[1] % 2
c2 = min(t[0], t[2]) * 2
print('{}'.format(n - max(c1, c2)))
if c1 > c2:
	print('{} '.format(a_min) * (t[0] + t[1] // 2), '{} '.format(a_max) * (t[2] + t[1] // 2), '{} '.format(a_min + 1) * (t[1] % 2), sep='')
else:
	print('{} '.format(a_min) * (t[0] - c2 // 2), '{} '.format(a_max) * (t[2] - c2 // 2), '{} '.format(a_min + 1) * (t[1] + c2), sep='')


n = int(input())
lst = []
for x in input().split():
	lst.append(int(x))

def main():
	maxi = max(lst)
	mini = min(lst)
	if maxi - mini < 2:
		print(n)
		print(*lst)
	else:
		MIN = 0
		MAX = 0
		k2 = 0
		for x in lst:
			if x == mini:
				MIN += 1
			elif x == maxi:
				MAX += 1
			else:
				k2 += 1
		k1 = min(MIN, MAX)
		if 2 * k1 >= k2:
			count_min = 0
			count_max = 0
			for x in range(len(lst)):
				if lst[x] == mini and count_min < k1:
					lst[x] += 1
					count_min += 1
				elif lst[x] == maxi and count_max < k1:
					lst[x] -= 1
					count_max += 1
			print(k2 + abs(MIN - MAX))
			print(*lst)
		else:
			k = 0
			if k2 % 2 == 1:
				k += 1
			k2 = k2 // 2
			count_min = 0
			count_max = 0
			for x in range(len(lst)):
				if lst[x] == maxi - 1:
					if count_max > count_min and count_min < k2:
						count_min += 1
						lst[x] -= 1
					elif count_max < k2:
						count_max += 1
						lst[x] += 1
			print(k + MIN + MAX)
			print(*lst)
main()


n = int(input())
x = list(map(int, input().split()))
r = max(x)
l = min(x)
m = r - 1
if r - l == 0 or r - l == 1:
	print(n)
	print(*x)
else:
	cr = x.count(r)
	cl = x.count(l)
	cm = x.count(m)
	print(n - max(min(cr, cl), cm // 2) * 2)
	if min(cr, cl) > cm // 2:
		for i in range(min(cr, cl) * 2 + cm):
			print(m, end=' ')
		for i in range(cr - min(cr, cl)):
			print(r, end=' ')
		for i in range(cl - min(cr, cl)):
			print(l, end=' ')
	else:
		if cm % 2:
			print(m, end=' ')
		for i in range(cl + cm // 2):
			print(l, end=' ')
		for i in range(cr + cm // 2):
			print(r, end=' ')


from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = [int(x) for x in input().split()]
if max(a) - min(a) < 2:
	print(n)
	print(' '.join(map(str, a)))
else:
	mine = min(a)
	e = [(len(list(filter(lambda x: x == mine + i, a))), mine + i) for i in range(3)]
	s1 = e[1][0] + abs(e[0][0] - e[2][0])
	s2 = e[1][0] % 2 + e[0][0] + e[2][0]
	if s1 < s2:
		print(s1)
		res = [max(e[0], e[2])[1] for _ in range(abs(e[0][0] - e[2][0]))]
		res += [mine + 1 for _ in range(e[1][0] + 2 * min(e[0][0], e[2][0]))]
		print(' '.join(map(str, res)))
	else:
		print(s2)
		res = [e[0][1] for _ in range(e[0][0] + e[1][0] // 2)]
		res += [e[2][1] for _ in range(e[2][0] + e[1][0] // 2)]
		if e[1][0] % 2 == 1:
			res.append(e[1][1])
		print(' '.join(map(str, res)))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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')
n = int(input())
a = list(map(int, input().split()))
a.sort()
a1 = min(a)
a3 = max(a)
if a3 - a1 <= 1:
	print(n)
	print(*a)
else:
	a2 = a1 + 1
	c1 = a.count(a1)
	c2 = a.count(a2)
	c3 = a.count(a3)
	if c2 >= 2 * min(c1, c3):
		clash = c1 + c3 + c2 % 2
		n1 = c2 // 2
		n2 = c2 // 2
		r = [a1] * (c1 + n1) + [a3] * (c3 + n2) + [a2] * (c2 % 2)
	else:
		clash = c2 + max(c1, c3) - min(c1, c3)
		r = [a2] * (c2 + 2 * min(c1, c3)) + [a1] * max(0, c1 - c3) + [a3] * max(0, c3 - c1)
	print(clash)
	print(*r)


(n, m, xss) = (int(input()), 0.0, '')
xs = list(map(int, input().split()))
ch = {}
for i in xs:
	xss += str(i) + ' '
	m += i
	if i not in ch:
		ch[i] = 1
	else:
		ch[i] += 1
m /= n
(n1, n3) = (max(ch), min(ch))
if n1 - n3 == 2:
	n2 = (n1 + n3) // 2
	if n2 not in ch:
		ch[n2] = 0
	(n1, n2, n3, n0) = (ch[n1], ch[n2], ch[n3], n1)
else:
	print(n)
	print(xss)
	quit()
dn = min(n1, n3)
if 2 * dn >= n2 or n2 < 2:
	n2 += 2 * dn
	if n1 < n3:
		(n1, n3) = (0, n3 - dn)
	else:
		(n1, n3) = (n1 - dn, 0)
else:
	dn = n2 // 2
	n2 -= 2 * dn
	(n1, n3) = (n1 + dn, n3 + dn)
print(n - 2 * dn)
print((str(n0) + ' ') * n1 + (str(n0 - 1) + ' ') * n2 + (str(n0 - 2) + ' ') * n3)


n = int(input())
X = list(map(int, input().split()))
S = set(X)
if len(S) == 1:
	print(n)
	print(*X)
if len(S) == 2:
	m = min(X)
	M = max(X)
	if M - m == 1:
		print(n)
		print(*X)
	else:
		C = [0, 0, 0]
		for x in X:
			if x == m:
				C[0] += 1
			else:
				C[2] += 1
		res = 10 ** 18
		mi = -1
		for i in range(-n, n + 1):
			if C[0] + i < 0 or C[1] - 2 * i < 0 or C[2] + i < 0:
				continue
			if C[0] + i > n or C[1] - 2 * i > n or C[2] + i > n:
				continue
			temp = min(C[0], C[0] + i) + min(C[1], C[1] - 2 * i) + min(C[2], C[2] + i)
			if temp <= res:
				res = temp
				mi = i
		print(res)
		ans = [m] * (C[0] + mi) + [m + 1] * (C[1] - 2 * mi) + [M] * (C[2] + mi)
		print(*ans)
if len(S) == 3:
	m = min(X)
	M = max(X)
	if M - m == 1:
		print(n)
		print(*X)
	else:
		C = [0, 0, 0]
		for x in X:
			if x == m:
				C[0] += 1
			elif x == M:
				C[2] += 1
			else:
				C[1] += 1
		res = 10 ** 18
		mi = -1
		for i in range(-n, n + 1):
			if C[0] + i < 0 or C[1] - 2 * i < 0 or C[2] + i < 0:
				continue
			if C[0] + i > n or C[1] - 2 * i > n or C[2] + i > n:
				continue
			temp = min(C[0], C[0] + i) + min(C[1], C[1] - 2 * i) + min(C[2], C[2] + i)
			if temp <= res:
				res = temp
				mi = i
		print(res)
		ans = [m] * (C[0] + mi) + [m + 1] * (C[1] - 2 * mi) + [M] * (C[2] + mi)
		print(*ans)


import sys

def solve(xs):
	d = dict()
	for x in xs:
		if x not in d:
			d[x] = 0
		d[x] += 1
	vs = sorted(d.keys())
	if len(vs) == 1:
		v = vs[0]
		d[v - 1] = 0
		d[v + 1] = 0
	elif len(vs) == 2:
		(v1, v2) = vs
		if v2 - v1 == 1:
			if d[v1] > d[v2]:
				d[v1 - 1] = 0
			else:
				d[v2 + 1] = 0
		else:
			d[v1 + 1] = 0
	ks = sorted(d.keys())
	(l, m, s) = [b for (_, b) in sorted(d.items())]
	v = [l, m, s]
	if len(vs) == 1 or (len(vs) == 2 and abs(vs[0] - vs[1]) == 1):
		return (len(xs), zip(ks, v))
	t = m // 2
	vs1 = [l + t, m - t * 2, s + t]
	p1 = sum([min(v[i], vs1[i]) for i in range(3)])
	t = min(l, s)
	vs2 = [l - t, m + t * 2, s - t]
	p2 = sum([min(v[i], vs2[i]) for i in range(3)])
	if p1 < p2:
		vsr = vs1
	else:
		vsr = vs2
	return (min(p1, p2), zip(ks, vsr))
lines = sys.stdin.readlines()
n = int(lines[0])
xs = [int(v) for v in lines[1].split(' ')]
(d, ys) = solve(xs)
parts = [' '.join([str(k)] * n) for (k, n) in ys if n > 0]
res = ' '.join(parts)
print(d)
print(res)

def test():
	assert solve([-1, 1, 1, 0, 0, -1]) == (2, [(-1, 0), (0, 6), (1, 0)])
	assert solve([100, 100, 101]) == (3, [(99, 0), (100, 2), (101, 1)])
	assert solve([-10, -9, -10, -8, -10, -9, -9]) == (5, [(-10, 2), (-9, 5), (-8, 0)])


n = int(input())
a = [int(x) for x in input().split()]
if max(a) - min(a) < 2:
	print(len(a))
	print(' '.join([str(x) for x in a]))
else:
	x1 = min(a)
	(x2, x3) = (x1 + 1, x1 + 2)
	ms = {x: 0 for x in (x1, x2, x3)}
	for x in a:
		ms[x] += 1
	o = ms[x2] // 2 * 2
	i = min(ms[x1], ms[x3]) * 2
	if o > i:
		print(n - o)
		s1 = [x1 for _ in range(ms[x1] + o // 2)]
		s2 = [x2 for _ in range(ms[x2] % 2)]
		s3 = [x3 for _ in range(ms[x3] + o // 2)]
	else:
		print(n - i)
		s1 = [x1 for _ in range(ms[x1] - i // 2)]
		s2 = [x2 for _ in range(ms[x2] + i)]
		s3 = [x3 for _ in range(ms[x3] - i // 2)]
	print(' '.join(map(str, s1 + s2 + s3)))


n = int(input())
x = sorted(list(map(int, input().split())))
c = [0, 0, 0]
for i in x:
	c[i - x[0]] += 1
if max(x) - x[0] < 2:
	print(n)
	print(*x)
	exit()
if 2 * min(c[0], c[2]) >= c[1]:
	t = min(c[0], c[2])
	print(n - 2 * t)
	print(*[x[0]] * (c[0] - t), end=' ')
	print(*[x[0] + 1] * (c[1] + 2 * t), end=' ')
	print(*[x[0] + 2] * (c[2] - t), end=' ')
else:
	t = c[1] // 2
	print(n - t * 2)
	print(*[x[0]] * (c[0] + t), end=' ')
	print(*[x[0] + 1] * (c[1] - t * 2), end=' ')
	print(*[x[0] + 2] * (c[2] + t), end=' ')


n = int(input())
X = list(map(int, input().split()))
_min = min(X)
_max = max(X)
if _max < _min + 2:
	print(n)
	print(*X)
else:
	A = X.count(_min)
	B = X.count(_min + 1)
	C = X.count(_min + 2)
	best = n
	best_D = -1
	for D in range(-(B // 2), min(A, C) + 1):
		curr = min(A - D, A) + min(B, B + 2 * D) + min(C, C - D)
		if curr < best:
			best_D = D
			best = curr
	print(best)
	print(*[_min for _ in range(A - best_D)] + [_min + 1 for _ in range(B + 2 * best_D)] + [_min + 2 for _ in range(C - best_D)])


n = int(input())
x = [int(xx) for xx in input().split()]
x = sorted(x)
x = [str(xx) for xx in x]
m = dict()
for e in x:
	if e in m:
		m[e] += 1
	else:
		m[e] = 1
if len(m) == 1:
	print(n)
	print(' '.join(x))
if len(m) == 2:
	if int(x[-1]) - int(x[0]) == 1:
		print(n)
		print(' '.join(x))
	else:
		pair = min(m[x[0]], m[x[-1]])
		print(n - 2 * pair)
		middle = (int(x[0]) + int(x[-1])) // 2
		middle = str(middle)
		y = [x[0] for i in range(m[x[0]] - pair)] + [x[-1] for i in range(m[x[-1]] - pair)] + [middle for i in range(2 * pair)]
		print(' '.join(y))
if len(m) == 3:
	middle = (int(x[0]) + int(x[-1])) // 2
	middle = str(middle)
	pair = min(m[x[0]], m[x[-1]])
	if pair > m[middle] // 2:
		print(n - 2 * pair)
		y = [x[0] for i in range(m[x[0]] - pair)] + [x[-1] for i in range(m[x[-1]] - pair)] + [middle for i in range(2 * pair)] + [middle for i in range(m[middle])]
		print(' '.join(y))
	else:
		r = m[middle] // 2
		print(n - 2 * r)
		y = [x[0] for i in range(m[x[0]])] + [x[-1] for i in range(m[x[-1]])] + [x[0] for i in range(r)] + [x[-1] for i in range(r)] + [middle for i in range(m[middle] % 2)]
		print(' '.join(y))


from collections import Counter
n = int(input())
a = [(k, v) for (k, v) in dict(Counter([int(x) for x in input().split()])).items()]
a.sort()
if len(a) > 2:
	((k0, n0), (k1, n1), (k2, n2)) = a
	if n0 != 0 and n2 != 0:
		if min(n0, n2) * 2 > n1:
			if n0 > n2:
				n0 -= n2
				n1 += 2 * n2
				n2 = 0
			else:
				n2 -= n0
				n1 += 2 * n0
				n0 = 0
		else:
			d = n1 // 2
			n0 += d
			n1 -= 2 * d
			n2 += d
	n -= (abs(n0 - a[0][1]) + abs(n1 - a[1][1]) + abs(n2 - a[2][1])) // 2
	a = [(k0, n0), (k1, n1), (k2, n2)]
elif len(a) > 1 and abs(a[0][0] - a[1][0]) == 2:
	((k0, n0), (k2, n2)) = a
	k1 = (k0 + k2) // 2
	d = min(n0, n2)
	n1 = 2 * d
	n0 -= d
	n2 -= d
	n -= 2 * d
	a = [(k0, n0), (k1, n1), (k2, n2)]
print(n)
for (k, n) in a:
	for i in range(n):
		print(k, end=' ')


n = int(input())
ar = list(map(int, input().split()))
mn = min(ar)
mx = max(ar)
if mx - mn < 2:
	print(n)
	print(' '.join([str(i) for i in ar]))
	return
a = 0
b = 0
c = 0
for i in ar:
	if i == mn:
		a += 1
	elif i == mx:
		c += 1
	else:
		b += 1
cans1 = b - b % 2
cans2 = 2 * min(a, c)
if cans1 > cans2:
	ans = []
	for i in range(a):
		ans.append(mn)
	for i in range(c):
		ans.append(mx)
	for i in range(b // 2):
		ans.append(mn)
		ans.append(mx)
	if len(ans) < n:
		ans.append(mn + 1)
	print(n - cans1)
	print(' '.join([str(i) for i in ans]))
else:
	ans = []
	if c > a:
		ans = [mx for i in range(c - a)]
		while len(ans) < n:
			ans.append(mn + 1)
	else:
		ans = [mn for i in range(a - c)]
		while len(ans) < n:
			ans.append(mn + 1)
	print(n - cans2)
	print(' '.join([str(i) for i in ans]))


n = int(input())
x = list(map(int, input().strip().split()))
xmin = min(x)
xmax = max(x)
if xmax - xmin < 2:
	print(n)
	print(' '.join(map(str, x)))
	exit(0)
x.sort()
(a, b, c) = (0, 0, 0)
for e in x:
	if e == xmin:
		a += 1
	elif e == xmax:
		c += 1
	else:
		b += 1
tmin = n
res = [a, b, c]
for a2 in range(n + 1):
	c2 = c + a2 - a
	b2 = n - (2 * a2 + c - a)
	if c2 < 0 or c2 > n or b2 < 0 or (b2 > n):
		continue
	t = min(a, a2) + min(b, b2) + min(c, c2)
	if t < tmin:
		tmin = t
		res = [a2, b2, c2]
s = list()
s.extend([xmin] * res[0])
s.extend([xmin + 1] * res[1])
s.extend([xmin + 2] * res[2])
print(tmin)
print(' '.join(map(str, s)))


n = int(input())
x = list(map(int, input().split()))
mn = 0
mx = 0
minv = min(x)
maxv = max(x)
for i in x:
	if i == minv:
		mn += 1
	elif i == maxv:
		mx += 1
if minv != maxv - 2:
	print(n)
	for i in x:
		print(i, end=' ')
else:
	c = min(mn, mx)
	print(min(n - 2 * c, mn + mx + (n - mn - mx) % 2))
	if n - 2 * c < mn + mx + (n - mn - mx) % 2:
		for i in range(len(x)):
			if x[i] == maxv and c > 0:
				x[i] = (maxv + minv) // 2
				c -= 1
		c = min(mn, mx)
		for i in range(len(x)):
			if x[i] == minv and c > 0:
				x[i] = (maxv + minv) // 2
				c -= 1
		for i in x:
			print(i, end=' ')
	else:
		c = (n - mn - mx) // 2
		for i in range(len(x)):
			if x[i] == (minv + maxv) // 2 and c > 0:
				c -= 1
				x[i] = minv
		c = (n - mn - mx) // 2
		for i in range(len(x)):
			if x[i] == (minv + maxv) // 2 and c > 0:
				c -= 1
				x[i] = maxv
		for i in x:
			print(i, end=' ')


n = int(input())
x = list(map(int, input().split()))
ln = len(set(x))
if ln <= 2 and max(x) - min(x) <= 1:
	print(n)
	print(' '.join(map(str, x)))
else:
	abc = sorted(set(x))
	if len(abc) == 2:
		abc.insert(1, (abc[0] + abc[1]) // 2)
	co = [x.count(el) for el in abc]
	ans = n
	(a, b, c) = co
	ans_co = [a, b, c]
	while b >= 2:
		b -= 2
		a += 1
		c += 1
		s = min(a, co[0]) + min(b, co[1]) + min(c, co[2])
		if s < ans:
			ans = s
			ans_co = [a, b, c]
	(a, b, c) = co
	while min(a, c) > 0:
		a -= 1
		c -= 1
		b += 2
		s = min(a, co[0]) + min(b, co[1]) + min(c, co[2])
		if s < ans:
			ans = s
			ans_co = [a, b, c]
	print(ans)
	print(' '.join([' '.join([str(abc[j]) for i in range(ans_co[j])]) for j in range(3)]).strip())


n = int(input())
x = input()
a = list(map(int, x.split()))
if max(a) - min(a) < 2:
	print(n)
	print(x)
	exit()
s = set(a)
q = min(a)
s = max(a)
r = q + 1
m = {}
m[q] = m[s] = m[r] = 0
for i in a:
	m[i] += 1
if n - 2 * min(m[q], m[s]) < n - m[r] // 2 * 2:
	print(n - 2 * min(m[q], m[s]))
	e = min(m[q], m[s])
	m[r] += e + e
	m[q] -= e
	m[s] -= e
else:
	print(n - m[r] // 2 * 2)
	e = m[r] // 2
	m[r] -= e + e
	m[q] += e
	m[s] += e
b = [r for i in range(m[r])]
b = b + [q for i in range(m[q])]
b = b + [s for i in range(m[s])]
print(*b)


n = int(input())
x = list(map(int, input().split(' ')))
x.sort()
a = x.count(x[0])
b = x.count(x[0] + 1)
c = x.count(x[0] + 2)
if x[-1] - x[0] < 2:
	print(n)
	for j in range(0, n):
		print(x[j], end=' ')
elif b - b % 2 <= min(a, c) * 2:
	print(n - min(a, c) * 2)
	y = (b + min(a, c) * 2) * [x[0] + 1] + (a - min(a, c)) * [x[0]] + (c - min(a, c)) * [x[0] + 2]
	for j in range(0, n):
		print(y[j], end=' ')
else:
	print(n - b + b % 2)
	y = b % 2 * [x[0] + 1] + (a + b // 2) * [x[0]] + (c + b // 2) * [x[0] + 2]
	for j in range(0, n):
		print(y[j], end=' ')


n = int(input())
A = list(map(int, input().split()))
inf = 1000000000000
inf = 1000000000000
max1 = -inf
max2 = -inf
max3 = -inf
max1c = 0
max2c = 0
max3c = 0
for q in range(n):
	if A[q] > max1:
		max3 = max2
		max2 = max1
		max1 = A[q]
	elif A[q] > max2 and A[q] < max1:
		max3 = max2
		max2 = A[q]
	elif A[q] > max3 and A[q] < max1 and (A[q] < max2):
		max3 = A[q]
if max2 == max1 - 2:
	max3 = max2
	max2 = -inf
for q in range(n):
	a = A[q]
	if a == max1:
		max1c += 1
	elif a == max2:
		max2c += 1
	else:
		max3c += 1
if max3 != -inf:
	izm1 = min(max1c, max3c) * 2
	izm2 = max2c // 2 * 2
	if izm1 > izm2:
		cnt = 0
		q = 0
		while cnt < izm1 // 2:
			if A[q] == max1:
				A[q] -= 1
				cnt += 1
			q += 1
		cnt = 0
		q = 0
		while cnt < izm1 // 2:
			if A[q] == max3:
				A[q] += 1
				cnt += 1
			q += 1
	else:
		cnt = 0
		q = 0
		while cnt < izm2 // 2:
			if A[q] == max2:
				A[q] -= 1
				cnt += 1
			q += 1
		while cnt < izm2:
			if A[q] == max2:
				A[q] += 1
				cnt += 1
			q += 1
	print(n - max(izm1, izm2))
	print(*A)
else:
	print(n)
	print(*A)


import itertools
from collections import Counter

def from_edges(a, b, c):
	m = min(a, c)
	ap = a - m
	bp = 2 * m + b
	cp = c - m
	return (ap, bp, cp)

def to_edges(a, b, c):
	h = b // 2
	ap = a + h
	bp = b - 2 * h
	cp = c + h
	return (ap, bp, cp)

def score(a, b, c, ap, bp, cp):
	return min(a, ap) + min(b, bp) + min(c, cp)

def gen_ans(s, ap, bp, cp):
	return itertools.chain(itertools.repeat(s - 1, ap), itertools.repeat(s, bp), itertools.repeat(s + 1, cp))
n = int(input())
inp = input()
cnt = Counter((int(v) for v in inp.split()))
items = sorted(cnt.items())
if len(items) == 1:
	print(n)
	print(inp)
	exit()
elif len(items) == 2:
	if items[1][0] - items[0][0] == 1:
		print(n)
		print(inp)
		exit()
	else:
		(a, b, c) = (items[0][1], 0, items[1][1])
		s = items[0][0] + 1
		(ap, bp, cp) = from_edges(a, b, c)
		print(score(a, b, c, ap, bp, cp))
		print(' '.join((str(v) for v in gen_ans(s, ap, bp, cp))))
else:
	(a, b, c) = [p[1] for p in items]
	s = items[1][0]
	(ap1, bp1, cp1) = from_edges(a, b, c)
	(ap2, bp2, cp2) = to_edges(a, b, c)
	score1 = score(a, b, c, ap1, bp1, cp1)
	score2 = score(a, b, c, ap2, bp2, cp2)
	if score1 <= score2:
		(ap, bp, cp, score) = (ap1, bp1, cp1, score1)
	else:
		(ap, bp, cp, score) = (ap2, bp2, cp2, score2)
	print(score)
	print(' '.join((str(v) for v in gen_ans(s, ap, bp, cp))))


n = int(input())
r = input()
a = list(map(int, r.split()))
(x, y) = (max(a), min(a))
t = [0, 0, 0]
if x - y < 2:
	print(n)
	print(r)
else:
	for i in a:
		if i == x:
			t[0] += 1
		elif i == y:
			t[2] += 1
	t[1] = n - t[0] - t[2]
	if t[1] // 2 > min(t[0], t[2]):
		print(n - 2 * (t[1] // 2))
		s = [str(x)] * (t[0] + t[1] // 2) + [str(x - 1)] * (t[1] - 2 * (t[1] // 2)) + [str(y)] * (t[2] + t[1] // 2)
		print(' '.join(s))
	else:
		print(n - 2 * min(t[0], t[2]))
		s = [str(x)] * (t[0] - min(t[0], t[2])) + [str(x - 1)] * (t[1] + 2 * min(t[0], t[2])) + [str(y)] * (t[2] - min(t[0], t[2]))
		print(' '.join(s))


n = int(input())
arr = list(map(int, input().split()))
mn = min(arr)
mx = max(arr)
if mn == mx:
	print(n)
	print(*arr)
elif mn + 1 == mx:
	print(n)
	print(*arr)
else:
	a = 0
	b = 0
	c = 0
	for i in range(n):
		if arr[i] == mn:
			a += 1
		elif arr[i] == mx:
			c += 1
		else:
			b += 1
	a1 = a + b // 2
	c1 = c + b // 2
	b1 = b % 2
	s1 = min(a1, a) + min(b1, b) + min(c1, c)
	b2 = b + min(a, c) * 2
	q = min(a, c)
	a2 = a - q
	c2 = c - q
	s2 = min(a2, a) + min(b2, b) + min(c2, c)
	if s1 < s2:
		print(s1)
		ans = [mn] * a1 + [mn + 1] * b1 + [mx] * c1
		print(*ans)
	else:
		print(s2)
		ans = [mn] * a2 + [mn + 1] * b2 + [mx] * c2
		print(*ans)


n = int(input())
arr = list(map(int, input().split()))
mina = min(arr)
maxa = max(arr)
if maxa - mina < 2:
	print(n)
	print(*arr)
	exit()
(a, b, c) = (0, 0, 0)
for i in arr:
	if i == mina:
		a += 1
	elif i == maxa:
		c += 1
	else:
		b += 1
m = max(2 * min(a, c), b // 2 * 2)
if 2 * min(a, c) > b:
	b += 2 * min(a, c)
	(a, c) = (a - min(a, c), c - min(a, c))
else:
	a += b // 2
	c += b // 2
	b = b % 2
ans = (str(mina) + ' ') * a + (str(mina + 1) + ' ') * b + (str(mina + 2) + ' ') * c
print(n - m)
print(ans[:-1])


n = int(input())
x = n * [0]
s = input().split()
for i in range(n):
	x[i] = int(s[i])
m = min(x)
M = max(x)
if M - m < 2:
	print(n)
	for e in x:
		print(e, end=' ')
else:
	m_num = 0
	M_num = 0
	for e in x:
		if e == m:
			m_num += 1
		elif e == M:
			M_num += 1
	mid_num = n - m_num - M_num
	candidate_min1 = 0
	if mid_num % 2 == 0:
		candidate_min1 = m_num + M_num
	else:
		candidate_min1 = m_num + M_num + 1
	candidate_min2 = mid_num + abs(m_num - M_num)
	if candidate_min1 <= candidate_min2:
		print(candidate_min1)
		if mid_num % 2 == 0:
			for i in range(int(m_num + mid_num / 2)):
				print(m, end=' ')
			for i in range(int(M_num + mid_num / 2)):
				print(M, end=' ')
		else:
			for i in range(int(m_num + (mid_num - 1) / 2)):
				print(m, end=' ')
			print(m + 1, end=' ')
			for i in range(int(M_num + (mid_num - 1) / 2)):
				print(M, end=' ')
	else:
		print(candidate_min2)
		if M_num - m_num >= 0:
			for i in range(M_num - m_num):
				print(M, end=' ')
			for i in range(n - (M_num - m_num)):
				print(M - 1, end=' ')
		elif M_num - m_num < 0:
			for i in range(m_num - M_num):
				print(m, end=' ')
			for i in range(n - (m_num - M_num)):
				print(m + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
sr = sum(a) / n
x = []
min1 = min(a)
max1 = max(a)
targ = False
if min1 + 2 != max1:
	print(n)
	print(*a)
	min1 = int(sr) - 1
	max1 = int(sr) + 1
else:
	sred = (min1 + max1) // 2
	i = 0
	k = 0
	u = [0, 0, 0]
	for j in a:
		if j == min1:
			u[0] += 1
		elif j == max1:
			u[1] += 1
		else:
			u[2] += 1
	if min(u[0], u[1]) * 2 > u[2]:
		while min1 == a[k] and max1 == a[-1 - k]:
			x += [sred, sred]
			a[k] = -200001
			a[-1 - k] = -200001
			i += 2
			k += 1
		print(n - i)
		for j in a:
			if j != -200001:
				x += [j]
		print(*x)
	else:
		k = u[2] - u[2] % 2
		while u[2] > 1:
			u[2] -= 2
			x += [min1, max1]
		if u[2] > 0:
			x += [sred]
		print(n - k)
		for i in range(u[0]):
			x += [min1]
		for i in range(u[1]):
			x += [max1]
		print(*x)


n = int(input())
l = list(map(int, input().split()))
d = dict()
l.sort()
d.update({l[0] + 1: 0})
for i in range(n):
	if l[i] not in d:
		d.update({l[i]: 1})
	else:
		d[l[i]] += 1
if l[0] + 1 >= l[-1]:
	print(n)
	print(*l, sep=' ')
else:
	a = d[l[0]]
	c = d[l[-1]]
	b = d[l[0] + 1]
	b += 2 * min(a, c)
	r = min(a, c)
	a -= min(a, c)
	c -= r
	ans = [0] * n
	for i in range(a):
		ans[i] = l[0]
	for i in range(b):
		ans[i + a] = l[0] + 1
	for i in range(c):
		ans[i + a + b] = l[-1]
	dw = min(d[l[0]], a) + min(d[l[0] + 1], b) + min(d[l[-1]], c)
	a = d[l[0]] + d[l[0] + 1] // 2
	c = d[l[-1]] + d[l[0] + 1] // 2
	b = d[l[0] + 1] % 2
	ans1 = [0] * n
	tre = 0
	for i in range(a):
		ans1[tre] = l[0]
		tre += 1
	for i in range(b):
		ans1[tre] = l[0] + 1
		tre += 1
	for i in range(c):
		ans1[tre] = l[-1]
		tre += 1
	dw1 = min(d[l[0]], a) + min(d[l[0] + 1], b) + min(d[l[-1]], c)
	if dw < dw1:
		print(dw)
		print(*ans, sep=' ')
	else:
		print(dw1)
		print(*ans1, sep=' ')


import math
n = int(input())
x = [int(x) for x in input().split()]
max = max(x)
minm = min(x)
min_counts = x.count(minm)
avg_counts = x.count(minm + 1)
max_counts = x.count(max)
ans = n
if max - minm <= 1:
	print(n)
	for i in x:
		print(i, end=' ')
else:
	if min(min_counts, max_counts) * 2 < avg_counts:
		while avg_counts >= 2:
			avg_counts -= 2
			min_counts += 1
			max_counts += 1
			ans -= 2
	else:
		while min_counts > 0 and max_counts > 0:
			min_counts -= 1
			max_counts -= 1
			avg_counts += 2
			ans -= 2
	print(ans)
	for i in range(min_counts):
		print(minm, end=' ')
	for i in range(avg_counts):
		print(minm + 1, end=' ')
	for i in range(max_counts):
		print(max, end=' ')


import sys
n = int(input())
x = list(map(int, sys.stdin.readline().split()))
(mn, mx) = (min(x), max(x))
if mx - mn != 2:
	print(n)
	print(' '.join((str(i) for i in x)))
	exit(0)
av = mn + 1
m = len(list(filter(lambda x: x == mn, x)))
M = len(list(filter(lambda x: x == mx, x)))
a = len(list(filter(lambda x: x == av, x)))
if a + min(m, max(0, m - M)) + min(M, max(0, M - m)) < a - a // 2 * 2 + m + M:
	pa = a + 2 * min(M, m)
	pm = max(0, m - M)
	pM = max(0, M - m)
else:
	pa = a - a // 2 * 2
	pm = m + a // 2
	pM = M + a // 2
print(min(pa, a) + min(m, pm) + min(M, pM))
print(' '.join([str(av)] * pa + [str(mn)] * pm + [str(mx)] * pM))


n = int(input())
x = [int(y) for y in input().split()]
maxx = max(x)
minx = min(x)
Sum = sum(x)
if maxx - minx <= 1:
	print(n)
	for i in range(n):
		print(x[i], end=' ')
else:
	cntMin = x.count(minx)
	cntMax = x.count(maxx)
	ans = [n, cntMin, cntMax]
	for i in range(0, n + 1):
		leftSum = Sum - minx * i
		minSum = (n - i) * (minx + 1)
		maxSum = (n - i) * maxx
		if leftSum < minSum or leftSum > maxSum:
			continue
		else:
			cMax = leftSum - minSum
			cMinAddOne = n - i - cMax
			numOfCommon = min(cMax, cntMax) + min(cntMin, i) + min(n - cntMax - cntMin, cMinAddOne)
			if numOfCommon < ans[0]:
				ans[0] = numOfCommon
				ans[1] = i
				ans[2] = cMax
	print(ans[0])
	print((str(minx) + ' ') * ans[1] + (str(maxx) + ' ') * ans[2] + (str(minx + 1) + ' ') * (n - ans[1] - ans[2]))


n = int(input())
xraw = input()
xs = [int(x) for x in xraw.split()]
xs_set = set(xs)
mi = min(xs_set)
ma = max(xs_set)
if ma - mi < 2:
	print(n)
	print(xraw)
else:
	m = mi + 1
	mi_c = xs.count(mi)
	ma_c = xs.count(ma)
	m_c = n - mi_c - ma_c
	res = n
	if m_c // 2 > min(ma_c, mi_c):
		res = ma_c + mi_c + m_c % 2
		mi_c += m_c // 2
		ma_c += m_c // 2
		m_c = m_c % 2
	elif mi_c == ma_c:
		res = m_c
		mi_c = 0
		ma_c = 0
		m_c = n
	elif mi_c < ma_c:
		res = m_c + abs(mi_c - ma_c)
		m_c += mi_c * 2
		ma_c -= mi_c
		mi_c = 0
	else:
		res = m_c + abs(mi_c - ma_c)
		m_c += ma_c * 2
		mi_c -= ma_c
		ma_c = 0
	print(res)
	if m_c > 0:
		print(' '.join([str(m)] * m_c), end=' ')
	if mi_c > 0:
		print(' '.join([str(mi)] * mi_c), end=' ')
	if ma_c > 0:
		print(' '.join([str(ma)] * ma_c), end=' ')


n = int(input())
x = list(map(int, input().split()))
[Min, Max, Mid] = [min(x), max(x), max(x) - 1]
if Max - Min < 2:
	print(n)
	print(*x)
	exit()
[nMin, nMax, nMid] = list(map(x.count, [Min, Max, Mid]))
[nfMinMax, nfMid] = [min(nMin, nMax), nMid // 2]
nf = max(nfMinMax, nfMid)
b = nf == nfMid or -1
nMin += nf * b
nMax += nf * b
nMid += -2 * nf * b
print(n - 2 * nf)
print(*[Min] * nMin + [Max] * nMax + [Mid] * nMid)