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.

Difficulty: interview

Starter code:

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

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


from collections import Counter

n = int(input())
izms = Counter(list(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

# print(' '.join(' '.join([str(iz)]*izms[iz]) for iz in izms), izms)

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



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)
    return
elif len(items) == 2:
    if items[1][0] - items[0][0] == 1:
        print(n)
        print(inp)
        return
    else:
        # diff is 2
        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)))


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))); return;

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

# vars: c1, c2, c3, ins, max_val, mid_val, min_val, n, res, res2, t1, t2, t3, x
from collections import Counter
n = int(input())
ins = input()
x = Counter(list(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)
#	res = min((c1+t1, t2, c3+t1), (c1-t3, c2+t3*2, c3-t3))
#	res1 = 0
#	for vs in zip((c1, c2, c3), res):
#		res1 += min(vs)
#	print(res1)
#	res2 = []
#	for k, v in zip((min_val, mid_val, max_val), res):
#		res2.extend([k]*v)
#	print(*res2)


n = int(input())
arr = list(map(int, input().split()))
mina = min(arr)
maxa = max(arr)
if maxa - mina < 2:
    print(n)
    print(*arr)
    return
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])

#!/usr/bin/env python3

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

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

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())
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=" ")
else:
    if (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;
#print(max1, max2, max3);
for q in range(n):
    a = A[q];
    if a == max1:
        max1c += 1;
    elif a == max2:
        max2c += 1;
    else:
        max3c += 1;
#print(max1c, max2c, max3c);
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;
        #print(n - izm1);
        #print(*A);
    else:
        #print(izm2);
        cnt = 0;
        q = 0;
        while cnt < izm2 // 2:
            #print(cnt);
            if A[q] == max2:
                A[q] -= 1;
                cnt += 1;
            q += 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);

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())
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
	
	# MAKE THE 2s as 1s and remove 0s
	t1 = min(ac0,ac2)
	ac1+=2*t1
	ac2-=t1
	ac0-=t1

	# COMBINE 1s to form 2s
	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 = ' ')

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


    



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

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


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)

n=int(input().strip())
l=[int(x) for x in input().strip().split()]
if len(set(l))==1:
  print(n)
  print(*l)
  return
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)
    return
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("")

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

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