This is the easy version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem.

Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a row and they are numbered from $1$ to $n$ from left to right. Each ice sphere has a positive integer price. In this version all prices are different.

An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.

You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered.


-----Input-----

The first line contains a single integer $n$ $(1 \le n \le 10^5)$ — the number of ice spheres in the shop.

The second line contains $n$ different integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^9)$ — the prices of ice spheres.


-----Output-----

In the first line print the maximum number of ice spheres that Sage can buy.

In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them.


-----Example-----
Input
5
1 2 3 4 5

Output
2
3 1 4 2 5 


-----Note-----

In the example it's not possible to place ice spheres in any order so that Sage would buy $3$ of them. If the ice spheres are placed like this $(3, 1, 4, 2, 5)$, then Sage will buy two spheres: one for $1$ and one for $2$, because they are cheap.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Constructive algorithms

Greedy algorithms


Solutions:
import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)
n = iinp()
l = linp()
l.sort()
s = 0
ans = []
end = n - 1
start = 0
while n > 2:
	ans.append(l[end])
	ans.append(l[start])
	s += 1
	end = end - 1
	start = start + 1
	n = n - 2
if n == 0:
	pass
elif n == 1:
	ans.append(l[start])
elif n == 2:
	ans.append(l[end])
	ans.append(l[start])
p(s)
print(*ans)


n = int(input())
w = []
r = list(map(int, input().split()))
r = sorted(r)

def numb(r):
	c = 0
	for i in r:
		if i == r[(n - 1) // 2]:
			c = c + 1
	return c
cons = r[(n - 1) // 2]
numbb = numb(r)
if numbb >= (n + 1) // 2:
	i = 0
	k = []
	a = 0
	while r[i] != cons:
		k.append(cons)
		k.append(r[i])
		i = i + 1
		a = a + 1
	i = n - 1
	c = 0
	while r[i] != cons:
		k.append(r[i])
		k.append(cons)
		i = i - 1
		c = c + 1
	for i in range(n - 2 * c - 2 * a):
		k.append(cons)
	if c > 1:
		print(c + a - 1)
		print(*k)
	else:
		print(a)
		print(*k)
else:
	k = []
	i = 0
	if n % 2 == 0:
		while len(k) < n:
			k.append(r[1 + i + (n - 1) // 2])
			k.append(r[i])
			i = i + 1
	else:
		k.append(r[(n - 1) // 2])
		while len(k) < n:
			k.append(r[i])
			i = i + 1
			k.append(r[i + (n - 1) // 2])
	print((n - 1) // 2)
	print(*k)


import math
t = int(input())
arr = list(map(int, input().split(' ')))
arr = sorted(arr)
if len(arr) % 2 != 0:
	val = int(len(arr) / 2)
	print(val)
	final_str = ''
	new_arr = arr[val:len(arr) + 1]
	k = 1
	for i in range(val):
		new_arr.insert(k, arr[i])
		k += 2
	for i in range(len(new_arr)):
		final_str += str(new_arr[i])
		if i != len(new_arr) - 1:
			final_str += ' '
	print(final_str)
else:
	val = int(len(arr) / 2) - 1
	print(val)
	final_str = ''
	new_arr = arr[val:len(arr) + 1]
	k = 1
	for i in range(val):
		new_arr.insert(k, arr[i])
		k += 2
	for i in range(len(new_arr)):
		final_str += str(new_arr[i])
		if i != len(new_arr) - 1:
			final_str += ' '
	print(final_str)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
(l2, l3) = ([], [])
x = n // 2
if n % 2 != 0:
	print(x)
	l2 = l1[0:x]
	l3 = l1[x:n]
else:
	print(x - 1)
	l2 = l1[0:x - 1]
	l3 = l1[x - 1:n]
(x, y) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		print(l3[x], end=' ')
		x += 1
	else:
		if y == len(l2):
			break
		print(l2[y], end=' ')
		y += 1
for i in range(x, len(l3)):
	print(l3[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
print((n - 1) // 2)
b = []
i = 0
j = n - 1
while i < j:
	b += (a[j],)
	j -= 1
	b += (a[i],)
	i += 1
if n & 1:
	b += (a[n // 2],)
print(*b)


n = int(input())
a = sorted(list(map(int, input().split())))
k = n // 2
l = 0
b = []
for i in range(n):
	if i % 2 == 0:
		b.append(a[k])
		k += 1
	else:
		b.append(a[l])
		l += 1
z = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		z += 1
print(z)
print(*b)


n = int(input())
a = list(map(int, input().split()))
i = 0
cnt = 0
while i + 2 < n:
	fst = a[i]
	mid = a[i + 1]
	lst = a[i + 2]
	if fst > mid and lst > mid:
		i = i + 2
		cnt += 1
	else:
		if fst < mid and fst < lst:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
			i = i + 2
		elif lst < mid and lst < fst:
			(a[i + 1], a[i + 2]) = (a[i + 2], a[i + 1])
			i = i + 2
		cnt += 1
print(cnt)
for i in range(n):
	print(a[i], end=' ')


from sys import *
from collections import deque
n = int(stdin.readline().strip())
things = sorted([int(x) for x in stdin.readline().strip().split(' ')])
count = 0
final = []
big = deque(things[n // 2:])
small = deque(things[:n // 2])
for i in range(len(small)):
	left = big.popleft()
	if big and left > small[0] and (big[0] > small[0]):
		count += 1
		final.append(left)
		final.append(small.popleft())
	else:
		final.append(left)
		final.append(small.pop())
if big:
	final.append(big.pop())
print(count)
print(' '.join(map(str, final)))


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
ans = [0] * n
x = 0
for i in range(n):
	if i % 2 == 1:
		ans[i] = ar[x]
		x += 1
for i in range(n):
	if i % 2 == 0:
		ans[i] = ar[x]
		x += 1
rslt = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		rslt += 1
print(rslt)
print(*ans)


n = int(input())
m = list(map(int, input().split()))
m.sort()
if n % 2:
	a = [0] * n
	for i in range(n // 2):
		a[2 * i + 1] = m[i]
	j = 0
	for i in range(n // 2, n):
		a[j] = m[i]
		j += 2
	print(n // 2)
	print(*a)
else:
	a = [0] * n
	for i in range(n // 2):
		a[2 * i] = m[i]
	j = 0
	for i in range(n // 2, n):
		a[j + 1] = m[i]
		j += 2
	print(n // 2 - 1)
	print(*a)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0 for i in range(n)]
i = 1
j = 0
while i < n:
	b[i] = a[j]
	i += 2
	j += 1
for k in range(n):
	if b[k] == 0:
		b[k] = a[j]
		j += 1
a.append(9999999999)
count = 0
add = 1
(store, flag) = (0, 0)
for i in range(n):
	if a[i] == a[i + 1]:
		add += 1
	else:
		if add > n // 2:
			flag = 1
		elif flag == 0:
			count += add
		else:
			store += add
		add = 1
if flag == 1:
	if store > 0:
		print(count + store - 1)
	else:
		print(count + store)
elif n % 2 == 1:
	print(n // 2)
else:
	print(n // 2 - 1)
for i in range(n):
	print(b[i], end=' ')


from collections import Counter
from collections import OrderedDict
from collections import defaultdict

def SOCountR(mylist):
	return OrderedDict(sorted(Counter(mylist).items(), reverse=True))

def SOCount(mylist):
	return OrderedDict(sorted(Counter(mylist).items()))

def freq_count(mylist):
	return Counter(mylist)
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = arr[0:n // 2]
arr2 = arr[n // 2:]
arr3 = []
for i in range(n // 2):
	arr3.append(arr2[i])
	arr3.append(arr1[i])
if n % 2 != 0:
	arr3.append(arr2[-1])
cnt = 0
for i in range(1, n - 1):
	if arr3[i - 1] > arr3[i] < arr3[i + 1]:
		cnt += 1
print(cnt)
print(*arr3)


n = int(input())
d = [*map(int, input().split())]
d.sort()
ans = 0
pref = 0
for i in d:
	pref += i
	if pref <= n:
		ans += 1
	else:
		break
p = []
for i in range(n // 2 + n % 2):
	p.append(d[n - i - 1])
	if n - i - 1 != i:
		p.append(d[i])
print(n // 2 - (n + 1) % 2)
print(*p)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
a.sort()
print(int((n - 1) / 2))
arr = []
for i in range(n):
	arr.append(0)
start = 0
for i in range(1, n, 2):
	arr[i] = a[start]
	start += 1
for i in range(0, n, 2):
	arr[i] = a[start]
	start += 1
for i in arr:
	print(i, '', end='')
print('')


n = int(input())
li = list(map(int, input().split()))
print((n - 1) // 2)
a = (n - 1) // 2
li.sort()
ans = [-1 for i in range(n)]
c = 0
for i in range(1, a + 1):
	ans[i * 2 - 1] = li[c]
	c += 1
for i in range(n):
	if ans[i] == -1:
		ans[i] = li[c]
		c += 1
print(*ans)


def solve():
	n = int(input())
	nums = list(map(int, input().split(' ')))
	nums.sort()
	i = 0
	while i < n - 1:
		(nums[i], nums[i + 1]) = (nums[i + 1], nums[i])
		i += 2
	cnt = 0
	for i in range(1, n - 1):
		if nums[i - 1] > nums[i] < nums[i + 1]:
			cnt += 1
	print(cnt)
	for i in range(n):
		sep = ' ' if i != n - 1 else ''
		print(nums[i], end=sep)
solve()


n = int(input())
l = list(map(int, input().split()))
l.sort()
d = n // 2
(r1, r2) = ([], [])
for i in range(d):
	r1.append(l[i + d])
	r1.append(l[i])
	r2.append(l[i])
	r2.append(l[i + d])
if n % 2 == 1:
	r1.append(l[-1])
	r2.append(l[-1])
(c1, c2) = (0, 0)
for i in range(1, n - 1):
	if r1[i] < r1[i - 1] and r1[i] < r1[i + 1]:
		c1 += 1
	if r2[i] < r2[i - 1] and r2[i] < r2[i + 1]:
		c2 += 1
if c1 > c2:
	print(c1)
	print(*r1)
else:
	print(c2)
	print(*r2)


N = int(input())
A = list(map(int, input().split()))
print((N - 1) // 2)
A.sort(reverse=True)
left = 0
right = N - 1
B = [0] * N
cnt = 0
while cnt < N:
	B[cnt] = A[left]
	left += 1
	cnt += 1
	if cnt == N:
		break
	B[cnt] = A[right]
	right -= 1
	cnt += 1
print(*B)


n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(0, n - 1, 2):
	(a[i], a[i + 1]) = (a[i + 1], a[i])
print((n - 1) // 2)
print(*a)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	v = []
	l = (n - 3) // 2
	r = n - 1
	for i in range(n):
		if i % 2 > 0 and l >= 0:
			v.append(a[l])
			l -= 1
		else:
			v.append(a[r])
			r -= 1
	ans = 0
	for i in range(1, n - 1):
		if v[i - 1] > v[i] and v[i] < v[i + 1]:
			ans += 1
	print(ans)
	print(*v)
t = 1
while t > 0:
	solve()
	t -= 1


from sys import stdin
n = int(input())
a = sorted(list(map(int, input().split())))
i = 0
j = n - 1
res = 0
arr = []
while i < j:
	arr.append(a[j])
	j -= 1
	arr.append(a[i])
	i += 1
if i == j:
	arr.append(a[i])
for k in range(1, n - 1):
	if arr[k] < arr[k - 1] and arr[k] < arr[k + 1]:
		res += 1
print(res)
print(*arr)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n <= 2:
	print(0)
	print(*arr, sep=' ')
else:
	mid = n // 2
	ans = []
	for i in range(mid, n):
		ans.append(arr[i])
		ans.append(arr[i - mid])
	if n % 2 == 1:
		ans.pop()
	val = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			val += 1
	print(val)
	print(*ans, sep=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans_arr = [0 for i in range(n)]
ind = n - 1
for i in range(0, n, 2):
	ans_arr[i] = str(arr[ind])
	ind -= 1
for i in range(1, n, 2):
	ans_arr[i] = str(arr[ind])
	ind -= 1
if n % 2 == 0:
	n -= 1
ans = n // 2
print(ans)
print(' '.join(ans_arr))


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = [int(X) for X in input().split()]
	a.sort()
	x = a[:n // 2]
	y = a[n // 2:]
	ma = []
	for i in range(len(x)):
		ma.append(y[i])
		ma.append(x[i])
	if n % 2 == 1:
		ma.append(y[-1])
	c = 0
	for i in range(1, n - 1):
		if ma[i] < ma[i - 1] and ma[i] < ma[i + 1]:
			c += 1
	print(c)
	print(*ma)
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())
a = list(map(int, input().split()))
a.sort()
j = n // 2
i = 0
ans = []
for _ in range(n):
	if _ % 2 == 0:
		ans.append(a[j])
		j += 1
	else:
		ans.append(a[i])
		i += 1
c = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		c += 1
print(c)
print(*ans)


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')
from collections import deque
n = int(input())
vals = list(map(int, input().split()))
vals.sort()
vals = deque(vals)
ans = []
count = 0
while len(vals) > 0:
	if len(ans) % 2 == 0:
		ans.append(vals.pop())
	else:
		ans.append(vals.popleft())
for s in range(1, n - 1):
	if ans[s - 1] > ans[s] and ans[s] < ans[s + 1]:
		count += 1
print(count)
print(*ans)


from sys import stdin
n = int(stdin.readline())
a = sorted(map(int, input().split()))
m = (n - 1) // 2
print(m)
for i in range(n):
	print(a[(1 - i % 2) * (n // 2) + i // 2], end=' ')


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
k = (n + 1) // 2 - 1
ss = 0
for i in range(k):
	if a[i] < a[n // 2 + i] and a[i] < a[n // 2 + i + 1]:
		ss += 1
print(ss)
for i in range(n):
	if i % 2 == 0:
		print(a[n // 2 + i // 2], end=' ')
	else:
		print(a[i // 2], end=' ')
print()


n = int(input())
v = sorted(list(map(int, input().split())))
result = list(v)
for i in range(n // 2):
	result[i * 2 + 1] = v[i]
for i in range(n // 2):
	result[i * 2] = v[i + n // 2]
if len(result) % 2 == 0:
	(result[-1], result[-2]) = (result[-2], result[-1])
c = 0
for i in range(1, n - 1):
	if result[i - 1] > result[i] < result[i + 1]:
		c += 1
print(c)
print(*result)


n = int(input())
a = [int(x) for x in input().split()]
asort = sorted(a)
j = 0
ans = [0] * len(a)
for i in range(1, len(a), 2):
	ans[i] = asort[j]
	j += 1
for k in range(0, len(a), 2):
	ans[k] = asort[j]
	j += 1
total = 0
for num in range(1, len(ans) - 1, 2):
	if ans[num] < ans[num - 1] and ans[num] < ans[num + 1]:
		total += 1
print(total)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
	print(a[0])
elif n == 2:
	print(0)
	print(a[0], a[1], end=' ')
	print()
else:
	a.sort(reverse=True)
	l = [0 for i in range(n)]
	c = 0
	v = 0
	for i in range(n):
		if i % 2 == 0:
			l[i] = a[v]
			c = c + 1
			v = v + 1
	k = 0
	for j in range(n):
		if l[j] == 0:
			l[j] = a[v]
			v = v + 1
			k = k + 1
	if n % 2 == 0:
		print(k - 1)
	else:
		print(k)
	for i in l:
		print(i, end=' ')
	print()


t = int(input())
ice = list(map(int, input().split()))
new_ice = []
count = 0
ice.sort()
if len(ice) % 2 != 0:
	for i in range(0, len(ice) // 2 + 1):
		new_ice.append(ice[len(ice) // 2 + i])
		new_ice.append(ice[i])
	del new_ice[-1]
elif len(ice) <= 2:
	for i in range(len(ice)):
		new_ice.append(ice[i])
else:
	for i in range(0, len(ice) // 2):
		new_ice.append(ice[len(ice) // 2 + i])
		new_ice.append(ice[i])
for i in range(1, len(new_ice) - 1, 1):
	if new_ice[i] < new_ice[i - 1] and new_ice[i] < new_ice[i + 1]:
		count += 1
print(count)
print(' '.join(map(str, new_ice)))


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1

def solve():
	l1 = [0] * n
	i = 1
	j = 2
	while i < n and j < n:
		l1[i] = l[j]
		j += 2
		i += 2
	l1[0] = l[0]
	i = 2
	j = 1
	while i < n and j < n:
		l1[i] = l[j]
		i += 2
		j += 2
	ans = 0
	if n % 2 == 0:
		l1[-1] = l[-1]
	for i in range(1, n - 1):
		if l1[i - 1] > l1[i] and l1[i + 1] > l1[i]:
			ans += 1
	return (ans, l1)
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	(ans, l1) = solve()
	print(ans)
	print(*l1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
	k = n // 2 - 1
else:
	k = n // 2
d = [0 for i in range(n)]
i = 0
j = n - 1
for i in range(0, k):
	d[2 * i] = a[j]
	d[2 * i + 1] = a[i]
	i += 1
	j -= 1
if i == j:
	d[n - 1] = a[i]
else:
	d[n - 1] = a[i]
	d[n - 2] = a[i + 1]
print(k)
print(' '.join(list(map(str, d))))


import sys
input = sys.stdin.readline
n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ans = [-1] * n
for i in range(0, n, 2):
	ans[i] = a.pop()
for i in range(1, n, 2):
	ans[i] = a.pop()
print((n - 1) // 2)
print(*ans)


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

def soln():
	if n == 1 or n == 2:
		return arr
	if n == 3:
		return [arr[1], arr[0], arr[2]]
	result = [0 for _ in arr]
	result[-1] = arr[-1]
	result[0] = arr[-2]
	i = n - 2
	parity = True
	while i > 0:
		if parity:
			if i - 2 >= 0:
				result[i] = arr[i - 2]
			elif i - 1 >= 0:
				result[i] = arr[i - 1]
		else:
			result[i] = arr[i]
		parity = not parity
		i -= 1
	return result
result = soln()
ans = (n - 1) // 2 if n % 2 == 1 else n // 2 - 1
print(ans)
print(' '.join(map(str, result)))


import sys
input = sys.stdin.readline
n = int(input())
w = sorted(map(int, input().split()))
print((n - 1) // 2)
d = []
for i in range((n - 1) // 2):
	d.append(w[(n - 1) // 2 + i])
	d.append(w[i])
d += w[(n - 1) // 2 + (n - 1) // 2:]
print(*d)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n % 2 != 0:
	v = a[-1]
	a = a[:-1]
p1 = 0
p2 = len(a) // 2
ans = []
while p1 <= len(a) // 2 and p2 < len(a):
	ans += [a[p2]]
	ans += [a[p1]]
	p1 += 1
	p2 += 1
if n % 2 != 0:
	ans += [v]
c = 0
for i in range(1, len(ans) - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		c += 1
print(c)
print(*ans)


def check(m):
	if 2 * m + 1 > n:
		return False
	s = []
	l = 0
	r = n - m - 1
	for i in range(2 * m + 1):
		if i % 2 == 0:
			s.append(arr[r])
			r += 1
		else:
			s.append(arr[l])
			l += 1
	for i in range(1, 2 * m, 2):
		if s[i] >= s[i - 1] or s[i] >= s[i + 1]:
			return False
	return True
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
lo = 0
hi = (n + 1) // 2
res = 0
while lo <= hi:
	mid = (lo + hi) // 2
	if check(mid):
		res = mid
		lo = mid + 1
	else:
		hi = mid - 1
print(res)
m = res
s = []
l = 0
r = n - m - 1
for i in range(2 * m + 1):
	if i % 2 == 0:
		s.append(arr[r])
		r += 1
	else:
		s.append(arr[l])
		l += 1
for i in range(m, n - m - 1):
	s.append(arr[i])
print(*s)


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(1):
	n = I()
	a = LI()
	a.sort()
	b = n // 2
	d = 0
	c = []
	for i in range(n):
		if i % 2:
			c += [a[d]]
			d += 1
		else:
			c += [a[b]]
			b += 1
	if n < 3:
		print(0)
		print(*a)
	else:
		print(n // 2 - 1 + n % 2)
		print(*c)


import sys
input = sys.stdin.readline
n = int(input())
price = list(map(int, input().split()))
price.sort()
ans = n // 2
first = ans + 1
cheap = price[:first - 1]
high = price[first - 1:]
fin = []
for i in range(len(cheap)):
	fin.append(high[i])
	fin.append(cheap[i])
high = high[len(cheap):]
while high:
	x = high.pop()
	fin.append(x)
res = 0
j = 1
while j < len(fin) - 1:
	if fin[j - 1] > fin[j] and fin[j] < fin[j + 1]:
		res += 1
	j += 2
print(res)
print(' '.join(map(str, fin)))


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	ans = []
	c1 = 0
	pos = n
	for i in range(0, n, 4):
		if i + 4 > n:
			pos = i
			break
		(b, c, d, e) = a[i:i + 4]
		ans += [e, b, d, c]
	rem = a[pos:n]
	if len(rem) == 1:
		ans += [a[pos]]
	elif len(rem) == 2:
		ans += rem
	elif len(rem) == 3:
		ans += [rem[-1], rem[0], rem[1]]
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] < ans[i + 1]:
			c1 += 1
	print(c1)
	print(*ans)


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = sorted(map(int, input().split()), reverse=1)
	b = [a[0]]
	cnt = 0
	(i, j) = (1, (n - 1) // 2 + 1)
	mark = [0] * n
	mark[0] = 1
	while i != n and j != n:
		while j != n and a[j] == a[i]:
			j += 1
		if j == n:
			break
		mark[j] = 1
		mark[i] = 1
		b.extend([a[j], a[i]])
		while i != n and mark[i]:
			i += 1
		j += 1
	for (ind, val) in enumerate(mark):
		if not val:
			b.append(a[ind])
	for i in range(1, n - 1):
		if b[i - 1] > b[i] and b[i + 1] > b[i]:
			cnt += 1
	print(cnt)
	print(' '.join(map(str, b)))
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())
spheres = list(map(int, input().split(' ')))
spheres = sorted(spheres)
ret = [-1 for _ in range(n)]
(l, r) = (0, n - 1)
cnt = 0
block_n = n // 2 + n % 2
inner_n = n - block_n
inners = spheres[:inner_n]
blocks = spheres[inner_n:n]
st = 0
if n % 2 == 0:
	ret[0] = inners.pop()
	st = 1
for i in range(st, n):
	if i % 2 == st:
		ret[i] = blocks.pop()
	else:
		ret[i] = inners.pop()
	if i > 1 and ret[i - 1] < ret[i - 2] and (ret[i - 1] < ret[i]):
		cnt += 1
print(cnt)
print(' '.join(list(map(str, ret))))


import math
t = 1
for tc in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	j = n // 2
	k = 0
	l = j
	new_arr = [0] * n
	for i in range(0, n, 2):
		new_arr[i] = arr[l]
		l += 1
		if i != n - 1:
			new_arr[i + 1] = arr[k]
			k += 1
	if n <= 2:
		j = 0
	elif n % 2 == 0:
		j -= 1
	print(j)
	for i in range(n):
		print(new_arr[i], end=' ')
	print()


import sys
n = int(sys.stdin.readline())
price = [int(v) for v in sys.stdin.readline().strip().split(' ')]
price.sort()
result = []
start = int(n / 2)
for i in range(0, start):
	result.append(price[i + start])
	result.append(price[i])
if n % 2 == 1:
	result.append(price[n - 1])
num = 0
for i in range(1, n - 1, 2):
	if result[i] < result[i - 1] and result[i] < result[i + 1]:
		num += 1
print(num)
print(' '.join((str(v) for v in result)))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
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()
A.sort()
A = deque(A)
B = []
while A:
	if A:
		x = A.pop()
		B.append(x)
	if A:
		x = A.popleft()
		B.append(x)
ans = 0
for i in range(1, N - 1):
	if B[i - 1] > B[i] < B[i + 1]:
		ans += 1
print(ans)
print(*B)


from math import *
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	print((n - 1) // 2)
	(l, r) = (0, n - 1)
	while l < r:
		print(a[r], end=' ')
		r = r - 1
		print(a[l], end=' ')
		l = l + 1
	if n % 2 != 0:
		print(a[n // 2], end=' ')
	print()


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
n = int(I1())
l = list(I())
l.sort()
a = []
(i, j) = (0, n // 2)
while i < n // 2:
	a.append(l[j])
	a.append(l[i])
	i += 1
	j += 1
c = 0
if j == n - 1:
	a.append(l[j])
for i in range(1, n - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		c += 1
print(c)
print(*a)


from sys import stdin
input = stdin.readline
n = int(input())
lst = sorted(map(int, input().split()), reverse=True)
if n > 2:
	arr = [lst[1]] + [0] * (n - 2) + [lst[0]]
	lst = lst[2:]
	ind = 0
	for i in range(2, n, 2):
		if arr[i] == 0:
			arr[i] = lst[ind]
			ind += 1
	lst = lst[ind:]
	ind = 0
	for i in range(1, n, 2):
		if arr[i] == 0:
			arr[i] = lst[ind]
			ind += 1
	cnt = 0
	if n % 2:
		print(n // 2)
	else:
		print(n // 2 - 1)
	print(*arr)
else:
	print(0)
	print(*lst)


a = int(input())
b = sorted(map(int, input().split()))
i = 0
j = a - 1
o = []
p = 0
while i <= j:
	if i == j:
		o.append(b[i])
	else:
		o.append(b[j])
		o.append(b[i])
		p += 1
	i += 1
	j -= 1
print(a // 2 - (a % 2 == 0))
print(*o)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
n = int(input())
l = sorted(list(list(map(int, input().split()))))
a = (n - 1) // 2
if a >= 1:
	mi = l[:a]
	ma = l[a:]
	ans = [ma[0], mi[0], ma[1]]
	j = 2
	for i in range(1, a):
		ans.append(mi[i])
		ans.append(ma[j])
		j += 1
	ans += ma[j:]
	a = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			a += 1
	print(a)
	print(*ans)
else:
	print(0)
	print(*l)


n = int(input())
array = list(map(int, input().split()))
array.sort()
b = int((n - 1) / 2)
small = array[:b]
large = array[b:]
ans = []
for i in range(b):
	ans.append(large[i])
	ans.append(small[i])
if n % 2 == 0:
	ans = ans + large[-2:]
else:
	ans.append(large[-1])
print(b)
print(' '.join(map(str, ans)))


n = int(input())
prices = list(map(int, input().split()))
ind = 0
if n % 2 == 1:
	print(int(n / 2))
else:
	print(int(n / 2 - 1))
prices.sort()
listCheap = prices[:int(n / 2)]
listExpensice = prices[int(n / 2):]
finalList = []
for i in range(int(n / 2) + 1):
	try:
		finalList.append(listExpensice[i])
		finalList.append(listCheap[i])
	except:
		continue
print(*finalList)


n = int(input())
a = list(map(int, input().split()))
a.sort()
from collections import deque
b = deque(a)
l = n // 2 - 1 if n % 2 == 0 else n // 2
ans = []
while len(b) >= 2:
	ans.append(b.pop())
	ans.append(b.popleft())
if len(b) == 1:
	ans.append(b.pop())
print(l)
print(' '.join(map(str, ans)))


N = int(input())
A = sorted([int(a) for a in input().split()])
print((N - 1) // 2)
B = [0] * N
for (i, a) in enumerate(A):
	if i < N // 2:
		B[i * 2 + 1] = a
	else:
		B[(i - N // 2) * 2] = a
print(*B)


n = int(input())
a = sorted(list(map(int, input().split())))
print((n - 1) // 2)
(b, c) = (a[:n // 2], a[n // 2:])
sol = []
if n % 2 == 1:
	sol.append(c[-1])
	(b, c) = (c[:-1], b)
for i in range(n // 2):
	sol.append(c[i])
	sol.append(b[i])
print(' '.join([str(i) for i in sol]))


input()
l = list(map(int, input().split()))
print((len(l) - 1) // 2)
a = list()
l.sort()
b = True
for ino in range(len(l)):
	if not b:
		a.append(l[ino // 2])
	else:
		a.append(l[len(l) - ino // 2 - 1])
	b = not b
print(*a)


n = int(input())
s = input()
prices = sorted(map(int, s.split(' ')))
optimal_order = []
half_way = n // 2
for i in range(half_way):
	optimal_order.append(str(prices[half_way + i]))
	optimal_order.append(str(prices[i]))
if n % 2 == 1:
	optimal_order.append(str(prices[-1]))
	print(n // 2)
else:
	print(n // 2 - 1)
print(' '.join(optimal_order))


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
if n % 2 == 0:
	print(n // 2 - 1)
	a = arr[n // 2:]
	b = arr[:n // 2]
	for i in range(n // 2):
		print(a[i], end=' ')
		print(b[i], end=' ')
else:
	a = arr[n // 2:]
	b = arr[:n // 2]
	print(n // 2)
	for i in range(n // 2 + 1):
		if i == n // 2:
			print(a[i])
		else:
			print(a[i], end=' ')
			print(b[i], end=' ')


(lambda N, n: (print(N - 1 >> 1), print(*[n[i >> 1] if i & 1 else n[(i >> 1) + (N >> 1)] for i in range(N)])))(int(input()), sorted(map(int, input().split())))


n = int(input())
lst1 = list(map(int, input().split()))
lst1.sort()
lst2 = []
lst2.append(0)
for i in range(0, int(n / 2)):
	lst2.append(lst1[int(n / 2) + i])
	lst2.append(lst1[i])
if n & 1:
	lst2.append(lst1[n - 1])
lst2.append(0)
cheap = 0
for i in range(1, n + 1):
	if lst2[i - 1] > lst2[i] and lst2[i] < lst2[i + 1]:
		cheap = cheap + 1
print(cheap)
for i in range(1, n + 1):
	print(lst2[i], end=' ')


n = int(input())
arr = list(map(int, input().split()))
ans = [-1] * n
arr.sort()
j = 0
p = 0
for i in range(n):
	if i & 1:
		ans[i] = arr[j]
		j += 1
for i in range(n):
	if ans[i] == -1:
		ans[i] = arr[j]
		j += 1
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		p += 1
print(p)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for i in range(0, n - 2, 2):
	(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
print(*arr)


from collections import *
from itertools import *

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

def arrinp():
	return [int(x) for x in input().split()]

def main():
	n = inp()
	A = arrinp()
	A.sort()
	right = len(A) - 1
	left = 0
	ans = []
	count = 0
	while left <= right:
		if left == right:
			ans.append(A[left])
			left += 1
			right -= 1
		else:
			ans.append(A[right])
			ans.append(A[left])
			count += 1
			left += 1
			right -= 1
	if len(A) % 2 == 0:
		count -= 1
	print(count)
	print(*ans, sep=' ')
main()


n = int(input())
list1 = list(map(int, input().strip().split()))
list1.sort()
list2 = []
for i in range(n // 2):
	list2.append(list1[n - i - 1])
	list2.append(list1[i])
if n % 2 != 0:
	list2.append(list1[(n - 1) // 2])
print((n - 1) // 2)
for val in list2:
	print(val, end=' ')
print()


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = sorted(inl())
ans = []
while len(a) > 0:
	ans.append(a.pop())
	if len(a) == 0:
		break
	ans.append(a.pop(0))
print(n // 2 if n % 2 else n // 2 - 1)
print(*ans)


import sys
n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))
lst.sort()
maxi = lst[n // 2:]
result = []
for i in range(n // 2):
	result.append(maxi[-i - 1])
	result.append(lst[i])
if n % 2 != 0:
	result.append(maxi[0])
print((n - 1) // 2)
print(*result)


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	a.sort()
	q = 0
	w = len(a) - 1
	qw = []
	for i in range(len(a) // 2):
		qw.append(a[w])
		qw.append(a[q])
		q = q + 1
		w = w - 1
	if len(a) % 2 != 0:
		qw.append(a[len(a) // 2])
	c = 0
	for i in range(1, len(qw) - 1):
		if qw[i] < qw[i - 1] and qw[i] < qw[i + 1]:
			c = c + 1
	q = len(a) // 2 - 1
	w = len(a) - 1
	qq = []
	for i in range(len(a) // 2):
		qq.append(a[w])
		qq.append(a[q])
		q = q - 1
		w = w - 1
	if len(a) % 2 != 0:
		qq.append(a[len(a) // 2])
	cc = 0
	for i in range(1, len(qq) - 1):
		if qq[i] < qq[i - 1] and qq[i] < qq[i + 1]:
			cc = cc + 1
	if len(a) == max(a) * 2:
		ww = counter(a)
		qwqw = [ww.index(max(ww)) + 1]
		for i in range(len(a)):
			if a[i] != ww.index(max(ww)) + 1:
				qwqw.append(a[i])
				qwqw.append(ww.index(max(ww)) + 1)
		qwqw.append(ww.index(max(ww)) + 1)
		print(ww.index(max(ww)) + 1)
		print(*qwqw)
	elif c > cc:
		print(c)
		print(*qw)
	else:
		print(cc)
		print(*qq)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def insr():
	return input().strip()

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def ceil(a, b):
	return -(-a // b)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
a = list(map(int, input().split()))
a.sort()
if t <= 2:
	print(0)
elif t % 2 == 0:
	print(int(t / 2) - 1)
else:
	print(int(t / 2))
for i in range(int(t / 2)):
	print(a[t - i - 1], end=' ')
	print(a[i], end=' ')
if t % 2 != 0:
	print(a[int(t / 2)])


n = int(input())
ar = list(map(int, input().split()))
ar = sorted(ar)
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = ar[j]
	j += 1
j = n // 2
for i in range(0, n, 2):
	ans[i] = ar[j]
	j += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
res = (n - 1) // 2
print(res)
arr.sort()
arr_sm = arr[0:res]
arr_big = arr[res:n]
for i in range(len(arr_big)):
	print(arr_big[i], end=' ')
	try:
		print(arr_sm[i], end=' ')
	except:
		pass


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	a.sort()
	temp = [0 for x in range(n)]
	cnt = 0
	for x in range(1, n, 2):
		temp[x] = a[cnt]
		cnt += 1
	for x in range(0, n, 2):
		temp[x] = a[cnt]
		cnt += 1
	cn = 0
	for x in range(1, n - 1):
		if temp[x] < temp[x - 1] and temp[x] < temp[x + 1]:
			cn += 1
	print(cn)
	print(*temp)
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())
a = list(map(int, input().split()))
a.sort()
outnum = 0
outlist = [0 for _ in a]
j = n - 1
i = n - 1
while j >= 0:
	outlist[j] = a[i]
	j = j - 2
	i = i - 1
j = n - 2
while j >= 0:
	outlist[j] = a[i]
	j = j - 2
	i = i - 1
if n % 2 == 0:
	outnum = int(n / 2 - 1)
	print(outnum)
	print(*outlist, sep=' ')
else:
	outnum = int((n - 1) / 2)
	print(outnum)
	print(*outlist, sep=' ')


n = int(input())
l = [int(x) for x in input().split(' ')]
l.sort()
a = l[:len(l) // 2]
b = l[len(l) // 2:]
answer = []
(x, y) = (0, 0)
for i in range(n):
	if i % 2:
		answer.append(a[x])
		x += 1
	else:
		answer.append(b[y])
		y += 1
ans = 0
for i in range(1, n - 1):
	if answer[i - 1] > answer[i] and answer[i] < answer[i + 1]:
		ans += 1
print(ans)
print(*answer)


n = int(input())
arr = list(map(int, input().split()))
ans = []
arr.sort()
ans = [-1] * n
i = 0
for j in range(n):
	if j % 2 != 0:
		ans[j] = arr[i]
		i += 1
j = 0
while i < n and j < n:
	if ans[j] == -1:
		ans[j] = arr[i]
		i += 1
	j += 1
print((n - 1) // 2)
print(*ans)


n = int(input())
a = list(map(int, input().split()))[:n]
a.sort()
b = []
for i in range(n // 2):
	b.append(a[n // 2 + i])
	b.append(a[i])
if n % 2 == 1:
	b.append(a[-1])
k = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		k += 1
print(k)
print(' '.join((str(x) for x in b)))


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = []
if n == 1:
	print(0)
	print(*l)
elif n == 2:
	print(0)
	print(*l)
else:
	ans = [0] * n
	j = 0
	for i in range(1, n, 2):
		ans[i] = l[j]
		j += 1
	for i in range(0, n, 2):
		ans[i] = l[j]
		j += 1
	count = 0
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] < ans[i + 1]:
			count += 1
	print(count)
	print(*ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
n = II()
a = sorted(MI())
print((n - 1) // 2)
(ans, i, j) = ([], (n - 1) // 2, 0)
nn = n if n % 2 else n - 1
for num in range(nn):
	if num % 2 == 0:
		ans.append(a[i])
		i += 1
	else:
		ans.append(a[j])
		j += 1
if not n % 2:
	ans.append(a[-1])
print(*ans)


import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 998244353

def main():
	n = int(input())
	arr = read()
	arr.sort()
	arr = deque(arr)
	ans = []
	i = 1
	while arr:
		if i % 2:
			ans.append(arr.pop())
		else:
			ans.append(arr.popleft())
		i += 1
	print(n // 2 - (n % 2 == 0))
	print(*ans)
main()


n = int(input())
a = sorted(map(int, input().split()))
b = [0] * n
(b[1::2], b[::2]) = (a[:n // 2], a[n // 2:])
print(sum((b[i - 1] > b[i] < b[i + 1] for i in range(1, n - 1))))
print(*b)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
res = [0] * n
a = sorted(a, reverse=True)
ai = 0
for i in range(0, n, 2):
	res[i] = a[ai]
	ai += 1
for i in range(1, n, 2):
	res[i] = a[ai]
	ai += 1
print((n - 1) // 2)
print(*res)


n = int(input())
nums = list(map(int, input().split()))
temp = nums[:]
nums.sort()
res = []
if n <= 2:
	print(0)
	print(*temp)
else:
	a = (n - 1) // 2
	small = nums[:a]
	i = 0
	j = 0
	new = nums[a:]
	new_len = len(new)
	while i < new_len and j < len(small):
		res.append(new[i])
		res.append(small[j])
		i += 1
		j += 1
	res.extend(new[i:])
	print(a)
	print(*res)


import math

def range_input():
	return range(int(input()))

def map_int_input():
	return list(map(int, input().split()))
n = int(input())
a = map_int_input()
a.sort()
print(math.ceil(n / 2) - 1)
odd = n % 2
for i in range(n // 2):
	print(a[n - 1 - i], end=' ')
	print(a[i], end=' ')
if odd == 1:
	print(a[n // 2], end=' ')


n = int(input())
l = list(map(int, input().split()))
ans = 0
l.sort()
la = l[-1]
k = []
if n < 3:
	print(0)
	print(*l)
elif n % 2 != 0:
	ans = 0
	l1 = l[0:n // 2]
	for i in range(n // 2, n - 1):
		k.append(l[i])
		k.append(l1[i - n // 2])
		ans += 1
	k.append(la)
	print(ans)
	print(*k)
else:
	ans = 0
	l1 = l[0:n // 2]
	for i in range(n // 2, n):
		k.append(l[i])
		k.append(l1[i - n // 2])
		ans += 1
	print(ans - 1)
	print(*k)


n = int(input())
A = list(map(int, input().split(' ')))
A.sort()
B = []
C = [1] * n
c = 0
if len(A) < 3:
	B = A
else:
	B.append(A[-2])
	B.append(A[0])
	B.append(A[-1])
	i = 1
	j = n - 3
	while i < j:
		B.append(A[i])
		i += 1
		B.append(A[j])
		j -= 1
	if i == j:
		B.append(A[i])
for i in range(1, n - 1):
	if B[i] < B[i - 1] and B[i] < B[i + 1]:
		c += 1
print(c)
print(*B)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
s = str(a[n // 2]) + ' '
if n % 2 != 0:
	for i in range(0, n // 2):
		s += str(a[i]) + ' ' + str(a[n // 2 + i + 1]) + ' '
else:
	for i in range(0, n // 2 - 1):
		s += str(a[i]) + ' ' + str(a[n // 2 + i + 1]) + ' '
	s += str(a[n // 2 - 1])
n1 = n // 2
if n % 2 == 0:
	n1 -= 1
print(n1)
print(s)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
mid = n // 2
i = 0
j = mid + 1
ans = [a[mid]]
if n % 2 == 0:
	for i in range(mid - 1):
		ans.append(a[i])
		ans.append(a[j])
		i += 1
		j += 1
	ans.append(a[i])
else:
	for i in range(mid):
		ans.append(a[i])
		ans.append(a[j])
		i += 1
		j += 1
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = [0] * n
i = 1
j = 0
while i < n:
	l1[i] = l[j]
	j += 1
	i += 2
i = 0
while i < n:
	l1[i] = l[j]
	j += 1
	i += 2
if n & 1:
	print(n // 2)
else:
	print(n // 2 - 1)
print(*l1)


import math
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
mid = 0
if n % 2 == 0:
	mid = n // 2 - 1
	print(n // 2 - 1)
else:
	mid = n // 2
	print(n // 2)
l = []
l.append(arr[mid])
l1 = []
l2 = []
for i in range(mid):
	l1.append(arr[i])
for i in range(mid + 1, n):
	l2.append(arr[i])
ind1 = 0
ind2 = 0
while ind1 < len(l1) and ind2 < len(l2):
	l.append(l1[ind1])
	ind1 = ind1 + 1
	l.append(l2[ind2])
	ind2 = ind2 + 1
if ind2 < len(l2):
	l.append(l2[ind2])
if len(arr) == 1:
	print(arr[0])
else:
	for i in l:
		print(i, end=' ')


import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split() if i != '\n']
a.sort()
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = a[j]
	j += 1
for i in range(n):
	if ans[i] == 0:
		ans[i] = a[j]
		j += 1
if n & 1:
	print(n // 2)
	print(*ans)
else:
	print((n - 2) // 2)
	print(*ans)


t = int(input())
a = list(map(int, input().split()))
a.sort()
g = []
if t % 2 == 0:
	for j in range(t // 2):
		g.append(a[t // 2 + j])
		g.append(a[j])
	print(t // 2 - 1)
	print(' '.join(map(str, g)))
else:
	for j in range(t // 2):
		g.append(a[t // 2 + j])
		g.append(a[j])
	g.append(a[-1])
	print(t // 2)
	print(' '.join(map(str, g)))


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
newArr = []
i = 0
j = n - 1
while i < j:
	newArr.append(arr[i])
	newArr.append(arr[j])
	i += 1
	j -= 1
if n % 2 == 1:
	newArr.append(arr[n // 2])
count = 0
for i in range(1, len(newArr) - 1):
	if newArr[i] < newArr[i - 1] and newArr[i] < newArr[i + 1]:
		count += 1
print(count)
print(' '.join(map(str, newArr)))


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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')

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

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(inverse(farr[-1], mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = 1
for i in range(t):
	n = N()
	a = RLL()
	ans = 0
	a.sort()
	i = 0
	res = [0] * n
	for j in range(1, n, 2):
		res[j] = a[i]
		i += 1
	for j in range(0, n, 2):
		res[j] = a[i]
		i += 1
	for j in range(1, n - (1 - (n & 1)), 2):
		if res[j - 1] > res[j] < res[j + 1]:
			ans += 1
	print(ans)
	print(*res)


from sys import stdin
N = int(stdin.readline())
sortedarray = sorted([int(i) for i in stdin.readline().split()])
if N % 2 == 1:
	print(N // 2)
	for i in range(N // 2):
		print(sortedarray[N - i - 1], end=' ')
		print(sortedarray[i], end=' ')
	print(sortedarray[N // 2])
else:
	print((N - 2) // 2)
	for i in range((N - 2) // 2):
		print(sortedarray[N - i - 1], end=' ')
		print(sortedarray[i], end=' ')
	print(sortedarray[(N - 2) // 2 + 1], end=' ')
	print(sortedarray[(N - 2) // 2])


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
ans = []
if n == 1:
	print('0')
	print(arr[0])
elif n == 2:
	print('0')
	print(arr[0], arr[1])
elif n % 2 == 0:
	for i in range(n // 2):
		ans.append(arr[i + n // 2])
		ans.append(arr[i])
	print((n - 1) // 2)
	print(' '.join(map(str, ans)))
else:
	for i in range(n // 2):
		ans.append(arr[i + n // 2])
		ans.append(arr[i])
	ans.append(arr[n - 1])
	print((n - 1) // 2)
	print(' '.join(map(str, ans)))


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
c = 0
arr.sort()
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = arr[j]
	j += 1
for i in range(0, n, 2):
	ans[i] = arr[j]
	j += 1
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		c += 1
print(c)
print(*ans)


n = int(input())
b = list(map(int, input().split()))
if n < 3:
	print(0)
	print(*b)
else:
	out = 0
	ans = []
	b.sort()
	k = b[:n // 2]
	l = b[n // 2:]
	if n % 2:
		for i in range(n // 2):
			ans.append(l.pop())
			ans.append(k.pop())
		ans.append(l.pop())
		for i in range(1, n, 2):
			if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
				out += 1
		print(out)
		print(*ans)
	else:
		for i in range(len(k)):
			ans.append(k.pop())
			ans.append(l.pop())
		for i in range(2, n, 2):
			if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
				out += 1
		print(out)
		print(*ans)


t = 1
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	i = 0
	j = n - 1
	l = []
	while i < j:
		l.append(a[j])
		l.append(a[i])
		j -= 1
		i += 1
	if n % 2:
		l.append(a[j])
	cnt = 0
	for i in range(1, n - 1):
		if l[i] < l[i - 1] and l[i] < l[i + 1]:
			cnt += 1
	print(cnt)
	for i in l:
		print(i, end=' ')
	print()


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
if n <= 2:
	print('0')
	for i in arr:
		print(i, end=' ')
elif n % 2 == 0:
	a = arr[n // 2:]
	b = arr[:n // 2]
	temp = []
	for i in range(n // 2):
		temp.append(a[i])
		temp.append(b[i])
	ans = 0
	for i in range(1, n - 1):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			ans += 1
	print(ans)
	for i in temp:
		print(i, end=' ')
else:
	a = arr[n // 2:]
	b = arr[:n // 2]
	temp = []
	for i in range(n // 2 + 1):
		if i == n // 2:
			temp.append(a[i])
		else:
			temp.append(a[i])
			temp.append(b[i])
	ans = 0
	for i in range(1, n - 1):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			ans += 1
	print(ans)
	for i in temp:
		print(i, end=' ')


import sys

def inp():
	return sys.stdin.readline().rstrip('\n').encode('utf8')

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

def itg():
	return int(sys.stdin.readline())
n = itg()
arr = sorted(mpint())
a1 = arr[n >> 1:]
a2 = arr[:n >> 1]
ans = []
for i in range(n):
	if i & 1:
		ans.append(a2.pop())
	else:
		ans.append(a1.pop())
for i in range(n - 2):
	if ans[i] == ans[i + 1]:
		(ans[i + 1], ans[i + 2]) = (ans[i + 2], ans[i + 1])
ans1 = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		ans1 += 1
print(ans1)
print(*ans)


n = int(input())
ns = list(map(int, input().split()))
ns.sort()
if n % 2 == 0:
	(first, second) = (ns[:n // 2], ns[n // 2:])
	n2 = ns
	n2[::2] = second
	n2[1::2] = first
	tot = 0
	for a in range(1, n - 1, 2):
		if ns[a] < ns[a + 1] and ns[a] < ns[a - 1]:
			tot += 1
	print(tot)
	print(' '.join(map(str, n2)))
else:
	(first, second) = (ns[:n // 2], ns[n // 2:])
	n2 = ns
	n2[::2] = second
	n2[1::2] = first
	tot = 0
	for a in range(1, n - 1, 2):
		if ns[a] < ns[a + 1] and ns[a] < ns[a - 1]:
			tot += 1
	print(tot)
	print(' '.join(map(str, n2)))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	output = [i for i in a]
	output[1::2] = a[0:n // 2]
	output[0::2] = a[n // 2:]
	output = ' '.join(['%d' % i for i in output])
	print(n // 2 - 1 + n % 2)
	print(output)
solve()


import sys
input = sys.stdin.readline

def prog():
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	output = [0] * n
	j = 0
	for i in range(1, n, 2):
		output[i] = a[j]
		j += 1
	for i in range(0, n, 2):
		output[i] = a[j]
		j += 1
	for i in range(1, n - 1):
		if output[i] < output[i + 1] and output[i] < output[i - 1]:
			ans += 1
	print(ans)
	print(*output)
prog()


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n < 3:
	print(0)
	for i in range(n):
		print(a[i], end=' ')
	print()
else:
	print((n - 1) // 2)
	x = 0
	if n % 2 == 1:
		n -= 1
		x = -1
	for i in range(1, n, 2):
		print(a[i], a[i - 1], end=' ')
	if x == -1:
		print(a[n])
	else:
		print()


x = int(input())
a = list(map(int, input().split()))

def answer(x, a):
	a.sort()
	n = (x - 1) // 2
	if n == 0:
		print(n)
		print(' '.join((str(i) for i in a)))
	else:
		a1 = a[:n]
		a2 = a[n:]
		s = ''
		for i in range(n):
			s += str(a2[i]) + ' ' + str(a1[i]) + ' '
		if x % 2 == 1:
			s += str(a2[n])
		else:
			s += str(a2[n]) + ' ' + str(a2[n + 1])
		print(n)
		print(s)
answer(x, a)


s = int(input())
a = list((int(num) for num in input().split()))
res = (len(a) - 1) // 2
print(res)
a.sort()
b = a[:res]
a = a[res:]
for i in range(res):
	a.insert(2 * i + 1, b[i])
for i in a:
	print(i, end=' ')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arry = list(map(int, input().split()))
arry.sort()
ans = [0] * n
if n % 2:
	rangen = n // 2 + 1
else:
	rangen = n // 2
for i in range(rangen):
	if n // 2 + i < n:
		ans[i * 2] = arry[n // 2 + i]
	if i * 2 + 1 < n:
		ans[i * 2 + 1] = arry[i]
print((n - 1) // 2)
print(' '.join([str(x) for x in ans]))


from sys import stdin, stdout

def segas_birthday_hard(n, a_a):
	a_a.sort()
	r1 = 0
	r2 = []
	a1 = a_a[0:n // 2]
	a2 = a_a[n // 2:n]
	i = 0
	j = 0
	while i < len(a1) or j < len(a2):
		r2.append(a2[j])
		if i < len(a1):
			r2.append(a1[j])
		i += 1
		j += 1
	for i in range(1, n - 1):
		if r2[i - 1] > r2[i] < r2[i + 1]:
			r1 += 1
	return [r1, r2]
n = int(stdin.readline())
a_a = list(map(int, stdin.readline().split()))
res_a = segas_birthday_hard(n, a_a)
stdout.write(str(res_a[0]) + '\n')
stdout.write(' '.join(map(str, res_a[1])) + '\n')


n = int(input())
l = sorted(map(int, input().split()))
print((n - 1) // 2)
print(*[l[n - i // 2 - 1] if i % 2 == 0 else l[i // 2] for i in range(n)])


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
res = []
for i in range(n // 2):
	res.append(arr[n // 2 + i])
	res.append(arr[i])
if n % 2:
	res.append(arr[-1])
	print(n // 2)
else:
	print(n // 2 - 1)
print(' '.join([str(i) for i in res]))


from sys import stdout, stdin
(_input, _print) = (stdin.readline, stdout.write)
(_int, _len, _min, _max, _range, _sorted) = (int, len, min, max, range, sorted)
from collections import deque

def solution():
	n = _int(_input())
	arr = _sorted([_int(i) for i in _input().split()])
	min_arr = deque(arr[:n // 2])
	max_arr = arr[n // 2:]
	index = 0
	ans = []
	z = 0
	while min_arr or max_arr:
		if index == 0:
			ans.append(max_arr.pop())
		else:
			if max_arr:
				while max_arr[-1] == min_arr[-1] and z < _len(min_arr):
					z += 1
					min_arr.appendleft(min_arr.pop())
			ans.append(min_arr.pop())
		index = (index + 1) % 2
	counter = 0
	for i in _range(1, n - 1):
		if ans[i - 1] > ans[i] < ans[i + 1]:
			counter += 1
	print(counter)
	print(*ans)
solution()


from sys import *
input = stdin.readline
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: f'{sep}'.join(a)
arrJoin = lambda a, sep: f'{sep}'.join(map(str, a))

def main():
	n = int(input())
	arr = sorted(listInput())
	a = arr[:n // 2]
	b = arr[n // 2:]
	print((n - 1) // 2)
	l = list(zip(b, a))
	ans = ''
	for i in l:
		print(i[0], end=' ')
		print(i[1], end=' ')
	if n % 2 == 1:
		print(arr[-1], end=' ')
main()


import sys
import os
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')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, lst):
	lstS = sorted(lst)
	val = n
	if val % 2 == 0:
		val -= 1
	val //= 2
	small = lstS[:val]
	large = lstS[val:]
	print(val)
	(a, b) = (0, 0)
	for i in range(n):
		if i % 2 == 1 and a <= val - 1:
			print(small[a], end=' ')
			a += 1
		else:
			print(large[b], end=' ')
			b += 1
n = int(input())
lst = list(map(int, input().split()))
solve(n, lst)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if n == 1 or n == 2:
	print(0)
	print(*a)
else:
	l = []
	st = 0
	en = 0
	i = 1
	while i < n - 1:
		if a[i] > a[i - 1]:
			(a[i], a[i - 1]) = (a[i - 1], a[i])
		elif a[i + 1] > a[i]:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
		i += 2
	print(int((n - 1) / 2))
	print(*a)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [None] * n
j = 0
for i in range(1, n, 2):
	ans[i] = a[j]
	j += 1
for i in range(0, n, 2):
	ans[i] = a[j]
	j += 1
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(*ans)


def sortInWave(arr, n):
	arr.sort()
	for i in range(0, n - 1, 2):
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
n = int(input())
arr = list(map(int, input().split()))
sortInWave(arr, n)
ans = 0
for i in range(1, n - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		ans += 1
print(ans)
for i in arr:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split(' ')))
b = a[:]
a.sort()
for i in range(int(n / 2)):
	b[i * 2 + 1] = a[i]
j = 0
for i in range(int(n / 2), n):
	b[j] = a[i]
	j += 2
print(int((n - 1) / 2))
for x in b:
	print(x, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
(i, j) = (0, int(n / 2))
res = []
while j < n:
	res.append(a[j])
	if i < int(n / 2):
		res.append(a[i])
	j += 1
	i += 1
cnt = 0
for i in range(1, n, 2):
	if i + 1 < n and res[i] < res[i - 1] and (res[i] < res[i + 1]):
		cnt += 1
print(cnt)
print(*res, sep=' ')


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = [0] * n
for i in range(0, n, 2):
	ans[i] = a.pop()
for i in range(1, n, 2):
	ans[i] = a.pop()
v = 0
flag = 0
for i in range(1, n - int(n & 1 == 0), 2):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		v += 1
	elif n & 1 == 0:
		if ans[-1] < ans[i - 1] and ans[-1] < ans[i + 1]:
			v += 1
			flag = 1
			(ans[-1], ans[i]) = (ans[i], ans[-1])
print(v)
print(*ans)


import sys
readline = sys.stdin.readline
INF = 1 << 60

def read_int():
	return int(readline())

def read_int_n():
	return list(map(int, readline().split()))

def read_float():
	return float(readline())

def read_float_n():
	return list(map(float, readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def ep(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.perf_counter()
		ret = f(*args, **kwargs)
		e = time.perf_counter()
		ep(e - s, 'sec')
		return ret
	return wrap
from collections import deque

def ref(N, A):
	from itertools import permutations
	ans = 0
	for B in permutations(A, r=N):
		t = 0
		for i in range(1, N - 1):
			if B[i - 1] > B[i] < B[i + 1]:
				t += 1
		ans = max(t, ans)
	return ans

def slv(N, A):
	A.sort()
	A = deque(A)
	M = N // 2
	L = [A.pop() for _ in range(N - M)]
	S = A
	B = [-1] * N
	for i in range(len(L)):
		B[i * 2] = L[i]
	for i in range(len(S)):
		if 2 * (i + 1) < N and B[2 * i] > S[-1] < B[2 * (i + 1)]:
			B[2 * i + 1] = S.pop()
		else:
			B[2 * i + 1] = S.popleft()
	t = 0
	for i in range(1, N - 1):
		if B[i - 1] > B[i] < B[i + 1]:
			t += 1
	print(t)
	print(*B)
	return t

def main():
	N = read_int()
	A = read_int_n()
	slv(N, A)
main()


n = int(input())
nums = sorted([int(i) for i in input().split()])
low = 0
high = n // 2
counter = 1
order = []
ans = 0
while len(order) < n:
	if counter:
		counter = 0
		order.append(nums[high])
		high += 1
	else:
		counter = 1
		order.append(nums[low])
		low += 1
for i in range(1, n - 1, 2):
	if order[i] < order[i - 1] and order[i] < order[i + 1]:
		ans += 1
print(ans)
print(' '.join([str(i) for i in order]))


n = int(input())
arr = list(map(int, input().strip().split()))
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
arr.sort()
low = arr[:n // 2]
hi = arr[n // 2:]
arr[::2] = hi
arr[1::2] = low
print(ans)
print(*arr, sep=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
v = 0
i = 2
while i < n:
	v += 1
	(l[i - 1], l[i]) = (l[i], l[i - 1])
	i += 2
print(v)
for i in range(n):
	l[i] = str(l[i])
s = ' '.join(l)
print(s)


n = int(input())
array = list(map(int, input().split(' ')))
array.sort()
menores = array[:int(n / 2)]
maiores = array[int(n / 2):]
index = 0
solucao = []
qtd = 0
flag_left = False
for i in range(n):
	if i % 2 != 0:
		solucao.append(menores[index])
		if menores[index] < solucao[i - 1]:
			flag_left = True
		else:
			flag_left = False
		index += 1
	else:
		solucao.append(maiores[int(i / 2)])
		if flag_left and maiores[int(i / 2)] > solucao[i - 1]:
			qtd += 1
			flag_left = False
print(qtd)
solucao = [str(int) for int in solucao]
print(' '.join(solucao))


from math import *
from cmath import *
from decimal import *
from fractions import *
n = int(input())
a = list(map(int, input().split()))
a.sort()
print((n - 1) // 2)
k = n - 1
for x in range(0, n // 2):
	print(a[k], a[x], end=' ')
	k -= 1
if n % 2 == 1:
	print(a[k])


import sys
mod = 1000000007

def set_io():
	fin = open('input.txt', 'r')
	fout = open('output.txt', 'w')
	sys.stdin = fin
	sys.stdout = fout

def solution(arr, n):
	if len(arr) <= 2:
		print(0)
		arr = list(map(str, arr))
		print(' '.join(arr))
		return
	arr.sort()
	middle = n // 2
	ans = []
	fp = 0
	count = 0
	i = middle
	while i < n:
		ans.append(str(arr[i]))
		if fp < middle:
			ans.append(str(arr[fp]))
			count += 1
		fp += 1
		i += 1
	if n & 1 == 0:
		count -= 1
	print(count)
	print(' '.join(ans))

def main():
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	solution(arr, n)
main()


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
tmp = [i for i in range(1, n + 1)]
cnt = 0
for i in range(1, n, 2):
	tmp[i] = lst[cnt]
	cnt += 1
if n % 2 == 0:
	print(cnt - 1)
else:
	print(cnt)
for i in range(0, n, 2):
	tmp[i] = lst[cnt]
	cnt += 1
print(*tmp)


def solve(a):
	num = int((len(a) - 1) / 2)
	print(num)
	if num == 0:
		return a
	a.sort()
	k = 0
	res = [0] * len(a)
	for i in range(1, len(a), 2):
		res[i] = a[k]
		k += 1
	for i in range(0, len(a), 2):
		res[i] = a[k]
		k += 1
	return res
n = int(input())
a = list(map(int, input().split()))
print(*solve(a))


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
i = 0
for j in range(1, n, 2):
	b[j] = a[i]
	i += 1
for j in range(0, n, 2):
	b[j] = a[i]
	i += 1
cnt = 0
for j in range(1, n - 1):
	if b[j - 1] > b[j] and b[j] < b[j + 1]:
		cnt += 1
print(cnt)
print(*b)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
for i in range(0, len(a) - 1, 2):
	(a[i], a[i + 1]) = (a[i + 1], a[i])
c = 0
for i in range(1, len(a) - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		c += 1
print(c)
print(*a)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
k = n // 2
s = []
l = []
for i in range(0, n):
	if i < k:
		s.append(arr[i])
	else:
		l.append(arr[i])
new = []
j = 0
while j < len(l):
	new.append(l[j])
	if j < len(s):
		new.append(s[j])
	j += 1
c = 0
for i in range(1, n - 1):
	if new[i - 1] > new[i] and new[i + 1] > new[i]:
		c += 1
print(c)
print(*new)


n = int(input())
a = list(map(int, input().split()))
s = 0
if n % 2 == 0:
	s = n // 2 - 1
else:
	s = n // 2
i = 1
j = 1
a.sort()
print(s)
i1 = 1
while i1 <= n:
	if i1 % 2 != 0:
		print(a[n - i], end=' ')
		i += 1
	else:
		print(a[j - 1], end=' ')
		j += 1
	i1 += 1


def iinput():
	return int(input())

def finput():
	return float(input())

def linput():
	return [int(_) for _ in input().split()]
n = iinput()
a = linput()
a = sorted(a)
b = [0] * len(a)
b[0::2] = a[n // 2:]
b[1::2] = a[:n // 2]
ans = 0
for i in range(1, len(b) - 1):
	if b[i - 1] > b[i] < b[i + 1]:
		ans += 1
print(ans)
print(' '.join(list(map(str, b))))


def turn_to_int(s):
	return int(s)
n = int(input())
values = list(map(turn_to_int, input().split(' ')))
values.sort()
mid = n // 2
result = []
for i in range(mid):
	result.append(values[mid + i])
	result.append(values[i])
if n % 2 == 1:
	result.append(values[len(values) - 1])
count = 0
for i in range(1, n - 1, 2):
	if result[i] < result[i - 1] and result[i] < result[i + 1]:
		count += 1
print(count)
for i in result:
	print(i, end=' ')


n = int(input())
a = sorted([int(x) for x in input().split()])
max_number = n // 2 - (n % 2 == 0)
b = a[:max_number]
c = a[max_number:]
ending = c[len(b) - len(c):]
del c[len(b) - len(c):]
output = [None] * (len(b) + len(c))
output[::2] = c
output[1::2] = b
output += ending
print(max_number)
print(*output)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
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()
A.sort()
B = [-1] * N
j = 0
while j < N:
	B[j] = A.pop()
	j += 2
D = B.copy()
j = 1
C = A.copy()
while A:
	B[j] = A.pop()
	j += 2
if N % 2 == 0:
	j = 1
	while j < N - 1:
		if not B[j - 1] > B[j] < B[j + 1]:
			(B[j], B[-1]) = (B[-1], B[j])
			break
		j += 2
ans1 = 0
for i in range(1, N - 1):
	if B[i - 1] > B[i] < B[i + 1]:
		ans1 += 1
j = 1
C.reverse()
while C:
	D[j] = C.pop()
	j += 2
if N % 2 == 0:
	j = 1
	while j < N - 1:
		if not D[j - 1] > D[j] < D[j + 1]:
			(D[j], D[-1]) = (D[-1], D[j])
			break
		j += 2
ans2 = 0
for i in range(1, N - 1):
	if D[i - 1] > D[i] < D[i + 1]:
		ans2 += 1
if ans1 >= ans2:
	print(ans1)
	print(*B)
else:
	print(ans2)
	print(*D)


import math
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
if n == 1 or n == 2:
	print(0)
	s = ' '.join((str(i) for i in a))
	print(s)
else:
	a.sort()
	print(int(math.ceil(n / 2) - 1))
	if n % 2 == 0:
		b[0] = a[0]
	b[n - 1] = a[n - 1]
	for i in range(n - 2, -1, -2):
		if i != 0:
			b[i] = a[i - 1]
			b[i - 1] = a[i]
	s = ' '.join((str(i) for i in b))
	print(s)


n = int(input())
p = [int(x) for x in input().split()]
p.sort()
a = [None] * n
k = 0
if n % 2 == 1:
	for i in range(1, n, 2):
		a[i] = p[k]
		k += 1
	for i in range(0, n, 2):
		a[i] = p[k]
		k += 1
else:
	for i in range(1, n, 2):
		a[i] = p[k]
		k += 1
	for i in range(0, n, 2):
		a[i] = p[k]
		k += 1
ct = 0
for i in range(1, n - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ct += 1
print(ct)
for e in a:
	print(e, end=' ')
print()


n = int(input())
L = [int(x) for x in input().split()]
ar = L
r1 = 0
for i in range(1, n - 1):
	if L[i - 1] > L[i] and L[i] < L[i + 1]:
		r1 += 1
L.sort()
gap = (n - 1) // 2
l = L[:gap]
arr = []
for i in range(gap, n):
	if i >= n - gap:
		arr.append(l[0])
		arr.append(L[i])
		del l[0]
	else:
		arr.append(L[i])
if r1 > gap:
	print(r1)
	print(*ar)
else:
	print(gap)
	print(*arr)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n <= 2:
	print('0')
	for c in a:
		print(c, end=' ')
	quit()
b = a[:n // 2]
a = a[n // 2:]
c = []
for i in range(n // 2 + 1):
	if i <= n // 2 and n % 2 != 0:
		c.append(a[i])
	if i < n // 2 and n % 2 != 0:
		c.append(b[i])
	if i < n // 2 and n % 2 == 0:
		c.append(a[i])
	if i < n // 2 and n % 2 == 0:
		c.append(b[i])
ans = len(b) if n % 2 != 0 else len(b) - 1
print(ans)
for j in c:
	print(j, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
total = (n - 1) // 2
print(total)
asort = sorted(a)
j = 0
ans = [0] * len(a)
for i in range(len(a)):
	if i % 2 != 0:
		ans[i] = asort[j]
		j += 1
	else:
		ans[i] = asort[-j - 1]
print(*ans)


n = int(input())
a = sorted([int(x) for x in input().split()])
result = []
can_buy = n % 2
if can_buy == 1:
	can_buy = n // 2
else:
	can_buy = n // 2 - 1
first = a[:can_buy]
second = a[can_buy:]
for i in range(can_buy):
	result.extend([second[i], first[i]])
result.extend(second[-n + 2 * can_buy:])
print(can_buy)
for i in result:
	print(i, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr1 = arr[:n // 2]
arr2 = arr[n // 2:]
lst = [0] * n
for i in range(n // 2):
	arr2.insert(i + (i + 1), arr[i])
if n < 3:
	print(0)
elif n % 2 == 0:
	print(int(n / 2 - 1))
elif n % 2 != 0:
	print(n // 2)
print(*arr2)


R = lambda : map(int, input().split())
n = int(input())
lst = sorted(list(R()))
for i in range(n // 2):
	(lst[i * 2], lst[i * 2 + 1]) = (lst[i * 2 + 1], lst[i * 2])
print((n - 1) // 2)
print(*lst)


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')

def check(a, mid):
	try:
		ind = mid + 1
		for i in range(mid):
			if a[ind] > a[i] < a[ind + 1]:
				pass
			else:
				return False
			ind += 1
		return True
	except:
		return False
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	a.sort()
	mins = a[:n // 2]
	bigs = a[n // 2:]
	bigs.reverse()
	mins.reverse()
	res = [0 for i in range(n)]
	for i in range(n):
		if i % 2 == 0:
			res[i] = bigs.pop()
		else:
			res[i] = mins.pop()
	ans = 0
	for i in range(1, n - 1):
		if res[i - 1] > res[i] < res[i + 1]:
			ans += 1
	print(ans)
	print(*res)


n = int(input())
a = list(map(int, input().split(' ')))
if n % 2 == 0 and n != 2:
	number = n // 2 - 1
elif n % 2 != 0 and n != 1:
	number = n // 2
elif n == 2 or n == 1:
	number = 0
if n > 2:
	a.sort()
	p = a[:number]
	neig = a[number:]
	l = []
	for i in range(len(p)):
		l.append(neig[i])
		l.append(p[i])
	if n % 2 != 0:
		l.append(neig[-1])
	else:
		l.append(neig[-2])
		l.append(neig[-1])
	print(number)
	print(*l)
else:
	print(0)
	print(*a)


n = int(input())
li = list(map(int, input().split()))
li.sort()
ans = [-1] * n
(i, j, k) = (0, n - 1, 0)
while k < n and i <= j:
	ans[k] = li[j]
	k = k + 1
	j = j - 1
	if k < n:
		ans[k] = li[i]
		k = k + 1
		i = i + 1
cc = 0
for i in range(1, n - 2 + 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		cc += 1
print(cc)
for i in range(n):
	print(ans[i], end=' ')
print('')


n = int(input())
a = [int(i) for i in input().split()]
if n < 3:
	print(0)
	print(str(a)[1:-1].replace(', ', ' '))
else:
	amount = (n - 3) // 2 + 1
	if n % 2 == 1:
		b = [i for i in range(1, amount + 1)]
		c = [i for i in range(amount + 1, n + 1)]
	else:
		b = [i for i in range(1, amount + 2)]
		c = [i for i in range(amount + 2, n + 1)]
	(k1, k2) = (0, 0)
	a.sort()
	ca = [0] * n
	for i in range(n):
		if i % 2 == 0:
			ca[i] = c[k1]
			k1 += 1
		else:
			ca[i] = b[k2]
			k2 += 1
	d = []
	for i in range(n):
		d.append(a[ca[i] - 1])
	print(amount)
	print(str(d)[1:-1].replace(', ', ' '))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
small = arr[:len(arr) // 2]
large = arr[len(arr) // 2:]
i = 0
while i < len(arr):
	if i % 2 == 0:
		arr[i] = large[i // 2]
	else:
		arr[i] = small[i // 2]
	i += 1
print((len(arr) - 1) // 2)
for i in arr:
	print(i, end=' ')


def solve():
	arrsize = int(input())
	arr = list(map(int, input().split()))
	ptr = 0
	ans = []
	for i in arr:
		ans.append(i)
	ans = sorted(ans)
	i = 1
	while i < arrsize:
		arr[i] = ans[ptr]
		ptr += 1
		i += 2
	i = 0
	while i < arrsize:
		arr[i] = ans[ptr]
		ptr += 1
		i += 2
	count = 0
	for j in range(1, arrsize - 1):
		if arr[j] < arr[j + 1] and arr[j] < arr[j - 1]:
			count += 1
	print(count)
	print(*arr)
Testcase = 1
for _ in range(Testcase):
	solve()


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
hr = (n - 1) // 2
out = []
male = hr - 1
velke = n - 1
while male >= 0 and velke >= hr:
	out.append(a[velke])
	out.append(a[male])
	velke = velke - 1
	male = male - 1
if n % 2 == 1:
	out.append(a[hr])
else:
	out.append(a[hr + 1])
	out.append(a[hr])
malych = 0
for i in range(n - 2):
	if i % 2 != 0:
		continue
	if out[i] > out[i + 1] and out[i + 1] < out[i + 2]:
		malych += 1
print(malych)
print(*out)


rw = 1
for wewq in range(rw):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	print((n - 1) // 2)
	b = [0] * n
	b[0] = a[n - 1]
	b[n - 1] = a[n - 2]
	dor = n - 3
	des = 0
	for i in range(1, n - 1):
		if i % 2 == 0:
			b[i] = a[dor]
			dor -= 1
		else:
			b[i] = a[des]
			des += 1
	for i in b:
		print(i, end=' ')


n = int(input())
l = [int(s) for s in input().split()]
l.sort()
print((n - 1) // 2)
(i, j) = (0, n - 1)
while i < j:
	print(l[j], l[i], end=' ')
	j -= 1
	i += 1
if n % 2 != 0:
	print(l[i])


n = int(input())
P = sorted((int(w) for w in input().split(' ')))
(m, z) = divmod(n - 1, 2)
Q = []
for i in range(1, m + 1):
	Q.extend([P[-i], P[m - i]])
if z:
	Q.append(P[m + 1])
Q.append(P[m])
print(m)
print(' '.join((str(x) for x in Q)))


n = int(input())
array = [int(c) for c in input().split()]
ans = []
if n % 2 == 1:
	print(int((n - 2) // 2 + 1))
else:
	print(int((n - 2) / 2))
array.sort()
x = n - 1
for i in range(n // 2):
	ans.append(array[x])
	x -= (n - 1) // 2 + 1
	ans.append(array[x])
	x += (n - 1) // 2
if len(ans) != len(array):
	ans.append(array[n // 2])
print(' '.join([str(c) for c in ans]))


n = int(input())
s = input()
L = s.split()
for i in range(len(L)):
	L[i] = int(L[i])
myLen = len(L)
if myLen <= 2:
	print(0)
	print(s)
	quit()
L.sort()
gr = myLen // 2
cnt = gr if myLen % 2 else gr - 1
v = L[0]
for i in range(gr, myLen - 1):
	if L[i] > v < L[i + 1]:
		k = i
		break
else:
	print(0)
	print(s)
	quit()
shift = k - gr
L1 = []
for i in range(gr, gr + shift):
	L1.append(L[i])
nn = -shift + cnt
for i in range(nn):
	L1.append(L[k + i])
	L1.append(L[i])
L1.append(L[-1])
for i in range(shift):
	L1.append(L[i + nn])
if not myLen % 2:
	L1.append(L[cnt])
nSales = 0
for i in range(1, len(L1), 2):
	if i + 1 < len(L1) and L1[i - 1] > L1[i] < L1[i + 1]:
		nSales += 1
print(nSales)
L1 = [str(e) for e in L1]
print(' '.join(L1))


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
p = 0
new = []
for i in range(n // 2, n):
	new.append(l[i])
	if p < n // 2:
		new.append(l[p])
		p += 1
x = 0
for i in range(1, n - 1):
	if new[i] < new[i - 1] and new[i] < new[i + 1]:
		x += 1
print(x)
print(*new)


n = int(input())
l = sorted(list(map(int, input().split())))
x1 = l[:n // 2]
x2 = l[n // 2:]
i = 0
j = 0
ans = []
while i < len(x1) and j < len(x2):
	ans.append(x2[j])
	ans.append(x1[i])
	j = j + 1
	i = i + 1
if n % 2 == 1:
	ans.append(x2[j])
c = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
		c = c + 1
print(c)
print(*ans)


n = int(input())
price = list(map(int, input().split()))
price = sorted(price)
result = [0] * n
if n % 2 == 0:
	k = 0
	for j in range(1, n, 2):
		result[j] = price[k]
		k += 1
	for j in range(0, n - 1, 2):
		result[j] = price[k]
		k += 1
	print(n // 2 - 1)
	for value in result:
		print(value, end=' ')
if n % 2 != 0:
	k = 0
	for j in range(1, n - 1, 2):
		result[j] = price[k]
		k += 1
	for j in range(0, n, 2):
		result[j] = price[k]
		k += 1
	print((n - 1) // 2)
	for value in result:
		print(value, end=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort()
h = n // 2
l1 = l[:h]
l2 = l[h:]
ans = []
for i in range(n):
	if i % 2 == 0:
		ans.append(l2[i // 2])
	else:
		ans.append(l1[i // 2])
if n % 2 == 1:
	print(h)
else:
	print(h - 1)
print(*ans)


from sys import stdin, stdout, maxsize
import math
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))

def f(n, x):
	if n * (n + 1) * (4 * n - 1) // 6 <= x:
		return True
	return False
n = int(R())
a = RL(int)
a.sort()
ans = n * [-1]
ptr = 0
for i in range(1, n, 2):
	ans[i] = a[ptr]
	ptr += 1
for i in range(0, n, 2):
	ans[i] = a[ptr]
	ptr += 1
if n % 2:
	print(n // 2)
	print(*ans)
else:
	print(n // 2 - 1)
	print(*ans)


a = int(input())
b = sorted(list(map(int, input().split(' '))))
b1 = b[:len(b) // 2]
b2 = b[len(b) // 2:]
ans = []
ans.append(b2[0])
for i in range(len(b2) - 1):
	ans.append(b1[i])
	ans.append(b2[i + 1])
if len(b2) == len(b1):
	ans.append(b1[-1])
a = 0
for i in range(1, len(ans) - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		a += 1
print(a)
print(' '.join(list(map(str, ans))))


n = int(input())
array = list(map(int, input().split()))
aux = n * [None]
array.sort()
(small, large) = (0, n - 1)
flag = True
for j in range(n):
	if flag:
		aux[j] = array[large]
		large -= 1
	else:
		aux[j] = array[small]
		small += 1
	flag = bool(1 - flag)
res = 0
for i in range(n):
	if i == 0 or i == n - 1:
		continue
	if aux[i - 1] > aux[i] and aux[i] < aux[i + 1]:
		res += 1
print(res)
print(*aux)


T = 1
for Tid in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = []
	p1 = 0
	p2 = n // 2
	print((n - 1) // 2)
	for i in range(n):
		if i % 2 == 0:
			x = a[p2]
			p2 = p2 + 1
		else:
			x = a[p1]
			p1 = p1 + 1
		if i == n - 1:
			print(x)
		else:
			print(x, end=' ')


import math
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	print(0)
	print(*a)
else:
	left = 0
	right = n - 1
	ans = []
	a.sort()
	for i in range(n):
		if i % 2 == 0:
			ans.append(a[right])
			right -= 1
		else:
			ans.append(a[left])
			left += 1
	print(math.ceil((n - 2) / 2))
	print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [0] * n
if n % 2 == 1:
	j = 0
	for i in range(n):
		if i % 2 == 1:
			ans[i] = arr[j]
			j += 1
	for i in range(n):
		if ans[i] == 0:
			ans[i] = arr[j]
			j += 1
	a = 0
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
			a += 1
	print(a)
	print(' '.join((str(x) for x in ans)))
elif n == 2:
	print(0)
	print(' '.join((str(x) for x in arr)))
else:
	j = 0
	for i in range(2, n):
		if i % 2 == 0:
			ans[i] = arr[j]
			j += 1
	for i in range(n):
		if ans[i] == 0:
			ans[i] = arr[j]
			j += 1
	a = 0
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
			a += 1
	print(a)
	print(' '.join((str(x) for x in ans)))


import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
res = []
i = 0
j = n - 1
f = 0
while i <= j:
	if f == 0:
		res.append(lis[j])
		j -= 1
	else:
		res.append(lis[i])
		i += 1
	f = 1 - f
print((n + 1) // 2 - 1)
print(*res)


def algo(n, arr):
	if len(arr) == 1:
		print(0)
		print(*arr)
		return
	arr.sort()
	print((n + 1) // 2 - 1)
	lt = [None] * n
	(lt[0], lt[-1]) = (arr.pop(), arr.pop())
	j = 0
	for i in range(2, n - 1, 2):
		j -= 1
		lt[i] = arr[j]
	for i in range(1, n - 1, 2):
		j -= 1
		lt[i] = arr[j]
	print(*lt)
n = int(input())
arr = list(map(int, input().split()))
ans = algo(n, arr)


n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = A[0:n // 2]
C = A[n // 2:]
a = []
for i in range(len(B)):
	a.append(C[i])
	a.append(B[i])
if n % 2 != 0:
	a.append(C[-1])
ans = 0
for i in range(1, n - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ans += 1
print(ans)
for x in a:
	print(x, end=' ')
print()


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = [0] * n
c = 0
for i in range(1, n, 2):
	b[i] = a[c]
	c += 1
for i in range(0, n, 2):
	b[i] = a[c]
	c += 1
s = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		s += 1
print(s)
print(*b)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
p = -1
s = 0
for j in range(n):
	if j % 2 == 0:
		l.append(a[p])
		p -= 1
	else:
		l.append(a[s])
		s += 1
if n % 2 != 0:
	print(n // 2)
	print(*l)
else:
	print(n // 2 - 1)
	print(*l)


from itertools import *
(n, a) = (int(input()), [int(x) for x in input().split()])
print(n // 2 - (n % 2 == 0))
s = sorted(a)[::-1]
(a, b) = (s[:n // 2 + n % 2], s[n // 2 + n % 2:])
for (c, v) in zip(a, b):
	print(c, v, end=' ')
(c, v) = (len(a), len(b))
if c > v:
	print(a[c - 1])
elif v > c:
	print(b[v - 1])


from math import *
from random import *
from bisect import *
from math import *
n = int(input())
mas = sorted(list(map(int, input().split())))
otv = [0 for i in range(n)]
nxt = 0
for i in range(1, n, 2):
	otv[i] = mas[nxt]
	nxt += 1
for i in range(0, n, 2):
	otv[i] = mas[nxt]
	nxt += 1
res = 0
for i in range(1, n - 1):
	if otv[i] < otv[i + 1] and otv[i] < otv[i - 1]:
		res += 1
print(res)
print(' '.join(map(str, otv)))


def swap(x, i):
	(x[i], x[i + 1]) = (x[i + 1], x[i])
	return x
n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
ans = n / 2
if ans.is_integer():
	print(int(ans - 1))
else:
	print(int(ans))
for i in range(0, n - 2, 2):
	swap(x, i)
print(*x)


n = int(input())
m = list(map(int, input().split()))
m.sort()
if n % 2:
	a = [0] * n
	for i in range(n // 2):
		a[2 * i + 1] = m[i]
	j = 0
	for i in range(n // 2, n):
		a[j] = m[i]
		j += 2
	c = 0
	i = 1
	while i < n:
		if a[i] < a[i - 1] and a[i] < a[i + 1]:
			c += 1
		i += 2
	print(c)
	print(*a)
else:
	a = [0] * n
	for i in range(n // 2):
		a[2 * i] = m[i]
	j = 0
	for i in range(n // 2, n):
		a[j + 1] = m[i]
		j += 2
	c = 0
	i = 2
	while i < n:
		if a[i] < a[i - 1] and a[i] < a[i + 1]:
			c += 1
		i += 2
	b = [0] * n
	for i in range(n // 2):
		b[2 * i + 1] = m[i]
	j = 0
	for i in range(n // 2, n):
		b[j] = m[i]
		j += 2
	d = 0
	i = 1
	while i < n - 1:
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			d += 1
		i += 2
	if c > d:
		print(c)
		print(*a)
	else:
		print(d)
		print(*b)


import math
a = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [0] * len(arr)
even = [arr[i] for i in range(len(arr) // 2, len(arr))]
odd = [arr[i] for i in range(0, len(arr) // 2)]
i = 0
for j in even:
	ans[i] = j
	i = i + 2
i = 1
for j in odd:
	ans[i] = j
	i = i + 2
print(math.ceil(a / 2) - 1)
print(' '.join(map(str, ans)))


from sys import *
input = stdin.readline
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = [0] * n
	k = n // 2
	j = k
	for i in range(0, n, 2):
		b[i] = a[j]
		j += 1
	j = 0
	for i in range(1, n, 2):
		b[i] = a[j]
		j += 1
	ans = 0
	for i in range(1, n - 1):
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			ans += 1
	stdout.write(str(ans) + '\n')
	print(*b)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n % 2 == 0:
		ans = n // 2 - 1
	else:
		ans = n // 2
	print(ans)
	i = 0
	j = n - 1
	c = 0
	while i <= j:
		if c % 2 != 0:
			print(a[i], end=' ')
			i += 1
		else:
			print(a[j], end=' ')
			j -= 1
		c += 1
	print()
main()


def answer(n, A):
	A.sort()
	x = (n - 1) // 2
	a = A[:x]
	b = A[x:]
	ans = []
	i = 0
	j = 0
	while i < len(a):
		ans.append(b[j])
		ans.append(a[i])
		i += 1
		j += 1
	ans += b[j:]
	return (x, ans)
n = int(input())
A = list(map(int, input().split()))
(x, ans) = answer(n, A)
print(x)
print(*ans)


n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
	print(0)
	print(a[0])
else:
	a.sort()
	i = 0
	j = n - 1
	k = n - 1
	k //= 2
	print(k)
	while i != j:
		print(a[j], end=' ')
		j -= 1
		if i == j:
			print(a[i])
			break
		print(a[i], end=' ')
		i += 1
		if i == j:
			print(a[i])
			break


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(0, n // 2):
	b.append(a[i + n // 2])
	b.append(a[i])
if n < 3:
	print(0)
	print(*a)
elif n % 2 != 0:
	b.append(a[n - 1])
	print(n // 2)
	print(*b)
else:
	print(n // 2 - 1)
	print(*b)


import math
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
ans = (n - 1) // 2
print(ans)
r = n - 1
l = 0
lis = []
while l <= r:
	lis.append(arr[r])
	r -= 1
	if l <= r:
		lis.append(arr[l])
		l += 1
print(*lis)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = n // 2
if n % 2 == 0:
	ans -= 1
cnt = 0
for i in range(n):
	if i % 2 == 1:
		t = a[i]
		a[i] = a[i - 1]
		a[i - 1] = t
		cnt += 1
	if cnt == ans:
		break
print(ans)
for x in a:
	print(x, end=' ')


import math
n = int(input())
arr = [int(item) for item in input().split()]
arr.sort()
brr = []
i = 0
j = n // 2
while j < n:
	brr.append(arr[j])
	j = j + 1
	if i < n // 2:
		brr.append(arr[i])
		i = i + 1
print(math.floor((n - 1) / 2))
print(*brr)


def iinput():
	return int(input())

def finput():
	return float(input())

def linput():
	return [int(_) for _ in input().split()]
n = iinput()
a = linput()
ans = (n - 1) // 2
print((n - 1) // 2)
a = sorted(a)
a1 = a[:n // 2]
a2 = a[n // 2:]
for (x1, x2) in zip(a1, a2):
	print(x2, end=' ')
	print(x1, end=' ')
if len(a2) > len(a1):
	print(a2[-1])
else:
	print()


import sys

def input():
	return sys.stdin.readline().rstrip()
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [0] * n
j = 0
for i in range(1, n - 1, 2):
	ans[i] = arr[j]
	j += 1
if n % 2 == 0:
	ans[n - 1] = arr[j]
	j += 1
for i in range(0, n, 2):
	ans[i] = arr[j]
	j += 1
ans_count = 0
for i in range(1, n - 1, 2):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		ans_count += 1
print(ans_count)
print(' '.join(map(str, ans)))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n < 3:
	print(0)
	for x in arr:
		print(x, end=' ')
	print()
else:
	ans = n // 2
	if n % 2 == 0:
		ans -= 1
	print(ans)
	i = 0
	j = n - 1
	ans = list()
	while i <= j:
		ans.append(arr[j])
		j -= 1
		if i < j:
			ans.append(arr[i])
			i += 1
		else:
			if i == j:
				ans.append(arr[j])
			break
	for x in ans:
		print(x, end=' ')
	print()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def solve():
	n = int(inp())
	ar = lis()
	ar.sort()
	k = (n - 1) // 2
	ans = []
	i = 0
	j = n - 1
	while i < j:
		ans.append(ar[j])
		ans.append(ar[i])
		i += 1
		j -= 1
	if i == j:
		ans.append(ar[i])
	print(k)
	print(*ans)
solve()


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
l = []
i = 0
j = -1
if n % 2 == 0:
	while i < n // 2 and j < n // 2:
		l.append(a[j])
		l.append(a[i])
		i += 1
		j -= 1
else:
	while i <= n // 2 and j < n // 2:
		l.append(a[j])
		l.append(a[i])
		i += 1
		j -= 1
	del l[-1]
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
for i in range(len(l)):
	print(l[i], end=' ')
print()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, nums):
	nums.sort()
	mid = len(nums) // 2
	ret = []
	if len(nums) % 2 == 1:
		for (x, y) in zip(nums[:mid], nums[mid + 1:]):
			ret.append(y)
			ret.append(x)
		ret.append(nums[mid])
	else:
		for (x, y) in zip(nums[:mid][::-1], nums[mid:][::-1]):
			ret.append(y)
			ret.append(x)
	count = 0
	for i in range(1, N - 1):
		if ret[i - 1] > ret[i] and ret[i] < ret[i + 1]:
			count += 1
	return str(count) + '\n' + ' '.join(map(str, ret))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


def proA(arr):
	arr.sort()
	lst = [0] * len(arr)
	i = 1
	j = 0
	ans = 0
	while i < len(arr):
		lst[i] = arr[j]
		j += 1
		i = i + 2
	k = j
	for i in range(len(lst)):
		if lst[i] == 0:
			lst[i] = arr[k]
			k += 1
	for i in range(1, len(lst) - 1):
		if lst[i - 1] > lst[i] < lst[i + 1]:
			ans += 1
	print(ans)
	for i in lst:
		print(i, end=' ')
t = int(input())
arr = list(map(int, input().split()))
proA(arr)


from sys import stdin
input = stdin.readline
n = int(input())
a = sorted(map(int, input().split()))
b = [0] * n
idx = {}
cnt = {}
for i in range(n):
	idx[a[i]] = i + 1
	cnt[a[i]] = cnt.get(a[i], 0) + 1
c = 0
for i in range(n):
	if i:
		if a[i] == a[i - 1]:
			c += 1
		else:
			c = 1
	else:
		c = 1
	if i + 2 > n - idx[a[i]] + min(idx[a[i]] - cnt[a[i]], cnt[a[i]] - c):
		m = i
		break
print(m)
p = m
vis = [0] * n
for i in range(n):
	if i < m:
		b[2 * i + 1] = a[i]
	elif i < 2 * m + 1:
		if (i - m) * 2 == n - 1:
			b[(i - m) * 2] = a[-1]
		else:
			while a[p] == b[(i - m) * 2 + 1]:
				p += 1
			b[(i - m) * 2] = a[p]
			vis[p] = 1
			p += 1
	else:
		for j in range(m, n):
			if not vis[j]:
				b[i] = a[j]
				i += 1
		break
print(*b)


import math

def solution(n, a):
	a.sort()
	low = 0
	(r1, r2) = (math.ceil((n - 2) / 2), [0] * n)
	for i in range(n):
		if i <= r1 - 1 and a[i] == a[i + n // 2 + 1]:
			low += 1
		if i % 2:
			r2[i] = a[i // 2]
		else:
			r2[i] = a[n // 2 + i // 2]
	return [r1 - low, r2]
n = int(input())
a = list(map(int, input().split(' ')))
x = solution(n, a)
print(x[0])
print(*x[1])


def birth(n, arr):
	if n == 2:
		print(0)
		return ' '.join(list(map(str, arr)))
	lower = len(arr) // 2
	arr = sorted(arr)
	small = arr[:lower]
	large = arr[lower:]
	blanck = []
	for i in range(lower):
		blanck.append(large[i])
		blanck.append(small[i])
	if n % 2 != 0:
		blanck.append(arr[-1])
	else:
		lower -= 1
	print(lower)
	blanck = list(map(str, blanck))
	return ' '.join(blanck)
n = int(input())
print(birth(n, list(map(int, input().strip().split()))))


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)

def main():
	n = int(input())
	a = sorted([int(i) for i in input().split()])
	q = []
	for i in range(n // 2 + n % 2):
		q.extend([a[i + n // 2], a[i]])
	if n % 2 == 1:
		q.pop()
	k = 0
	for i in range(1, n - 1):
		if q[i - 1] > q[i] < q[i + 1]:
			k += 1
	print(k)
	print(*q)
main()


n = input()
n = int(n)

def solve(n, arr):
	arr.sort()
	if n % 2 == 1:
		k = n // 2
		small = arr[:k]
		large = arr[k:]
		ans = [0 for i in range(n)]
		cpk = True
		cnt = 1
		while cnt <= n:
			if cpk:
				ans[-cnt] = large.pop()
				cpk = False
			else:
				ans[-cnt] = small.pop()
				cpk = True
			cnt += 1
		print(k)
		print(*ans)
	else:
		k = n // 2
		small = arr[:k]
		large = arr[k:]
		ans = [0 for i in range(n)]
		cpk = True
		cnt = 1
		while cnt <= n:
			if cpk:
				ans[-cnt] = large.pop()
				cpk = False
			else:
				ans[-cnt] = small.pop()
				cpk = True
			cnt += 1
		print(k - 1)
		print(*ans)
arr = list(map(int, input().split()))
solve(n, arr)


def birthday_sage(arr, n):
	if len(arr) < 3:
		return (0, arr)
	op = []
	cnt = 0
	arr.sort()
	while arr:
		value = arr.pop()
		op.append(value)
		if arr:
			cube = arr.pop(0)
			cnt += 1
			op.append(cube)
	return (cnt, op)

def birthday_sage_efficient(arr, n):
	arr.sort()
	for i in range(0, n - 1, 2):
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	return ((n - 1) // 2, arr)
n = int(input())
arr = list(map(int, input().split()))
(cnt, arr) = birthday_sage_efficient(arr, n)
print(cnt)
print(' '.join((str(c) for c in arr)))


n = int(input())
prices = [int(i) for i in input().split()]
ordenado = sorted(prices)
print((n - 1) // 2)
for i in range(n):
	if i < n // 2:
		prices[2 * i + 1] = ordenado[i]
	else:
		prices[(i - n // 2) * 2] = ordenado[i]
print(*prices)


input()
s = [int(i) for i in input().split()]
s.sort()
for i in range(1, len(s), 2):
	(s[i], s[i - 1]) = (s[i - 1], s[i])
print((len(s) - 1) // 2)
print(*s)


n = int(input().strip())
a = list(map(int, input().strip().split()))
a.sort()
i = n - 1
j = 0
print((n - 1) // 2)
while i - j > j:
	print(a[i - j], end=' ')
	print(a[j], end=' ')
	j += 1
if n % 2 == 1:
	print(a[n // 2])


from sys import stdin
input = stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
le = 1
pr = (n - 1) // 2
if n <= 2:
	print(0)
	print(*l)
else:
	while le != pr:
		mid = (le + pr + 1) // 2
		dasie = True
		for i in range(mid):
			if l[mid - i - 1] == l[n - 1 - i] or l[mid - i - 1] == l[n - 2 - i]:
				dasie = False
		if dasie:
			le = mid
		else:
			pr = mid - 1
	m = pr
	if l[0] == l[-2]:
		print(0)
		print(*l)
	else:
		print(m)
		odp = []
		duze = n - 1
		male = 0
		for i in range(2 * m):
			if i % 2 == 0:
				odp.append(l[duze])
				duze -= 1
			else:
				odp.append(l[m - 1 - male])
				male += 1
		dlug = 2 * m
		i = m
		pupa = []
		while dlug < n:
			pupa.append(l[i])
			dlug += 1
			i += 1
		pupa.reverse()
		odp += pupa
		print(*odp)


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	n = int(input())
	a = [int(o) for o in input().split()]
	a.sort()
	ans = [0] * n
	j = 0
	for i in range(n):
		if i % 2 != 0:
			ans[i] = a[j]
			j += 1
	for i in range(n):
		if i % 2 == 0:
			ans[i] = a[j]
			j += 1
	lol = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			lol += 1
	print(lol)
	print(*ans)
sync_with_stdio(False)
main()


import functools
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

@functools.lru_cache(maxsize=128)
def main():
	n = ii()
	l = li()
	l.sort()
	ll = []
	ll.append(l[-1])
	i = 0
	j = n - 2
	s = 0
	while i < j:
		ll.append(l[i])
		ll.append(l[j])
		i += 1
		j -= 1
		if ll[-2] < ll[-1] and ll[-3] > ll[-2]:
			s += 1
	if i == j:
		ll.append(l[i])
		if ll[-2] < ll[-1] and ll[-3] > ll[-2]:
			s += 1
	print(s)
	print(*ll)
import os, 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')
from math import gcd

def find(l):
	c = 0
	for i in range(len(l)):
		if l[i] > 1:
			c = i
			return c
	else:
		return None
main()

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = [1]
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

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

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True


n = int(input())
arr = list(map(int, input().split(' ')))
arr = list(sorted(arr))
p = n // 2
resultarr = []
i = 0
while p < n:
	resultarr.append(arr[p])
	if i < n // 2:
		resultarr.append(arr[i])
	i += 1
	p += 1
result = 0
for i in range(1, len(arr) - 1):
	if resultarr[i - 1] > resultarr[i] and resultarr[i + 1] > resultarr[i]:
		result += 1
print(result)
print(' '.join(list(map(str, resultarr))))


n = int(input())
ks = 0
a = list(map(int, input().split()))
a.sort()
mmn = [0] * n
cad = 0
for j in range(1, n, 2):
	mmn[j] = a[cad]
	cad += 1
while False:
	break
for j in range(0, n, 2):
	mmn[j] = a[cad]
	while False:
		break
	cad += 1
lamp = 0
lonm = 0
for j in range(1, n - 1):
	if mmn[j - 1] > mmn[j] and mmn[j + 1] > mmn[j]:
		lamp += 1
print(lamp)
while False:
	break
for j in mmn:
	print(j, end=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = []
for i in range(n // 2):
	a.append(l[-i - 1])
	a.append(l[i])
if n % 2:
	a.append(l[n // 2])
print((n - 1) // 2)
for i in a:
	print(i, end=' ')


from math import ceil
n = int(input())
l = list(map(int, input().split()))
l.sort()
if len(l) == 1:
	print(0)
	print(*l)
	exit()
ans = [0] * n
c = 0
for i in range(1, n, 2):
	ans[i] = l[c]
	c += 1
for i in range(0, n, 2):
	ans[i] = l[c]
	c += 1
final = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		final += 1
print(final)
print(*ans)


from sys import stdin
from math import ceil, gcd
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.sort()
ans = [0] * n
j = n - 1
for i in range(0, n, 2):
	ans[i] = arr[j]
	j -= 1
j = 0
if n % 2 == 0:
	for i in range(n - 3, -1, -2):
		ans[i] = arr[j]
		j += 1
	ans[n - 1] = arr[j]
else:
	for i in range(n - 2, -1, -2):
		ans[i] = arr[j]
		j += 1
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = len(a) // 2
f = a[:l]
s = a[l:]
t = [0] * len(a)
ind = 0
for i in range(len(s)):
	t[ind] = s[i]
	ind += 2
ind = 1
for i in range(len(f)):
	t[ind] = f[i]
	ind += 2
x = 0
for i in range(1, len(t) - 1):
	if t[i] < t[i + 1] and t[i] < t[i - 1]:
		x += 1
print(x)
print(' '.join([str(i) for i in t]))


from collections import deque
from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	aa.sort()
	res = []
	i = 0
	j = n - 1
	while i < j:
		res.append(aa[j])
		res.append(aa[i])
		j -= 1
		i += 1
	if i == j:
		res.append(aa[i])
	print((n - 1) // 2)
	print(' '.join(map(str, res)))
main()


from sys import stdin, stdout
import bisect

def main():
	n = int(input())
	a = sorted(list(map(int, stdin.readline().split())))
	(i, j) = (n // 2 - 1, n // 2 + 1)
	ans = []
	ans.append(a[n // 2])
	while i >= 0 or j < n:
		if i >= 0:
			ans.append(a[i])
			i -= 1
		if j < n:
			ans.append(a[j])
			j += 1
	print((n - 1) // 2)
	print(' '.join(map(str, ans)))
main()


def process():
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	if n % 2 == 1:
		print(n // 2)
	else:
		print(n // 2 - 1)
	for i in range(0, n, 2):
		if i != n - 1 and i + 1 != n - 1 and (i + 1 <= n - 1):
			(li[i], li[i + 1]) = (li[i + 1], li[i])
	li = [str(i) for i in li]
	return ' '.join(li)
tests = 1
for i in range(tests):
	print(process())


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	ls = get_list()
	temp = list(sorted(ls))
	start = 0
	if n < 3:
		print(0)
		print(*ls)
	else:
		ans = [0] * n
		for i in range(1, n, 2):
			ans[i] = temp[start]
			start += 1
		for i in range(0, n, 2):
			ans[i] = temp[start]
			start += 1
		print((n - 1) // 2)
		print(*ans)

def main():
	solve()
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


n = int(input())
a = list(map(int, input().split()))
k = [0] * n
a.sort()
l = 0
for i in range(1, n, 2):
	k[i] = a[l]
	l += 1
for i in range(0, n, 2):
	k[i] = a[l]
	l += 1
if n % 2 != 0:
	print(n // 2)
else:
	print(n // 2 - 1)
print(*k)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque

def main():
	(n, *a) = map(int, read().split())
	a.sort()
	a = deque(a)
	res = deque()
	flag = True
	while a:
		if flag:
			res.append(a.pop())
			flag ^= 1
		else:
			res.append(a.popleft())
			flag ^= 1
	if n & 1:
		print(n // 2)
	else:
		print((n - 1) // 2)
	print(*res, sep=' ')
main()


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
out = []
i = 0
j = n // 2
while i < n // 2 and j < n:
	out.append(ai[j])
	out.append(ai[i])
	j += 1
	i += 1
if n % 2:
	out.append(ai[n - 1])
ct = 0
for i in range(1, n - 1):
	if out[i] < out[i - 1] and out[i] < out[i + 1]:
		ct += 1
print(ct)
print(*out)


def GetInput():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	return (n, a)

def Sol(n, a):
	num_cheap = (n - 1) // 2
	b = a.copy()
	for i in range(1, n, 2):
		(b[i - 1], b[i]) = (b[i], b[i - 1])
	return (num_cheap, b)
(n, a) = GetInput()
(num_cheap, b) = Sol(n, a)
print(num_cheap)
for x in b:
	print(x, end=' ')


import sys
n = int(input())
A = sorted(list(map(int, input().split())))
if n % 2 == 1:
	nans = n // 2
	Ans = A
else:
	nans = (n - 1) // 2
	Ans = A[:-1]
print(nans)
if nans == 0:
	print(*A)
	sys.exit()
nl = len(Ans)
Amx = Ans[nl // 2:]
Amn = Ans[:nl // 2]
output = [Amx[0]]
Amx = Amx[1:]
for i in range(len(Amx)):
	output.append(Amn[i])
	output.append(Amx[i])
if len(output) != n:
	output.append(A[-1])
print(*output)


import heapq as hq
from heapq import heappop, heappush
from collections import deque, defaultdict, Counter
from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def inlt():
	return list(map(int, stdin.readline().split()))

def insr():
	return list(stdin.readline().strip())

def invr():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def subset_sum_count(arr, n, sum):
	dp = [[0 for _ in range(sum + 1)] for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(sum + 1):
			if j == 0:
				dp[i][j] = 1
			elif arr[i - 1] <= j:
				dp[i][j] = dp[i - 1][j - arr[i - 1]] + dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[n][sum]

def binary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		mi = lo + (hi - lo) / 2
		if func(mi):
			hi = mi
		else:
			lo = mi
	return (lo + hi) / 2

def ternary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		lo_third = lo + (hi - lo) / 3
		hi_third = hi - (hi - lo) / 3
		if func(lo_third) < func(hi_third):
			lo = lo_third
		else:
			hi = hi_third
	return (lo + hi) / 2

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def discrete_ternary_search(func, lo, hi):
	while lo <= hi:
		lo_third = lo + (hi - lo) // 3
		hi_third = lo + (hi - lo) // 3 + (1 if 0 < hi - lo < 3 else (hi - lo) // 3)
		if func(lo_third) < func(hi_third):
			lo = lo_third + 1
		else:
			hi = hi_third - 1
	return lo
	return -1

def right_rotate(a, s):
	return a[s:] + a[:s]

def dec_to_bin(x):
	return int(bin(x)[2:])

def str_to_integer_list(n):
	a = []
	for i in range(len(n)):
		a.append(int(n[i]))
	return a

def list_to_str(l):
	s = ''
	for i in l:
		s += str(i)
	return s

def dijkstra(s, N, E):
	visited = set()
	dist = {}
	for i in range(1, N + 1):
		dist[i] = 1 << 29
	queue = [(dist[i], i) for i in range(1, N + 1)]
	hq.heappush(queue, (0, s))
	dist[s] = 0
	while queue:
		(d, u) = hq.heappop(queue)
		if u in visited:
			continue
		for t in E[u]:
			(v, r) = t
			if dist[v] > d + r:
				dist[v] = d + r
				hq.heappush(queue, (dist[v], v))
		visited.add(u)
	return dist

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def dijkstra(n, graph, start):
	(dist, parents) = ([float('inf')] * n, [-1] * n)
	dist[start] = 0
	queue = [(0, start)]
	while queue:
		(path_len, v) = heappop(queue)
		if path_len == dist[v]:
			for (w, edge_len) in graph[v]:
				if edge_len + path_len < dist[w]:
					(dist[w], parents[w]) = (edge_len + path_len, v)
					heappush(queue, (edge_len + path_len, w))
	return (dist, parents)

def path(start, end, parent):
	path = [end]
	while path[-1] != start:
		path.append(parent[path[-1]])
	path.reverse()
	return path

def bfs(graph, start, goal):
	if start == goal:
		return [start]
	visited = {start}
	queue = deque([(start, [])])
	while queue:
		(current, path) = queue.popleft()
		visited.add(current)
		for neighbor in graph[current]:
			if neighbor == goal:
				return path + [current, neighbor]
			if neighbor in visited:
				continue
			queue.append((neighbor, path + [current]))
			visited.add(neighbor)
	return None

def fillPrefixSum(arr, n, prefixSum):
	prefixSum[0] = arr[0]
	for i in range(1, n):
		prefixSum[i] = prefixSum[i - 1] + arr[i]

def check(a, ind, d1):
	beg = a[:ind + 1]
	end = a[ind + 1:]
	d = []
	c = 0
	for i in end:
		if i - d1 in beg:
			c += 1
	return c
import os
import sys
from io import BytesIO, IOBase

def DecimalToBinary(n):

	def helper(n):
		if n == 0:
			return ''
		else:
			if n % 2 == 1:
				binaryDigit = '1'
			else:
				binaryDigit = '0'
			return helper(n // 2) + binaryDigit
	if n == 0:
		result = '0'
	else:
		result = helper(n)
	return result

def p(board):
	for i in range(8):
		s = ''
		for j in range(8):
			s += board[i][j]
		print(s)

def binaryToDecimal(n):
	return int(n, 2)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def solve(a, b):
	x = DecimalToBinary(a)
	y = DecimalToBinary(b)
	z = x + y
	l = y + x
	r = binaryToDecimal(z) - binaryToDecimal(l)
	return r

def mostFrequent(arr, n):
	arr.sort()
	max_count = 1
	res = arr[0]
	curr_count = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			curr_count += 1
		else:
			if curr_count > max_count:
				max_count = curr_count
				res = arr[i - 1]
			curr_count = 1
	if curr_count > max_count:
		max_count = curr_count
		res = arr[n - 1]
	return res
from bisect import bisect_right, bisect_left

def lds(arr, n):
	lds = [0] * n
	max = 0
	for i in range(n):
		lds[i] = 1
	for i in range(1, n):
		for j in range(i):
			if arr[i] < arr[j] and lds[i] < lds[j] + 1:
				lds[i] = lds[j] + 1
	for i in range(n):
		if max < lds[i]:
			max = lds[i]
	return max
import math

def prefix(a):
	pre = []
	pre.append(a[0])
	for i in range(1, len(a)):
		pre.append(pre[i - 1] + a[i])
	return pre

def solve(n, x, size):
	res = 10000000
	if n == 0:
		return 0
	if size == 0:
		return 0
	for i in x:
		res = 1 + min(res, solve(n - i, x, size - 1))
		return res

def main():
	n = inp()
	a = inlt()
	a.sort(reverse=True)
	if n > 3:
		y = (n - 2) // 2
		x = n - 2 - y
		res = []
		res[:] = [a[0]] + a[2:2 + y] + [a[1]]
		k = 1
		for i in range(2 + y, n):
			res.insert(k, a[i])
			k += 2
		print(x)
		print(*res)
	elif n <= 2:
		print(0)
		print(*a)
	elif n == 3:
		(a[1], a[2]) = (a[2], a[1])
		print(1)
		print(*a)
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())
price = input()
if n <= 2:
	print(0)
	print(price)
else:
	price = price.split()
	price = [int(i) for i in price]
	price.sort()
	res1 = n // 2
	res2 = []
	for i in range(res1):
		res2.append(str(price[res1 + i]))
		res2.append(str(price[i]))
	if n % 2 == 1:
		res2.append(str(price[-1]))
	if n % 2 == 0:
		res1 -= 1
	print(res1)
	print(' '.join(res2))


n = int(input())
a = sorted([int(i) for i in input().split()])
if n < 3:
	print(0)
	for i in range(n):
		print(a[i], end=' ')
else:
	print((n - 1) // 2)
	b = []
	i = 0
	j = n - 1
	while i <= j:
		b.append(a[j])
		j -= 1
		if i <= j:
			b.append(a[i])
			i += 1
	for i in range(n):
		print(b[i], end=' ')


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2 == 1:
		print(n // 2)
		l.sort()
		m = [0] * n
		ind = 0
		for i in range(1, n, 2):
			m[i] = l[ind]
			ind += 1
		for i in range(0, n, 2):
			m[i] = l[ind]
			ind += 1
		print(' '.join((str(x) for x in m)))
	else:
		print(n // 2 - 1)
		l.sort()
		m = [0] * n
		ind = 0
		for i in range(1, n, 2):
			m[i] = l[ind]
			ind += 1
		for i in range(0, n, 2):
			m[i] = l[ind]
			ind += 1
		print(' '.join((str(x) for x in m)))


from math import ceil
n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n - 1
ans = []
while i <= j:
	ans.append(l[j])
	ans.append(l[i])
	i += 1
	j -= 1
if n % 2 != 0:
	ans.pop()
print(ceil((n - 1) // 2))
print(*ans)


from math import ceil
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	print('0')
	for e in a:
		print(e, end=' ')
	print()
else:
	a = sorted(a)
	a_1 = a[:ceil((len(a) - 2) / 2)]
	a_2 = a[ceil((len(a) - 2) / 2):-2]
	print(ceil((len(a) - 2) / 2))
	print(a[-2], end=' ')
	for i in range(len(a_2)):
		print(a_1[i], end=' ')
		print(a_2[i], end=' ')
	if len(a_2) < len(a_1):
		print(a_1[-1], end=' ')
	print(a[-1])


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

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

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

def invr():
	return map(int, input().split())
(n, l) = (inp(), inlt())
res = []
l.sort()
for i in range(n // 2):
	if i + n // 2 < n:
		res.append(l[i + n // 2])
		res.append(l[i])
if n % 2:
	res.append(l[-1])
	print(n // 2)
else:
	print(n // 2 - 1)
print(' '.join([str(x) for x in res]))


n = int(input())
ar = sorted(list(map(int, input().split())))
ar1 = [0] * n
i = 0
j = 1
while j < n:
	ar1[j] = ar[i]
	i += 1
	j += 2
j = 0
while j < n:
	ar1[j] = ar[i]
	j += 2
	i += 1
count = 0
for i in range(1, n - 1):
	if ar1[i] < ar1[i - 1] and ar1[i] < ar1[i + 1]:
		count += 1
print(count)
print(*ar1)


import sys
import math
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
X = N // 2
it1 = iter(A[:X])
it2 = iter(A[X:])
x = True
y = True
ans = []
while x or y:
	try:
		ans.append(next(it2))
	except StopIteration:
		x = False
	try:
		ans.append(next(it1))
	except StopIteration:
		y = False
count = 0
for i in range(1, N - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(' '.join(map(str, ans)))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans1 = (n - 1) // 2
	ans = []
	t = 1
	ans.append(l[-t])
	t += 1
	for i in range((n - 1) // 2):
		ans.append(l[i])
		ans.append(l[-t])
		t += 1
	for i in range(n - len(ans)):
		ans.append(l[-t])
		t += 1
	print(ans1)
	print(*ans)


x = int(input())
l = sorted(list(map(int, input().split())))
i = 0
ans = 0
while i + 2 < x:
	if l[i] < l[i + 1] and l[i] < l[i + 2]:
		ans += 1
		(l[i], l[i + 1]) = (l[i + 1], l[i])
		i += 2
	else:
		i += 1
print(ans)
for num in l:
	print(num, end=' ')


n = int(input())
A = sorted(list(map(int, input().split())))
print(n // 2 - 1 + (n & 1))
for (x, y) in zip(A[n // 2:], A[:n // 2]):
	print(x, y, end=' ')
if n % 2 != 0:
	print(A[-1])
else:
	print()


n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
a.sort()
middle = int(n / 2)
j = n - 1
for i in range(n - 1, middle - 1, -1):
	ans[j] = a[i]
	j -= 2
j = 0
if n % 2 == 1:
	j = 1
for i in range(middle):
	ans[j] = a[i]
	j += 2
print((n - 1) // 2)
print(*ans)


import io, os, sys

def print(*args, sep=' ', end='\n'):
	string = sep.join(map(str, args)) + end
	sys.stdout.write(string)

def debug(*args, sep=' ', end='\n'):
	string = 'Debug: ' + sep.join(map(str, args)) + end
	sys.stderr.write(string)
N = int(input())
A = list(map(int, input().split()))
print((N - 1) // 2)
A.sort()
B = [None] * N
i = 1
for elt in A:
	if i >= N:
		i = 0
	B[i] = elt
	i += 2
print(' '.join(map(str, B)))


import sys
input = sys.stdin.readline
from math import gcd
from functools import reduce

def read():
	N = int(input().strip())
	A = list(map(int, input().strip().split()))
	return (N, A)

def solve(N, A):
	A.sort()
	B = [0] * N
	for i in range(N // 2):
		j = 1 + i * 2
		B[j] = A[i]
	for i in range(N // 2 + N % 2):
		j = 0 + i * 2
		B[j] = A[i + N // 2]
	ans = 0
	for i in range(1, N - 1):
		if B[i - 1] > B[i] and B[i] < B[i + 1]:
			ans += 1
	print(ans)
	print(*B)
T = 1
for t in range(T):
	inputs = read()
	solve(*inputs)


n = int(input())
l = list(map(int, input().split()))
l.sort()
duze = 0
male = 0
print((n - 1) // 2)
odp = []
for i in range(n):
	if i % 2 == 0:
		odp.append(l[n - 1 - duze])
		duze += 1
	else:
		odp.append(l[male])
		male += 1
print(*odp)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = []
i = 0
while len(ans) != n:
	ans.append(a[n - i - 1])
	if len(ans) != n:
		ans.append(a[i])
	i += 1
print((n - 1) // 2)
print(*ans)


n = int(input())
lst = list(map(int, input().split()))
ans = [-1 for i in range(n)]
lst.sort()
k = n // 2
for i in range(k):
	ans[i * 2 + 1] = lst[i]
for i in range(k, n):
	ans[(i - k) * 2] = lst[i]
res = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		res += 1
print(res)
print(*ans)


from sys import *
n = int(input())
a = list(map(int, input().split()))
a.sort()
arr = []
b = []
c = []
if n % 2 != 0:
	for i in range(n // 2):
		b.append(a[i])
	for i in range(n // 2, n):
		c.append(a[i])
	i = 0
	arr = []
	j = 0
	k = 0
	while i < n:
		if i % 2 == 0 or i == n - 1:
			arr.append(c[j])
			j = j + 1
		elif i % 2 != 0 and i != n - 1:
			arr.append(b[k])
			k = k + 1
		i = i + 1
if n % 2 == 0:
	for i in range(n // 2):
		b.append(a[i])
	for i in range(n // 2, n):
		c.append(a[i])
	i = 0
	arr = []
	j = 0
	k = 0
	while i < n:
		if i % 2 == 0:
			arr.append(c[j])
			j = j + 1
		elif i % 2 != 0:
			arr.append(b[k])
			k = k + 1
		i = i + 1
ans = 0
for i in range(1, n - 1):
	if arr[i] < arr[i + 1] and arr[i] < arr[i - 1]:
		ans = ans + 1
print(ans)
print(*arr)


import sys
n = int(input())
lst1 = list(map(int, input().split()))
a = [None] * n
lst1.sort()
index = ans = 0
for i in range(1, n, 2):
	a[i] = lst1[index]
	index += 1
for i in range(0, n, 2):
	a[i] = lst1[index]
	index += 1
for i in range(1, n - 1, 2):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ans += 1
print(ans)
print(*a)


def solve():
	n = int(input())
	p = list(map(int, input().split()))
	if n <= 2:
		print(0)
		print(*p)
		return
	a = []
	p.sort()
	l = n - 1
	r = 0
	while l >= r:
		a.append(p[l])
		a.append(p[r])
		l -= 1
		r += 1
	if n % 2:
		a.pop()
	print((n - 1) // 2)
	print(*a)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


from __future__ import division, print_function
import sys
sys.setrecursionlimit(10 ** 4)
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f

def primeFactors(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			a.append(i)
			n = n // i
	if n > 2:
		a.append(n)
	return a

def main():
	n = inin()
	a = ain()
	a.sort()
	b = []
	for i in range(n // 2):
		b.append(a[n - i - 1])
		b.append(a[i])
	if n % 2 == 1:
		b.append(a[n // 2])
	ans = 0
	for i in range(1, n - 1):
		if b[i] < b[i + 1] and b[i] < b[i - i]:
			ans += 1
	print(ans)
	print(*b)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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 sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'R'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'R'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
l = sorted(list(map(int, input().split())))
if n % 2 == 1:
	print(n // 2)
	for i in range(n // 2):
		print(l[-i - 1], l[i], end=' ')
	print(l[n // 2])
else:
	print(n // 2 - 1)
	for i in range(n // 2 - 1):
		print(l[-i - 1], l[i], end=' ')
	print(l[n // 2], l[n // 2 - 1])


n = int(input())
a = [int(x) for x in input().split()]
if n < 3:
	print(0)
	print(*a)
else:
	a.sort()
	b = [-1] * n
	b[-1] = a[-1]
	j = 0
	for z in range(1, n - 1, 2):
		b[z] = a[j]
		j += 1
	ans = j
	for z in range(n):
		if b[z] == -1:
			b[z] = a[j]
			j += 1
	print(ans)
	print(*b)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n == 1:
	print(0)
	print(l[0])
elif n == 2:
	print(0)
	print(l[0], l[1])
elif n % 2 == 0:
	print(n // 2 - 1)
	j = 0
	for i in range(n // 2, n):
		print(l[i], end=' ')
		if j < n // 2:
			print(l[j], end=' ')
			j += 1
else:
	print(n // 2)
	j = 0
	for i in range(n // 2, n):
		print(l[i], end=' ')
		if j < n // 2:
			print(l[j], end=' ')
			j += 1


n = int(input())
l = list(map(int, input().split()))
l.sort()
print((n - 1) // 2)
i = 0
while i < n - 1:
	(l[i], l[i + 1]) = (l[i + 1], l[i])
	i += 2
print(*l)


import sys
input = sys.stdin.readline

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

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

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

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

def solve(arr, n):
	arr.sort()
	if n <= 2:
		print(0)
		print(*arr)
	else:
		res = [0] * n
		j = 0
		for i in range(1, n, 2):
			res[i] = arr[j]
			j += 1
		for i in range(0, n, 2):
			res[i] = arr[j]
			j += 1
		cnt = 0
		for i in range(1, n - 1):
			cnt += res[i - 1] > res[i] < res[i + 1]
		print(cnt)
		print(*res)
n = inp()
arr = inlt()
solve(arr, n)


n = int(input())
l = list(map(int, input().split()))
l.sort()
small = []
large = []
for i in range(n // 2 - 1, -1, -1):
	small.append(l[i])
for i in range(n - 1, n // 2 - 1, -1):
	large.append(l[i])
ans = []
n1 = len(large)
n2 = len(small)
(p1, p2) = (0, 0)
while p2 < n // 2:
	if small[p2] == large[p1]:
		p2 -= -1
		continue
	ans.append(large[p1])
	ans.append(small[p2])
	large[p1] = 0
	small[p2] = 0
	p1 -= -1
	p2 -= -1
for i in large:
	if i:
		ans.append(i)
for i in small:
	if i:
		ans.append(i)
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt -= -1
print(cnt)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
d = []
mid = len(l) // 2
d.append(l[mid])
i = 0
j = len(l) - 1
k = 0
while i < mid and j > mid:
	if k % 2 == 0:
		d.append(l[i])
		i += 1
	else:
		d.append(l[j])
		j -= 1
	k += 1
if i != mid:
	for x in range(i, mid):
		d.append(l[x])
if j != mid:
	for x in range(j, mid, -1):
		d.append(l[x])
c = 0
for i in range(1, len(d) - 1):
	if d[i] < d[i - 1] and d[i] < d[i + 1]:
		c += 1
print(c)
for i in d:
	print(i, end=' ')


from sys import *
from collections import deque
n = int(stdin.readline())
things = sorted([int(x) for x in stdin.readline().split()])
new = []
big = things[n // 2:]
small = things[:n // 2]
for i in range(n // 2):
	new.append(str(big[i]))
	new.append(str(small[i]))
if n % 2 != 0:
	new.append(str(big[-1]))
print((n - 1) // 2)
print(' '.join(new))


n = int(input())
l = list(map(int, input().split()))
l.sort()
for i in range(0, len(l), 2):
	if i + 1 < len(l):
		(l[i], l[i + 1]) = (l[i + 1], l[i])
ans = 0
for i in range(1, len(l) - 1):
	if l[i] < l[i - 1] and l[i] < l[i + 1]:
		ans += 1
print(ans)
print(*l)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
pointer = 0
bckt = [0] * n
if n == 1 or n == 2:
	print(0)
	print(*a)
else:
	for i in range(0, n, 2):
		bckt[i] = a[pointer]
		pointer += 1
	if n % 2 == 0:
		bckt[-1] = bckt[-2]
		bckt[-2] = 0
	ct = 0
	for i in range(n):
		if bckt[i] == 0:
			bckt[i] = a[pointer]
			pointer += 1
	for i in range(1, n - 1):
		if bckt[i] < bckt[i - 1] and bckt[i] < bckt[i + 1]:
			ct += 1
	print(ct)
	print(*bckt)


n = int(input())
u = sorted(list(map(int, input().split())))
print((n - 1) // 2)
ans = []
ind = 0
for i in range((n - 1) // 2, n):
	ans.append(u[i])
	if ind == (n - 1) // 2:
		continue
	ans.append(u[ind])
	ind += 1
print(' '.join(map(str, ans)))


def do(l, n):
	o = l[0:n // 2]
	k = l[n // 2:n]
	nlist = []
	for i in range(n // 2):
		nlist.append(str(k[i]))
		nlist.append(str(o[i]))
	nlist.append(str(k[n // 2]))
	return nlist
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n % 2 == 0:
	x = l[n - 1]
	l.pop(n - 1)
	a = do(l, n - 1)
	a.append(str(x))
	n -= 1
else:
	a = do(l, n)
print(n // 2)
print(' '.join(a))


n = int(input())
a = [int(x) for x in input().split()]
if n < 3:
	print(0)
	print(*a)
else:
	a.sort()
	b = [-1] * n
	c = [-1] * n
	l = 0
	m = n // 2
	r = n - 1
	for z in range(n):
		if z & 1:
			b[z] = a[l]
			c[z] = a[l]
			l += 1
		else:
			b[z] = a[r]
			c[z] = a[m]
			r -= 1
			m += 1
	ans1 = 0
	ans2 = 0
	for z in range(1, n - 1):
		if b[z] < b[z - 1] and b[z] < b[z + 1]:
			ans1 += 1
		if c[z] < c[z - 1] and c[z] < c[z + 1]:
			ans2 += 1
	if ans1 > ans2:
		print(ans1)
		print(*b)
	else:
		print(ans2)
		print(*c)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

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 convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

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

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	n = ii()
	arr = li()
	arr = sorted(arr)
	m = 0
	for i in range(1, n - 1, 2):
		if arr[i - 1] < arr[i]:
			(arr[i - 1], arr[i]) = (arr[i], arr[i - 1])
			m += 1
		else:
			for j in range(0, i - 1):
				if arr[j] < arr[i]:
					(arr[j], arr[i]) = (arr[i], arr[j])
					m += 1
					break
	print(m)
	print(*arr)
main()


t = 1
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr)
	temp = [0 for x in range(n)]
	c = 0
	for i in range(1, n, 2):
		temp[i] = arr[c]
		c += 1
	for i in range(0, n, 2):
		temp[i] = arr[c]
		c += 1
	ans = 0
	val = n
	if n % 2 == 0:
		val -= 1
	for i in range(1, val, 2):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			ans += 1
	print(ans)
	print(*temp)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
res = [0] * n
a = sorted(a, reverse=True)
ai = 0
for i in range(0, n, 2):
	res[i] = a[ai]
	ai += 1
if n % 2 == 0:
	res[-1] = a[ai]
	ai += 1
for i in range(1, n - 1, 2):
	res[i] = a[ai]
	ai += 1
ans = 0
for i in range(n):
	if not (i - 1 >= 0 and i + 1 < n):
		continue
	if res[i] < res[i - 1] and res[i] < res[i + 1]:
		ans += 1
print(ans)
print(*res)


import sys
n = int(input())
ar = [int(i) for i in input().split()]
ar.sort()
ind = 0
res = [0] * n
for i in range(1, n, 2):
	res[i] = ar[ind]
	ind += 1
for i in range(0, n, 2):
	res[i] = ar[ind]
	ind += 1
kek = 0
for i in range(1, n - 1):
	kek += res[i] < res[i - 1] and res[i] < res[i + 1]
print(kek)
print(*res)


n = int(input())
arr = list(map(int, input().split()))
res = [0] * n
arr.sort()
res[1::2] = arr[:n // 2]
res[::2] = arr[n // 2:]
x = 0
for i in range(1, n - 1):
	x += res[i - 1] > res[i] < res[i + 1]
print(x)
print(*res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = a[j]
	j += 1
for i in range(0, n, 2):
	ans[i] = a[j]
	j += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
ans = ' '.join(map(str, ans))
print(ans)


N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = [None] * N
if N % 2:
	for i in range(N):
		j = (i * 2 + 1) % N
		ans[j] = A[i]
else:
	for i in range(N):
		j = i * 2 + 1
		if j > N:
			j -= N + 1
		ans[j] = A[i]
m = 0
for (a, b, c) in zip(ans, ans[1:], ans[2:]):
	if a > b and b < c:
		m += 1
print(m)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
x = a[:n // 2]
a = a[n // 2:]
(l, k, m) = ([], 0, 0)
for i in range(n):
	if i % 2 == 0:
		l.append(a[k])
		k += 1
	else:
		l.append(x[m])
		m += 1
m = 0
for i in range(1, n - 1):
	if l[i] < l[i - 1] and l[i] < l[i + 1]:
		m += 1
print(m)
for i in l:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
print((n - 1) // 2)
a.sort(reverse=True)
ans = [0] * n
for i in range(0, n, 2):
	ans[i] = a[i // 2]
a.sort()
for i in range(1, n, 2):
	ans[i] = a[i // 2]
print(*ans)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = 998244353
INF = float('inf')
n = int(data())
a = mdata()
a.sort()
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = a[j]
	j += 1
for i in range(0, n, 2):
	ans[i] = a[j]
	j += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
		cnt += 1
out(cnt)
outl(ans)


n = int(input())
ar = [int(k) for k in input().split()]
ar.sort()
ar1 = [0 for i in range(n)]
for i in range((n + 1) // 2):
	ar1[2 * i] = ar[n - i - 1]
ar2 = sorted(ar[:n // 2], reverse=True)
if n % 2 == 0:
	ar2 = ar2[1:] + [ar2[0]]
count = 0
for k in range(n // 2):
	if 2 * k + 2 < n and ar2[k] < ar1[2 * k + 2] and (ar2[k] < ar1[2 * k]):
		count += 1
	ar1[2 * k + 1] = ar2[k]
print(count)
for k in ar1:
	print(k, end=' ')


number_of_ice_spheres = int(input())
ice_spheres_prices = list(map(int, input().split()))
ice_spheres_prices.sort()
result = []
for i in range(number_of_ice_spheres // 2):
	result.append(ice_spheres_prices[-i - 1])
	result.append(ice_spheres_prices[i])
if number_of_ice_spheres % 2 == 1:
	result.append(ice_spheres_prices[number_of_ice_spheres // 2])
	print(number_of_ice_spheres // 2)
else:
	print((number_of_ice_spheres - 1) // 2)
print(' '.join(map(str, result)))


i_sfer = int(input())
sfery = sorted(list(map(int, input().split())))
(male, duze) = (sfery[:(i_sfer - 1) // 2], sfery[i_sfer - (i_sfer - 1) // 2 - 1:])
if len(male) <= (i_sfer - 1) // 2:
	male += [sfery[(i_sfer - 1) // 2]]
mal = False
print((i_sfer - 1) // 2)
for x in range(i_sfer):
	if mal:
		print(male[x // 2], end=' ')
	else:
		print(duze[x // 2], end=' ')
	mal = not mal


from collections import deque
n = int(input())
al = list(map(int, input().split()))
al.sort()
q = deque(al)
ans = [-1] * n
for i in range(1, n, 2):
	ans[i] = q.popleft()
for i in range(0, n, 2):
	ans[i] = q.popleft()
print((n - 1) // 2)
print(*ans)


n = int(input())
inp = sorted(list(map(int, input().split())))
print((n - 1) // 2)
for i in range(n // 2):
	print(inp[n - i - 1], inp[i], sep=' ', end=' ')
if n % 2 == 1:
	print(inp[n // 2])


n = int(input())
esferas = list(map(int, input().split(' ')))
esferas.sort()
limite = int(n / 2)
menores = esferas[:limite]
maiores = esferas[limite:]
indice = 0
reordenadas = []
compras = 0
esquerda = False
for i in range(n):
	if i % 2 == 0:
		reordenadas.append(maiores[int(i / 2)])
		if esquerda and maiores[int(i / 2)] > reordenadas[i - 1]:
			compras += 1
			esquerda = False
	else:
		reordenadas.append(menores[indice])
		if menores[indice] < reordenadas[i - 1]:
			esquerda = True
		else:
			esquerda = False
		indice += 1
print(compras)
reordenadas = [str(int) for int in reordenadas]
print(' '.join(reordenadas))


import sys
from sys import stdin
import math

def iinput():
	return int(input())

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

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

def fiinput():
	return int(stdin.readline())

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
n = iinput()
list1 = linput()
list1.sort()
nn = n
if nn % 2 == 0:
	nn -= 1
m = nn // 2
list2 = []
ii = 0
jj = n - 1
for i in range(n):
	if i % 2 == 0:
		list2.append(list1[jj])
		jj -= 1
	else:
		list2.append(list1[ii])
		ii += 1
c = 0
for i in range(n):
	if i % 2 != 0 and i != n - 1:
		if list2[i - 1] > list2[i] and list2[i] < list2[i + 1]:
			c += 1
print(c)
print(*list2)


import sys
from collections import deque
input = sys.stdin.buffer.readline
(n, ls) = (int(input()), list(map(int, input().split())))
ls.sort()
if n < 3:
	print(0)
	print(*ls)
	exit()
(m, cc) = ((n - 1) // 2, 0)
(a, b, c) = (deque(ls[0:m]), deque(ls[m:]), deque([]))
c.append(b.pop())
while a and b:
	if b[-1] > a[-1]:
		c.appendleft(a.pop())
		c.appendleft(b.pop())
		cc += 1
	else:
		b.appendleft(a.pop())
if a:
	c += a
if b:
	c += b
print(cc)
print(*c)


n = int(input())
l = sorted(list(map(int, input().split())))
if n <= 2:
	print(0)
	print(*l)
elif n % 2 == 0:
	print(n // 2 - 1)
	a = l[:n // 2]
	b = l[n // 2:]
	for i in range(n // 2):
		print(b[i], a[i], end=' ')
else:
	a = l[:n // 2]
	b = l[n // 2:]
	print(n // 2)
	for i in range(n // 2):
		print(b[i], a[i], end=' ')
	print(b[-1])


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = a.copy()
s = s[::-1]
a = a[n // 2:]
s = s[n // 2 + n % 2:]
s = s[::-1]
z = []
for i in range(len(s)):
	z.append(a[i])
	z.append(s[i])
if n % 2 == 1:
	z.append(a[-1])
	print(len(s))
else:
	print(len(s) - 1)
print(*z)


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = [int(c) for c in input().split()]
arr.sort()
ans = []
fpos = -1
lpos = 0
pos = fpos
for i in range(n):
	ans.append(arr[pos])
	if pos < 0:
		fpos -= 1
		pos = lpos
	else:
		lpos += 1
		pos = fpos
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(*ans)


n = int(input())
s = sorted(map(int, input().split()))
ans = [None] * n
print((n - 1) // 2)
count = 0
for i in range(1, len(s), 2):
	ans[i] = str(s[count])
	count += 1
for i in range(0, len(s), 2):
	ans[i] = str(s[count])
	count += 1
print(' '.join(ans))


import math
n = int(input())
a = [int(i) for i in input().split()]
k = n // 2
j = 0
a.sort()
if n % 2:
	print(n // 2)
else:
	print(n // 2 - 1)
for i in range(n):
	if i % 2 == 0:
		print(a[k], end=' ')
		k += 1
	else:
		print(a[j], end=' ')
		j += 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
mi = a[:n // 2]
ma = a[n // 2:]
l = []
for i in range(n):
	if i % 2 == 0:
		l.append(ma[i // 2])
	else:
		l.append(mi[i // 2])
ans = 0
for i in range(1, n - 1):
	if l[i - 1] > l[i] < l[i + 1]:
		ans += 1
print(ans)
print(*l)


def reOrder(arr):
	resArray = []
	arr = sorted(arr)
	mid = len(arr) // 2
	i = 0
	j = mid
	while i < mid and j < len(arr):
		resArray.append(arr[j])
		resArray.append(arr[i])
		i += 1
		j += 1
	while j < len(arr):
		resArray.append(arr[j])
		j += 1
	return resArray

def countPeaks(arr):
	if len(arr) <= 2:
		return 0
	res = 0
	i = 0
	j = i + 2
	while j < len(arr):
		left = arr[i]
		right = arr[j]
		middle = arr[i + 1]
		if middle < left and middle < right:
			res += 1
		i += 1
		j += 1
	return res
n = int(input())
arr = list(map(int, input().split()))
resArray = reOrder(arr)
res = countPeaks(resArray)
print(res)
print(*resArray)


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
a = list(map(int, input().split()))
count = 0
res = []
i = 0
j = n - 1
a.sort()
while i <= j:
	if i == j:
		res.append(a[i])
	else:
		res.append(a[j])
		res.append(a[i])
	i += 1
	j -= 1
for i in range(1, n - 1):
	if res[i] < res[i - 1] and res[i] < res[i + 1]:
		count += 1
print(count)
print(*res)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
left = arr[:n // 2]
right = arr[n // 2:]
narr = []
l = 0
r = 0
for i in range(n):
	if i % 2 == 0:
		narr.append(right[r])
		r += 1
	else:
		narr.append(left[l])
		l += 1
if n < 3:
	print(0)
	print(*arr)
elif n % 2 == 0:
	print(n // 2 - 1)
	print(*narr)
elif n % 2 == 1:
	print(n // 2)
	print(*narr)


from sys import stdin
tt = 1
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	print((n - 1) // 2)
	ans = [None] * n
	for i in range(0, n, 2):
		ans[i] = a[-1]
		del a[-1]
	for i in range(1, n, 2):
		ans[i] = a[-1]
		del a[-1]
	print(*ans)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = []
p = 0
if n % 2:
	for i in range(n // 2, n):
		ans.append(a[i])
		if i < n - 1:
			ans.append(a[p])
			p += 1
else:
	for i in range(n // 2, n):
		ans.append(a[i])
		ans.append(a[p])
		p += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


n = int(input())
a = [int(x) for x in input().split()]
if n % 2 != 0:
	a.sort()
	n1 = n // 2
	b = a[:n1]
	a = a[n1:]
	j = 1
	for i in b:
		a.insert(j, i)
		j = j + 2
	print(len(b))
	print(' '.join(map(str, a)))
else:
	a.sort()
	n1 = n // 2
	b = a[:n1]
	a = a[n1:]
	j = 0
	for i in b:
		a.insert(j, i)
		j = j + 2
	print(len(b) - 1)
	print(' '.join(map(str, a)))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
point = 0
temp = [0] * n
curr = 1
while curr < n:
	temp[curr] = arr[point]
	curr += 2
	point += 1
for i in range(n):
	if temp[i] == 0:
		temp[i] = arr[point]
		point += 1
count = 0
for i in range(1, n - 1):
	if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
		count += 1
print(count)
for i in range(n):
	print(temp[i], end=' ')


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = [0] * n
k = (n - 1) // 2
x = -1
i = 0
while x < n:
	x += 2
	if x >= n:
		break
	b[x] = a[i]
	i += 1
x = -2
while x < n:
	x += 2
	if x >= n:
		break
	b[x] = a[i]
	i += 1
d = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		d += 1
print(d)
for i in b:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = [0] * n
k = 0
for j in range(1, n, 2):
	l[j] = a[k]
	k += 1
for j in range(0, n, 2):
	l[j] = a[k]
	k += 1
if n <= 2:
	print(0)
else:
	cnt = 0
	for j in range(1, n - 1, 2):
		if l[j] < l[j + 1] and l[j] < l[j - 1]:
			cnt += 1
	print(cnt)
print(*l)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
res = []
i = 0
j = n - 1
k = 0
while k != n:
	if k % 2 == 0:
		res.append(a[j])
		j -= 1
	else:
		res.append(a[i])
		i += 1
	k += 1
acc = 0
for i in range(1, n - 1):
	if res[i - 1] > res[i] < res[i + 1]:
		acc += 1
print(acc)
print(*res)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = [0] * n
c = 0
for i in range(n // 2 + n % 2):
	ans[c] = a[-i - 1]
	c += 2
c = 1
an = 0
for i in range(n - (n // 2 + n % 2)):
	ans[c] = a[i]
	an += 1
	c += 2
print((n - 1) // 2)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
y = []
print((n - 1) // 2)
i = 0
j = n - 1
while i <= j:
	if i == j:
		y.append(a[i])
		break
	y.append(a[j])
	y.append(a[i])
	i += 1
	j -= 1
for i in range(len(y)):
	if i != len(y) - 1:
		print(y[i], end=' ')
	else:
		print(y[i])


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
if n % 2 == 0:
	p = n // 2 - 1
else:
	p = n // 2
print(p)
l2 = []
for i in range(p):
	l2.append(l[i])
index = p
indexl2 = 0
indexC = 0
l3 = []
while len(l3) != n:
	if indexC % 2 == 0:
		l3.append(l[index])
		index += 1
	elif indexl2 > len(l2) - 1:
		pass
	else:
		l3.append(l2[indexl2])
		indexl2 += 1
	indexC += 1
print(*l3)


from heapq import heapify, heappop
size = input()
numbers = input()
numbers = numbers.split(' ')
numbers = [-int(num) for num in numbers]
heapify(numbers)
res = [None for _ in range(0, int(size))]
res_num = 0
index = int(size) - 1
for round in range(0, 2):
	if round == 0:
		while index >= 0:
			curr = -heappop(numbers)
			res[index] = curr
			index -= 2
	else:
		while index >= 0:
			curr = -heappop(numbers)
			res[index] = curr
			if index:
				res_num += 1
			index -= 2
	index = int(size) - 2
print(res_num)
print(' '.join([str(x) for x in res]))


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	a.sort()
	mins = a[:n // 2]
	bigs = a[n // 2:]
	bigs.reverse()
	mins.reverse()
	res = [0 for i in range(n)]
	for i in range(n):
		if i % 2 == 0:
			res[i] = bigs.pop()
		else:
			res[i] = mins.pop()
	ans = 0
	for i in range(1, n - 1):
		if res[i - 1] > res[i] < res[i + 1]:
			ans += 1
	print(ans)
	print(*res)


import sys
input = sys.stdin.readline
n = int(input())
A = sorted(map(int, input().split()))
ans = [0] * n
j = n - 1
for i in range(0, n, 2):
	ans[i] = A[j]
	j -= 1
rem = []
cnt = 0
pre = -1
for i in range(1, n - 1, 2):
	if j < 0:
		break
	while j >= 0 and A[j] >= ans[i + 1]:
		rem.append(A[j])
		j -= 1
	cnt += 1
	ans[i] = A[j]
	pre = i
	j -= 1
rem += A[:j + 1]
j = 0
if rem:
	for k in range(pre + 2, n, 2):
		ans[k] = rem[j]
		j += 1
print(cnt)
print(*ans)


from collections import deque
n = int(input())
num = list(map(int, input().split()))
if n <= 2:
	print(0)
	print(' '.join(map(str, num)))
else:
	cnt = n - 2
	if cnt % 2 == 0:
		print(cnt // 2)
	else:
		print(cnt // 2 + 1)
	num.sort()
	max_value = [num[-1], num[-2]]
	num.pop()
	num.pop()
	temp = []
	num = deque(num)
	for i in range(cnt):
		if i % 2 == 0:
			temp.append(num.popleft())
		else:
			temp.append(num.pop())
	temp = [max_value[0]] + temp + [max_value[1]]
	print(' '.join(map(str, temp)))


n = int(input())
arr = input().strip().split()
arr = [int(ele) for ele in arr]
arr.sort()
first = n // 2
second = 0
out = []
while first < n or second < n // 2:
	if first < n:
		out.append(arr[first])
	if second < n // 2:
		out.append(arr[second])
	first += 1
	second += 1
out = [str(ele) for ele in out]
if n % 2:
	print(n // 2)
	print(' '.join(out))
else:
	print(n // 2 - 1)
	print(' '.join(out))


n = int(input())
l = list(map(int, input().split()))
res = [0] * n
(o, e) = (0, 0)
l.sort()
if len(l) % 2 == 0:
	print(len(l) // 2 - 1)
	l1 = [i for i in l[0:len(l) // 2]]
	l2 = [i for i in l[len(l) // 2:]]
	for i in range(n):
		if i % 2 == 0:
			res[i] = l2[o]
			o += 1
		else:
			res[i] = l1[e]
			e += 1
	for i in res:
		print(i, end=' ')
else:
	print(len(l) // 2)
	l1 = [i for i in l[0:len(l) // 2]]
	l2 = [i for i in l[len(l) // 2:]]
	for i in range(n):
		if i % 2 == 0:
			res[i] = l2[o]
			o += 1
		else:
			res[i] = l1[e]
			e += 1
	for i in res:
		print(i, end=' ')


from sys import stdin, stdout
from collections import deque
import bisect
from heapq import heapify, heappop, heappush
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
n = int(input())
l = RL(int)
l.sort()
ans = []
if n % 2 == 0:
	great = n // 2 + 1
	small = n // 2 - 1
else:
	great = n // 2 + 1
	small = n // 2
for i in range(n):
	if i % 2 == 0:
		ans.append(l[n - 1 - i // 2])
	else:
		ans.append(l[i // 2])
print(small)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
k = (n - 1) // 2
print(k)
arr1 = arr[:k]
arr2 = arr[k:]
for i in range(len(arr1)):
	print(arr2[i], end=' ')
	print(arr1[i], end=' ')
for i in arr2[len(arr1):]:
	print(i, end=' ')


from sys import stdin, stdout
from math import *
testing = True

def tp(s='\n'):
	if testing:
		stdout.write(s)

def main():
	n = int(stdin.readline())
	arr = [int(i) for i in stdin.readline().split()]
	arr.sort()
	out = [0] * n
	for i in range(floor(n / 2)):
		out[2 * i + 1] = arr[i]
	for i in range(ceil(n / 2)):
		out[2 * i] = arr[i + floor(n / 2)]
	count = 0
	for i in range(1, n - 1):
		if out[i] < out[i + 1] and out[i] < out[i - 1]:
			count += 1
	print(count)
	print(' '.join([str(i) for i in out]))
main()


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
if n < 3:
	print(0)
	print(' '.join((str(i) for i in arr)))
else:
	arr.sort()
	temp = [-1] * n
	start = 1 if n % 2 else 0
	idx = 0
	for i in range(start, n, 2):
		temp[i] = arr[idx]
		idx += 1
	idx = n - 1
	for i in range(n - 1, -1, -2):
		temp[i] = arr[idx]
		idx -= 1
	result = 0
	for i in range(1, n - 1):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			result += 1
	print(result)
	print(' '.join((str(i) for i in temp)))


from itertools import zip_longest, chain
n = int(input())
a = [int(s) for s in input().split(' ')]
a.sort(reverse=True)
print((n - 1) // 2)
i = 0
ans = [x for x in chain(*zip_longest(a[:n // 2 + 1], a[n // 2 + 1:])) if x]
print(*ans)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = sorted(l1)
(i, j) = (0, len(l1) - 1)
c = []
while j >= i:
	c.append(l2[j])
	j -= 1
	if j > i:
		c.append(l2[i])
		i += 1
print((n - 1) // 2)
print(*c)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
out = []
i = 0
j = n - 1
while i <= j:
	if i == j:
		out.append(ai[i])
		break
	out.append(ai[j])
	out.append(ai[i])
	j -= 1
	i += 1
print(int(n / 2)) if n % 2 != 0 else print(int(n / 2) - 1)
print(*out)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort(reverse=True)
new = [None] * n
count = 0
for i in range(n):
	if i % 2 == 1:
		new[i] = arr.pop()
		count += 1
for i in range(n):
	if i % 2 == 0:
		new[i] = arr.pop()
if n == 1 or n == 2:
	print(0)
else:
	print((n - 1) // 2)
print(*new)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 0:
		print(n // 2 - 1)
		b = [0] * n
		a.sort()
		j = 0
		for i in range(0, n, 2):
			b[i] = a[-j - 1]
			j += 1
		j = 0
		for i in range(1, n, 2):
			b[i] = a[j]
			j += 1
		print(*b)
	else:
		print(n // 2)
		b = [0] * n
		a.sort()
		j = 0
		for i in range(0, n, 2):
			b[i] = a[-j - 1]
			j += 1
		j = 0
		for i in range(1, n, 2):
			b[i] = a[j]
			j += 1
		print(*b)
main()


from sys import stdin
n = int(input())
l = list(map(int, stdin.readline().rstrip().split(' ')))
l.sort()
z = [0] * n
if n % 2:
	start = n // 2
else:
	start = n // 2
x = 0
for i in range(start, n):
	z[x] = l[i]
	x += 2
x = 1
for i in range(start):
	z[x] = l[i]
	x += 2
c = 0
for i in range(1, n - 1, 2):
	if z[i] < z[i - 1] and z[i] < z[i + 1]:
		c += 1
print(c)
print(*z)


n = int(input())
num = [0 for i in range(n)]
lis = list(map(int, input().split()))
if n < 3:
	print(0)
	print(*lis)
else:
	lis.sort()
	j1 = n - 1
	if n % 2 == 0:
		i = n // 2
	else:
		i = n // 2 + 1
	v1 = 0
	i1 = n - 1
	if n % 2 == 0:
		for k in range(i):
			num[j1] = lis[i1]
			i1 -= 1
			j1 -= 2
		n1 = 2
		n2 = 0
		for i in range(n // 2 - 1):
			num[n1] = lis[n2]
			n2 += 1
			n1 += 2
		num[0] = lis[n2]
		co = 0
		for i in range(1, n - 1, 1):
			if num[i] < num[i - 1] and num[i] < num[i + 1]:
				co += 1
		print(co)
		print(*num)
	else:
		for k in range(i):
			num[j1] = lis[i1]
			i1 -= 1
			j1 -= 2
		n1 = 1
		n2 = 0
		for i in range(n // 2):
			num[n1] = lis[n2]
			n2 += 1
			n1 += 2
		co = 0
		for i in range(1, n - 1, 1):
			if num[i] < num[i - 1] and num[i] < num[i + 1]:
				co += 1
		print(co)
		print(*num)


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
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()
setrecursionlimit(100000)
mod = 1000000007
n = ii1()
arr = deque(sorted(iia()))
if n < 3:
	print(0)
	print(*arr)
else:
	res = [0] * len(arr)
	res[0] = arr.pop()
	res[-1] = arr.pop()
	flag = 1
	for i in range(1, n - 1):
		if flag:
			res[i] = arr.popleft()
		else:
			res[i] = arr.pop()
		flag ^= 1
	ans = 0
	for i in range(1, n - 1):
		if res[i] < res[i - 1] and res[i] < res[i + 1]:
			ans += 1
	print(ans)
	print(*res)


from math import ceil

def fu():
	return map(int, input().split(' '))
n = int(input())
p = int((n - 1) / 2)
s = sorted(list(fu()))
s1 = s[:p]
s2 = s[p:]
A = ''
for i in range(p):
	A += str(s2[i]) + ' ' + str(s1[i]) + ' '
A += str(s2[p])
if n % 2 == 0:
	A += ' ' + str(s2[p + 1])
print(p)
print(A)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	data = sorted(idata())
	unused = data[:n // 2]
	ans = [0] * n
	ans1 = 0
	for i in range(0, n, 2):
		ans[i] = data[n // 2 + i // 2]
	(l, r) = (0, n // 2 - 1)
	if n % 2 == 0:
		ans[-1] = unused[-1]
		r -= 1
	for i in range(1, n - 1, 2):
		if min(ans[i + 1], ans[i - 1]) > unused[l]:
			ans[i] = unused[l]
			l += 1
			ans1 += 1
		else:
			ans[i] = unused[r]
			r -= 1
	print(ans1)
	print(*ans)
	return
solve()


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans = [0] * n
if n % 2 == 0:
	print((n - 2) // 2)
	p = 0
	for i in range(1, n, 2):
		ans[i] = str(lst[p])
		p += 1
	for i in range(0, n, 2):
		ans[i] = str(lst[p])
		p += 1
	print(' '.join(ans))
else:
	print((n - 1) // 2)
	p = 0
	for i in range(1, n, 2):
		ans[i] = str(lst[p])
		p += 1
	for i in range(0, n, 2):
		ans[i] = str(lst[p])
		p += 1
	print(' '.join(ans))


from math import *
n = int(input())
lista = [int(i) for i in input().split(' ')]
lista.sort()
for i in range(1, len(lista), 2):
	a = lista[i]
	b = lista[i - 1]
	lista[i - 1] = a
	lista[i] = b
print(ceil(n / 2 - 1))
print(' '.join([str(i) for i in lista]))


n = int(input())
print((n - 1) // 2)
a = [int(i) for i in input().split(' ')]
a.sort()
b = []
for i in range(n):
	if i % 2 == 0:
		b.append(a[n // 2 + i // 2])
	else:
		b.append(a[i // 2])
print(' '.join([str(i) for i in b]))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = li()
if n < 3:
	print(0)
	print(*l)
	exit()
l = [[i, l[i]] for i in range(n)]
l.sort(key=lambda x: x[1])
l = deque(l)
l1 = deque()
for i in range(n):
	l1.append(0)
left = 0
right = n - 1
while len(l):
	l1[left] = l.pop()
	left += 1
	if len(l):
		l1[right] = l.pop()
		right -= 1
	if len(l):
		l1[left] = l.popleft()
		left += 1
	if len(l):
		l1[right] = l.popleft()
		right -= 1
l1 = list(l1)
l1 = [i[1] for i in l1]
ans = 0
for i in range(1, n - 1):
	if l1[i] < l1[i - 1] and l1[i] < l1[i + 1]:
		ans += 1
print(ans)
print(*l1)


a = int(input())
b = [int(x) for x in input().split()]
if a % 2 == 0:
	d = a // 2
	c = d
else:
	c = a // 2 + 1
	d = a - c
b.sort()
b = b[::-1]
e = []
f = []
if a == 1:
	print(0)
	print(b[0])
if a == 2:
	print(0)
	print(str(b[0]) + ' ' + str(b[1]))
if a == 3:
	print(1)
	print(str(b[0]) + ' ' + str(b[2]) + ' ' + str(b[1]))
if a >= 4:
	g = [0] * a
	for i in range(c):
		e.append(b[i])
	b = b[::-1]
	for i in range(d):
		f.append(b[i])
	f = f[::-1]
	for i in range(a):
		if i % 2 == 0:
			g[i] = e[i // 2]
	for i in range(a):
		if i % 2 != 0:
			g[i] = f[i // 2]
	if a % 2 == 0:
		print(a // 2 - 1)
	else:
		print(a // 2)
	for i in range(a):
		print(g[i], end=' ')
	print()


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('0') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
a.sort()
ans = [0] * n
cur = 0
for i in range(1, n, 2):
	ans[i] = a[cur]
	cur += 1
for i in range(0, n, 2):
	ans[i] = a[cur]
	cur += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


import sys

def main():
	n = Iint()
	a = Ilist()
	if len(a) <= 2:
		print(0)
		Plist(a)
		return
	a.sort()
	a1 = a[:n // 2]
	a2 = a[n // 2:]
	b = [0] * n
	for i in range(n):
		if i % 2 == 0:
			b[i] = a2[i // 2]
		elif i % 2 == 1:
			b[i] = a1[i // 2]
	ans = 0
	for i in range(1, n - 1):
		if b[i - 1] > b[i] < b[i + 1]:
			ans += 1
	print(ans)
	Plist(b)
en = enumerate
FIO = 10

def debug(*args, c=6):
	pass
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=sys.stderr)
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

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


def solve(xs):
	xs.sort()
	n = len(xs)
	m = n - 3 if n % 2 == 0 else n - 2
	count = 0
	for i in range(0, m, 2):
		(xs[i], xs[i + 1]) = (xs[i + 1], xs[i])
		count += 1
	return count

def main(input_path=0):
	with open(input_path) as f:
		n = int(f.readline().strip())
		xs = [int(x) for x in f.readline().split(' ')]
		max_count = solve(xs)
		print(max_count)
		for x in xs:
			print(x, end=' ')
main()


from collections import Counter
import string
import math
import sys

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))
mod = 100000007
n = vary(1)
num = array_int()
num.sort()
ans = 0
new = []
a = num[:n // 2]
b = num[n // 2:]
for i in range(n // 2 + 1):
	try:
		new.append(b[i])
	except:
		pass
	try:
		new.append(a[i])
	except:
		pass
count = 0
for i in range(1, n - 1):
	if new[i] < new[i + 1] and new[i] < new[i - 1]:
		count += 1
print(count)
print(*new)


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
A.sort()
Ans = [None] * N
A1 = A[:(N - 1) // 2][::-1]
A2 = A[(N - 1) // 2:]
for i in range((N - 1) // 2):
	Ans[2 * i + 1] = A1[i]
for i in range(N):
	if Ans[i] is None:
		Ans[i] = A2.pop()
ans = 0
for i in range(1, N - 1):
	if Ans[i - 1] > Ans[i] and Ans[i] < Ans[i + 1]:
		ans += 1
print(ans)
print(*Ans)


for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	if n == 0:
		print(0)
		print(*arr)
	elif n == 2:
		print(0)
		arr.sort()
		print(*arr)
	else:
		ls = [0] * n
		var = 0
		var2 = n // 2
		for i in range(n):
			if (i + 1) % 2 == 0:
				ls[i] = arr[var]
				var += 1
			else:
				ls[i] = arr[var2]
				var2 += 1
		print(n // 2 if n % 2 != 0 else n // 2 - 1)
		print(*ls)


n = int(input())
lst = input().split()
for i in range(n):
	lst[i] = int(lst[i])
lst.sort()
ans = 0
if n % 2 != 0:
	ans = n // 2
else:
	ans = n // 2 - 1
mid = []
out = []
m = []
if n % 2 == 0:
	for i in range(ans + 1):
		mid.append(lst[i])
	for i in range(ans + 1, n):
		out.append(lst[i])
else:
	for i in range(ans):
		mid.append(lst[i])
	for i in range(ans, n):
		out.append(lst[i])
for i in range(n):
	if i % 2 == 0:
		m.append(str(out[i // 2]))
	else:
		m.append(str(mid[i // 2]))
print(ans)
print(' '.join(m))


import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ind = n // 2
i = 0
j_r = ind + bisect.bisect_right(l[ind:], l[i] + 1)
j = j_r
if n == 1 or n == 2:
	print(0)
elif n == 3:
	print(1)
elif len(l[:j]) == len(l[j:]):
	print(len(l[:j]) - 1)
else:
	print(len(l[:j]))
while i < j_r and j < n:
	print(l[j], l[i], end=' ')
	j += 1
	i += 1
print(*l[i:j_r] + l[j:])


import math
import sys
x = int(input())
a = sorted(list(map(int, input().split())))
if x < 3:
	print(0)
	print(*a)
	sys.exit()
print(math.ceil(x / 2 - 1))
c = [a[int(x / 2)]]
d = int(x / 2) + 1
for j in range(int(x / 2) - 1):
	c.append(a[j])
	c.append(a[d])
	d = d + 1
if x % 2 != 0:
	c.append(a[int(x / 2) - 1])
	c.append(a[d])
else:
	c.append(a[int(x / 2) - 1])
print(*c)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	a = arr.copy()
	a.sort(reverse=True)
	ind = 0
	for i in range(0, n, 2):
		arr[i] = a[ind]
		ind += 1
	for i in range(1, n, 2):
		arr[i] = a[ind]
		ind += 1
	cnt = 0
	for i in range(n):
		if i != 0 and i != n - 1:
			if i % 2:
				cnt += 1
	print(cnt)
	print(*arr)
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')
for _ in range(1):
	main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
g = []
h = []
for j in range(n // 2):
	g.append(a[j])
for j in range(n // 2, n):
	h.append(a[j])
gx = len(g)
hx = len(h)
gy = 0
hy = 0
c = 0
k = []
while gy < gx or hy < hx:
	if gy < gx and hy < hx:
		if g[gy] < h[hy]:
			k.append(h[hy])
			k.append(g[gy])
			hy = hy + 1
			gy = gy + 1
			if hy < hx:
				c = c + 1
		elif g[gy] == h[hy]:
			k.append(h[hy])
			hy = hy + 1
	elif gy == gx:
		k.append(h[hy])
		hy = hy + 1
	else:
		k.append(g[gy])
		gy = gy + 1
print(c)
print(' '.join(map(str, k)))


n = int(input())
a = list(map(int, input().split()))
a.sort()
output = []
left = a[:n // 2]
right = a[n // 2:]
i = 0
while i < n // 2:
	output.append(right[i])
	output.append(left[i])
	i += 1
if n % 2 == 1:
	output.append(right[i])
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
print(' '.join(map(str, output)))


n = int(input())
l = list(map(int, input().split()))
l.sort()
small = []
large = []
for i in range(n // 2 - 1, -1, -1):
	small.append(l[i])
for i in range(n - 1, n // 2 - 1, -1):
	large.append(l[i])
print((n - 1) // 2)
(p1, p2) = (0, 0)
while p2 < n // 2:
	print(large[p1], small[p2], end=' ')
	p1 -= -1
	p2 -= -1
if p1 == len(large) - 1:
	print(large[len(large) - 1])


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
i = 0
j = 0
ans = [0 for i in range(n)]
while j < n:
	ans[j] = a[i]
	i += 1
	j += 2
kk = 0
k = n - 1
for j in range(n):
	if ans[j] == 0:
		ans[j] = a[k]
		kk += 1
		k -= 1
if n < 3:
	print(0)
else:
	kk = 0
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
			kk += 1
	print(kk)
print(*ans, sep=' ')


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	n = ii()
	a = li()
	a.sort()
	ans = []
	l = 0
	r = n - 1
	ans.append(a[r])
	r -= 1
	while l <= r:
		ans.append(a[l])
		l += 1
		if l > r:
			break
		ans.append(a[r])
		r -= 1
	cnt = 0
	for i in range(1, n - 1):
		if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
			cnt += 1
	print(cnt)
	print(*ans)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


n = int(input())
m = [int(j) for j in input().split()]
m.sort()
for i in range(0, n - 1, 2):
	(m[i], m[i + 1]) = (m[i + 1], m[i])
print((n - 1) // 2)
print(*m)


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	if n == 1:
		print(0)
		print(a[0])
		continue
	ans = (n - 1) // 2
	b = []
	for i in range(ans, n):
		if i == n - 1:
			b += [a[i]]
		else:
			b += [a[i], 0]
	for i in range(ans):
		b[i * 2 + 1] = a[i]
	if b[-2] == 0:
		(b[-2], b[-1]) = (b[-1], '')
	print(ans)
	print(*b)


n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
if n % 2 == 0:
	arr_new = []
	x = int(n / 2)
	arr_new = arr_new + arr[0:x]
	del arr[0:x]
	for k in range(0, x):
		arr.insert(2 * k + 1, arr_new[k])
	print(x - 1)
	for i in range(0, len(arr)):
		print(arr[i], end=' ')
else:
	arr_new = []
	x = n // 2
	arr_new = arr_new + arr[0:x]
	del arr[0:x]
	for k in range(0, x):
		arr.insert(2 * k + 1, arr_new[k])
	print(x)
	for i in range(0, len(arr)):
		print(arr[i], end=' ')


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))
import math

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math as M
MOD = 10 ** 9 + 7
from random import randint as R
n = int(input())
A = INPUT()
A.sort()
for i in range(0, n, 2):
	if i + 1 < n:
		(A[i], A[i + 1]) = (A[i + 1], A[i])
ans = 0
for i in range(1, n - 1):
	if A[i] < A[i - 1] and A[i] < A[i + 1]:
		ans += 1
print(ans)
print(*A)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
	print(*a)
else:
	a.sort()
	ans = []
	i = 0
	vis = [0] * n
	j = n // 2
	while j < n:
		while i < n:
			if vis[i]:
				i += 1
			else:
				break
		if i == n:
			break
		while j < n:
			if a[j] <= a[i]:
				j += 1
			else:
				break
		if j == n:
			break
		ans.append(a[j])
		ans.append(a[i])
		vis[j] = 1
		vis[i] = 1
		j += 1
	for i in range(n):
		if not vis[i]:
			ans.append(a[i])
	n_ans = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			n_ans += 1
	print(n_ans)
	print(*ans)


import math
N = int(input())
arr = [int(i) for i in input().split(' ')]

def win(arr):
	if len(arr) <= 2:
		print(0)
		print(' '.join([str(i) for i in arr]))
		return
	arr.sort()
	maxPossible = math.ceil(len(arr) / 2) - 1
	minArr = arr[:maxPossible]
	maxArr = arr[maxPossible:]
	j = 0
	ans = [maxArr[0]]
	count = 0
	for i in range(1, len(maxArr)):
		if minArr[j] < maxArr[i - 1] and minArr[j] < maxArr[i]:
			count += 1
			ans.append(minArr[j])
			j += 1
		ans.append(maxArr[i])
		if j == len(minArr):
			ans += maxArr[i + 1:]
			break
	if j < len(minArr):
		ans += minArr[j:]
	print(count)
	print(' '.join([str(i) for i in ans]))
win(arr)


def solve():
	n = int(input())
	arr = sorted([int(v) for v in input().split()])
	if n < 3:
		print(0)
		print(*arr)
	else:
		if n % 2 == 0:
			ans = [arr[0]]
			l = 1
			r = n - 1
			print((n - 1) // 2)
		else:
			ans = []
			l = 0
			r = n - 1
			print(n // 2)
		while l < r:
			ans.append(arr[r])
			ans.append(arr[l])
			l += 1
			r -= 1
		ans.append(arr[l])
		print(*ans)
t = 1
for _ in range(t):
	solve()


from collections import defaultdict as dd
from sys import stdin, stdout
from bisect import bisect_left
from math import log, sqrt
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
a.sort()
k = 0
c = 0
for i in range(1, n, 2):
	ans[i] = a[k]
	k += 1
for i in range(0, n, 2):
	ans[i] = a[k]
	k += 1
for i in range(1, n - 1):
	if ans[i] < ans[i + 1] and ans[i] < ans[i - 1]:
		c += 1
print(c)
print(*ans)


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

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

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
import bisect as bs
n = N()
a = RLL()
a.sort()
key = a[n - 1 >> 1]
l = bs.bisect_left(a, key)
r = bs.bisect_right(a, key)
up = n - r
down = l
delta = max(0, (n + 1 >> 1) - (down + up))
if a[-1] == key:
	delta -= 1
print((n - 1 >> 1) - delta)
res = [0] * n
res[::2] = a[-(n + 1 >> 1):]
res[1::2] = a[:n >> 1]
print_list(res)


import sys
n = int(sys.stdin.readline())
l = sys.stdin.readline()
l = list(map(lambda x: int(x), l.split(' ')))
l = [0] + l
l.sort()
res = {}
i = 1
j = n // 2 + 1
bounus = []
while i <= n // 2:
	res[2 * i] = l[i]
	flag = False
	while j <= n:
		if l[j] > l[i]:
			flag = True
			res[2 * i - 1] = l[j]
			j += 1
			break
		bounus.append(l[j])
		j += 1
	if not flag:
		res[2 * i - 1] = bounus.pop()
	i += 1
if n % 2 == 1:
	res[n] = bounus.pop() if len(bounus) > 0 else l[-1]
k = []
a = 0
for i in range(1, n + 1):
	if res.get(i - 1, 0) > res[i] and res[i] < res.get(i + 1, 0):
		a += 1
	k.append(res[i])
print(a)
print(' '.join(list(map(lambda x: str(x), k))))


n = int(input())
(*a,) = map(int, input().split())
a.sort()
b = [0] * n
ai = 0
ans = 0
for i in range(n):
	if i % 2 == 1:
		b[i] = a[ai]
		ai += 1
for i in range(n):
	if i % 2 == 0:
		b[i] = a[ai]
		ai += 1
for i in range(1, n - 1):
	if i % 2 == 1:
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			ans += 1
print(ans)
print(*b)


import sys
n = int(sys.stdin.readline())
pricelist = [int(v) for v in sys.stdin.readline().strip().split(' ')]
pricelist.sort()
newlist = [0 for i in range(0, n)]
start = int(n / 2)
for i in range(0, start):
	newlist[i * 2] = pricelist[i + start]
	newlist[i * 2 + 1] = pricelist[i]
if n % 2 == 1:
	newlist[n - 1] = pricelist[n - 1]
total = 0
for i in range(1, n - 1, 2):
	if newlist[i] < newlist[i - 1] and newlist[i] < newlist[i + 1]:
		total += 1
print(total)
print(' '.join((str(v) for v in newlist)))


n = int(input())
a = sorted(map(int, input().split()))
print((n - 1) // 2)
for i in range(n):
	print(a[(1 - i % 2) * (n // 2) + i // 2], end=' ')


def solve(arr):
	arr.sort()
	half = len(arr) // 2
	for i in range(len(arr)):
		if i % 2 == 0:
			yield str(arr[half + i // 2])
		else:
			yield str(arr[i // 2])
N = int(input())
arr = [int(c) for c in input().split(' ')]
print(N // 2 if N % 2 == 1 else N // 2 - 1)
print(' '.join(solve(arr)))


import sys
import heapq
import copy
import math
import decimal
input = sys.stdin.readline

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

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

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

def insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def swap(a, b):
	temp = a
	a = b
	b = temp
	return [a, b]

def pri(a, b):
	s = '? ' + str(a) + ' ' + str(b)
	print(s)
	sys.stdout.flush()

def main():
	tests = 1
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	hashm = {}
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		n = inp()
		a = inlt()
		a.sort()
		ans = [0 for i in range(n)]
		j = 0
		result = 0
		for i in range(1, n, 2):
			ans[i] = a[j]
			j = j + 1
		for i in range(0, n, 2):
			ans[i] = a[j]
			j = j + 1
		for i in range(1, n, 2):
			if i == n - 1:
				break
			if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
				result += 1
		print(result)
		pr_list(ans)
main()


n = int(input())
s = [int(x) for x in input().split()]
ans = n // 2
if n % 2 == 0:
	ans -= 1
s.sort()
if n % 2 == 0:
	ptr = 0
	L = []
	for i in range(ans + 1, len(s)):
		L.append(s[i])
		if ptr < ans:
			L.append(s[ptr])
		ptr += 1
	L.append(s[ans])
	L = L[:len(s)]
	kk = 0
	for i in range(1, len(L) - 1):
		if L[i] < L[i - 1] and L[i] < L[i + 1]:
			kk += 1
	print(kk)
	print(*L)
else:
	ptr = 0
	L = []
	for i in range(ans, len(s)):
		L.append(s[i])
		if ptr < ans:
			L.append(s[ptr])
		ptr += 1
	L = L[:len(s)]
	kk = 0
	for i in range(1, len(L) - 1):
		if L[i] < L[i - 1] and L[i] < L[i + 1]:
			kk += 1
	print(kk)
	print(*L)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [0] * n
i = 0
j = n - 1
while i <= n - 1:
	ans[i] = a[j]
	j -= 1
	i += 2
i = 1
j = 0
while i <= n - 1:
	ans[i] = a[j]
	i += 2
	j += 1
print((n - 1) // 2)
print(*ans, sep=' ')


n = int(input())
l = sorted(list(map(int, input().split())))
if n < 3:
	print(0)
	print(*l)
else:
	k = [0] * n
	k[1::2] = l[:n // 2]
	k[::2] = l[n // 2:]
	print((n - 1) // 2)
	print(*k)


t = 1
for i in range(1):
	n = int(input())
	b = list(map(int, input().split()))
	b.sort()
	if n % 2 == 0:
		ans = (n - 2) // 2
		res = []
		j1 = 0
		j2 = ans
		p = 0
		while p < ans:
			res.append(b[j2])
			res.append(b[j1])
			j1 += 1
			j2 += 1
			p += 1
		res.append(b[-2])
		res.append(b[-1])
	else:
		ans = (n - 1) // 2
		j1 = 0
		j2 = ans
		res = []
		p = 0
		while p < ans:
			res.append(b[j2])
			res.append(b[j1])
			j1 += 1
			j2 += 1
			p += 1
		res.append(max(b))
	print(ans)
	print(*res)


n = int(input())
(*arr,) = map(int, input().split())
arr.sort()
half = n // 2
res = [-1] * n
if n % 2 == 0:
	res[::2] = arr[-half:]
	res[1::2] = arr[:-half]
else:
	res[::2] = arr[-half - 1:]
	res[1::2] = arr[:-half - 1]
ans = 0
for i in range(1, n - 1):
	if res[i - 1] > res[i] < res[i + 1]:
		ans += 1
print(ans)
print(*res)


n = int(input())
l = list(map(int, input().split()))
if n == 1 or n == 2:
	print(0)
	print(*l)
else:
	o = []
	l.sort()
	i = 0
	j = n - 1
	cnt = 0
	while j >= i:
		if cnt % 2 == 0:
			o.append(l[j])
			j = j - 1
		else:
			o.append(l[i])
			i = i + 1
		cnt += 1
	ans = 0
	i = 1
	while i < n - 1:
		if o[i] < o[i + 1] and o[i] < o[i - 1]:
			ans += 1
		i = i + 1
	print(ans)
	print(*o)


a = int(input())
l1 = sorted(map(int, input().split()))
l2 = []
print((a - 1) // 2)
for i in range((a + 1) // 2):
	l2.append(l1[-(i + 1)])
	l2.append(l1[i])
if a % 2:
	l2.remove(l2[-1])
print(*l2)


import sys, os.path, math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
sys.setrecursionlimit(10 ** 5)

def mod():
	return 10 ** 9 + 7

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	a = ii()
	b = sorted(lii())
	c = 0
	d = []
	e = len(b)
	if a % 2 == 0:
		for i in range(int(a / 2)):
			d.append(b[i + int(a / 2)])
			d.append(b[i])
	else:
		b.insert(math.floor(a / 2), ' ')
		for i in range(math.ceil(a / 2)):
			d.append(b[i + math.ceil(a / 2)])
			d.append(b[i])
	if e % 2 == 0:
		for i in range(1, a - 1, 2):
			if d[i - 1] > d[i] < d[i + 1]:
				c += 1
			else:
				pass
		print(c)
		for x in d:
			print(x, end=' ')
	else:
		d.remove(' ')
		for i in range(1, a - 1, 2):
			if d[i - 1] > d[i] < d[i + 1]:
				c += 1
			else:
				pass
		print(c)
		for x in d:
			print(x, end=' ')
for _ in range(1):
	solve()


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = [0] * n
i = 1
j = 0
while i < n:
	l1[i] = l[j]
	j += 1
	i += 2
i = 0
while i < n:
	l1[i] = l[j]
	j += 1
	i += 2
ans = 0
for (i, x) in enumerate(l1):
	if i == 0 or i == n - 1:
		continue
	if l1[i - 1] > l1[i] < l1[i + 1]:
		ans += 1
print(ans)
print(*l1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	print((n - 1) // 2)
	m = n // 2
	A.sort()
	B = [0] * n
	for i in range(0, m):
		B[2 * i + 1] = A[i]
	j = 0
	for i in range(m, n):
		while B[j] != 0:
			j += 1
		B[j] = A[i]
	print(' '.join((str(num) for num in B)))
f()


n = int(input())
a = list(sorted(list(map(int, input().split()))))
m = (n - 1) // 2
print(m)
x = a[:m]
y = a[m:]
s = []
for i in range(m):
	s += [y[i], x[i]]
s += y[m:]
s = list(map(str, s))
print(' '.join(s))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def binary(l, val):
	r = n - 1
	ans = -1
	id = -1
	while l <= r:
		m = (l + r) // 2
		if a[m] > val:
			ans = a[m]
			id = m
			r = m - 1
		else:
			l = m + 1
	return [ans, id]
n = I()
a = sorted(R())
if n == 1:
	print(0)
	print(*a)
	exit()
v = [1] * n
ans = [0] * n
j = 0
for i in range(1, n, 2):
	ans[i] = a[j]
	v[j] = 0
	j += 1
for i in range(0, n, 2):
	if not i:
		val = binary(j, ans[i + 1])
		if val[0] == -1:
			break
		ans[i] = val[0]
	else:
		val = binary(j, ans[i - 1])
		if val[0] == -1:
			break
		ans[i] = val[0]
	j = val[1] + 1
	v[j - 1] = 0
v = [i for i in range(n) if v[i]]
j = 0
for i in range(n):
	if not ans[i]:
		ans[i] = a[v[j]]
		j += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


def mi():
	return map(int, input().split())
for _ in range(1):
	n = int(input())
	a = list(mi())
	a.sort()
	k = 0
	out = [0] * n
	for i in range(1, n, 2):
		out[i] = a[k]
		k += 1
	for i in range(0, n, 2):
		out[i] = a[k]
		k += 1
	ans = 0
	a = out
	for i in range(1, n - 1):
		if a[i] < a[i - 1] and a[i] < a[i + 1]:
			ans += 1
	print(ans)
	print(*out)


from collections import Counter, OrderedDict
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
t = 1
for _ in range(t):
	(n,) = gil()
	a = gil()
	a.sort(reverse=True)
	ans = [a[0]]
	cnt = 0
	a = deque(a[1:])
	while a:
		if len(a) > 1:
			cnt += 1
		ans.append(a.pop())
		if a:
			ans.append(a.popleft())
	print(cnt)
	print(*ans)


n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
l = list()
i = 0
while i <= n - i - 1:
	l.append(a[i])
	l.append(a[n - i - 1])
	i += 1
end = 0
if n % 2 != 0:
	print(n // 2)
else:
	print(n // 2 - 1)
l = l[0:n]
print(*l)


(n, a) = (int(input()), [int(x) for x in input().split()])
s = sorted(a)[::-1]
(a, b) = (s[:n // 2 + n % 2], s[n // 2 + n % 2:])
o = []
for (c, v) in zip(a, b):
	o += [c]
	o += [v]
(c, v) = (len(a), len(b))
if c > v:
	o += [a[c - 1]]
elif v > c:
	o += [b[v - 1]]
c = 0
for i in range(1, n - 1):
	if o[i - 1] > o[i] < o[i + 1]:
		c += 1
o2 = o[1::2] + o[::2]
v = 0
for i in range(1, n - 1):
	if o2[i - 1] > o2[i] < o2[i + 1]:
		v += 1
if v > c:
	print(v)
	print(*o2)
else:
	print(c)
	print(*o)


n = int(input())
a = sorted([*map(int, input().split())])
ans = []
(l, i, j) = ((n - 1) // 2, 0, 0)
while i < l or j < n - l:
	if i < l and (i + j) % 2:
		ans.append(a[i])
		i += 1
	elif j < l and (i + j) % 2 == 0:
		ans.append(a[j + l])
		j += 1
	else:
		ans.append(a[j + l])
		j += 1
print(l)
print(*ans)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
t = (n - 1) // 2
print(t)
cnt = 1
i = 0
j = n - 1
while cnt <= n:
	if cnt % 2 == 0:
		print(a[i], end=' ')
		i += 1
	else:
		print(a[j], end=' ')
		j -= 1
	cnt += 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [-1] * n
k = 0
ans = 0
for i in range(1, len(b), 2):
	b[i] = a[k]
	k += 1
for i in range(0, len(b), 2):
	b[i] = a[k]
	k += 1
print((n - 1) // 2)
print(*b)


def iinput():
	return [int(i) for i in input().split()]
n = int(input())
mas = sorted(iinput())
k = (n + 1) // 2
ans1 = []
ans2 = []
ans = []
for i in range(n):
	if i < k:
		ans2 += [mas.pop()]
	else:
		ans1 += [mas.pop()]
for i in range(n):
	if not i % 2:
		ans += [ans2.pop()]
	else:
		ans += [ans1.pop()]
print(n // 2 - (n + 1) % 2)
print(*ans)


n = int(input())
a = list(map(int, input().split(' ')))
b = a.copy()
b.sort()
first = b[0:n // 2]
second = b[n // 2:]
ans = []
f = 0
s = 0
flags = True
for i in range(n):
	if flags == False:
		ans.append(first[f])
		f += 1
	else:
		ans.append(second[s])
		s += 1
	flags = not flags
count = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		count += 1
print(count)
for i in ans:
	print(i, end=' ')


import sys
input = sys.stdin.readline

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

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

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

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

def solution(n, arr):
	if n <= 2:
		print(0)
		for i in range(n):
			print(arr[i], end=' ')
	else:
		arr.sort()
		l = 0
		r = n - 1
		print((n - 1) // 2)
		while l <= r:
			print(arr[r], end=' ')
			r -= 1
			if l <= r:
				print(arr[l], end=' ')
				l += 1
n = inp()
arr = inlt()
solution(n, arr)
print()


n = int(input())
l = list(map(int, input().split()))[:n]
f = [0] * n
l.sort(reverse=True)
cnt = 0
for i in range(n):
	if i % 2 == 1:
		f[i] = l.pop()
for i in range(n):
	if f[i] == 0:
		f[i] = l.pop()
if n % 2 == 0:
	for i in range(1, n - 2, 2):
		if f[i] < f[i - 1] and f[i] < f[i + 1]:
			cnt += 1
else:
	for i in range(1, n - 1, 2):
		if f[i] < f[i - 1] and f[i] < f[i + 1]:
			cnt += 1
print(cnt)
print(*f)


import math
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
a.sort()
ar = []
a1 = a[:ans]
a2 = a[ans:n]
a1.reverse()
a2.reverse()
for i in range(n):
	if i % 2 == 0:
		ar.append(a2.pop())
	elif i % 2 == 1 and len(a1) != 0:
		ar.append(a1.pop())
if len(a2) > 0:
	ar = ar + a2
print(ans)
print(*ar)


n = int(input())
a = list(map(int, input().split()))
a.sort()
pointer = 0
bckt = [-1] * n
for i in range(1, n, 2):
	bckt[i] = a[pointer]
	pointer += 1
for i in range(0, n, 2):
	bckt[i] = a[pointer]
	pointer += 1
ct = 0
for i in range(1, n - 1):
	if bckt[i] < bckt[i - 1] and bckt[i] < bckt[i + 1]:
		ct += 1
print(ct)
print(*bckt)


import sys
import copy
n = int(input())
lst1 = list(map(int, input().split()))
lst2 = [None] * n
lst1.sort()
ans = (n - 1) // 2
print(ans)
if ans > 0:
	for i in range(n):
		if i < ans:
			lst2[i * 2 + 1] = lst1[i]
		else:
			if n & 1 == 0 and i == n - 1:
				lst2[i] = lst1[i]
				continue
			lst2[(i - ans) * 2] = lst1[i]
	print(*lst2)
else:
	print(*lst1)


n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
f = [0] * n
k = 0
for j in range(n):
	if j % 2 != 0:
		f[j] = s[k]
		k += 1
for j in range(n):
	if j % 2 == 0:
		f[j] = s[k]
		k += 1
total = 0
for j in range(1, n - 1, 1):
	if f[j - 1] > f[j] and f[j + 1] > f[j]:
		total += 1
print(total)
print(*f)


x = int(input())
arr = list(map(int, input().split()))
arr.sort()
temp = []
n = 0
if x % 2 != 0:
	mid = x // 2
	arr1 = arr[:mid]
	arr2 = arr[mid:]
	for i in range(mid):
		temp.append(arr2[i])
		temp.append(arr1[i])
	temp.append(arr[-1])
	for i in range(1, x, 2):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			n += 1
	print(n)
	print(*temp)
else:
	mid = x // 2
	arr1 = arr[:mid]
	arr2 = arr[mid:]
	for i in range(mid):
		temp.append(arr2[i])
		temp.append(arr1[i])
	for i in range(1, x - 1, 2):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			n += 1
	print(n)
	print(*temp)


import sys
input = sys.stdin.readline
n = int(input())
prices = sorted(map(int, input().split()))
if n < 3:
	print(0)
	print(*prices)
else:
	max_buy = n // 2 - 1 if n % 2 == 0 else n // 2
	buy_index = 0
	nb_index = max_buy
	output = []
	while buy_index < max_buy or nb_index < n:
		if nb_index < n:
			output.append(prices[nb_index])
			nb_index += 1
		if buy_index < max_buy:
			output.append(prices[buy_index])
			buy_index += 1
	print(max_buy)
	print(*output)


n = int(input())
A = [int(x) for x in input().split()]
A.sort()
R = [None] * n
R[1::2] = A[:n // 2]
R[0::2] = A[n // 2:]
r = 0
for i in range(1, n - 1):
	r += R[i - 1] > R[i] < R[i + 1]
print(r)
print(*R)


def check(M):
	ind = 0
	ans = []
	cur = [False] * n
	for i in range(M, n):
		if 0 < ind < M and u[ind - 1] < u[i] > u[ind] or (ind == 0 and u[i] > u[ind]) or (ind == M and u[i] > u[ind - 1]):
			ans.append(u[i])
			cur[i] = True
			if ind < M:
				ans.append(u[ind])
				cur[ind] = True
			ind += 1
	if ind == M + 1:
		for i in range(n):
			if not cur[i]:
				ans.append(u[i])
		return ans
	return False
n = int(input())
u = sorted(list(map(int, input().split())))
L = 0
R = n
gans = u[:]
while R - L > 1:
	M = (L + R) // 2
	ans = check(M)
	if ans == False:
		R = M
	else:
		L = M
		gans = ans[:]
print(L)
print(*gans)


import sys
n = int(sys.stdin.readline())
ss = sys.stdin.readline().strip().split(' ')
pricelist = []
for v in ss:
	pricelist.append(int(v))
pricelist.sort(reverse=True)
newlist = [0 for i in range(0, n)]
start = int((n + 1) / 2)
for i in range(0, start):
	newlist[i * 2] = pricelist[i]
waitlist = []
pt = 1
total = 0
for i in range(start, n):
	if pt < n - 1 and pricelist[i] < newlist[pt - 1] and (pricelist[i] < newlist[pt + 1]):
		newlist[pt] = pricelist[i]
		total += 1
		pt += 2
	else:
		waitlist.append(pricelist[i])
for v in waitlist:
	newlist[pt] = v
	pt += 2
print(total)
print(' '.join((str(v) for v in newlist)))


import sys

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

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
a = get_list()
a.sort()
if n % 2 == 1:
	ans = n // 2
else:
	ans = n // 2 - 1
res = []
j = ans
for i in range(ans):
	res.extend([a[j], a[i]])
	j += 1
if n % 2 == 1:
	res.append(a[-1])
else:
	res.extend([a[-2], a[-1]])
print(ans)
print(*res)


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
n = I()
l = L()
l.sort()
b = [0] * n
(b[::2], b[1::2]) = (l[n // 2:], l[:n // 2])
print(sum((b[i - 1] > b[i] < b[i + 1] for i in range(1, n - 1))))
print(*b)


n = int(input())
a = list(map(int, input().split()))
a.sort()
sp = 0
ep = n - 1
ans = []
t = 1
while sp <= ep:
	if t == 0:
		ans.append(a[sp])
		sp += 1
		t = 1
	else:
		ans.append(a[ep])
		ep -= 1
		t = 0
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
print(*ans)


n = int(input())
vect = [int(x) for x in input().split()]
vect = sorted(vect)
if n % 2 == 0:
	print(int(n / 2) - 1)
	print(vect[n - int(n / 2) - 1], end=' ')
	for i in range(0, int(n / 2) - 1):
		print(vect[i], vect[i + int(n / 2)], end=' ')
	print(vect[n - 1])
else:
	print(int(n / 2))
	print(vect[n - int(n / 2) - 1], end=' ')
	for i in range(0, int(n / 2)):
		print(vect[i], vect[i + int(n / 2) + 1], end=' ')


import sys
n = int(input())
A = sorted(list(map(int, input().split())))
Ans = A
if n % 2 == 0:
	Ans.insert(0, -1)
nl = len(Ans)
Amx = Ans[nl // 2:]
Amn = Ans[:nl // 2]
output = [Amx[0]]
Amx = Amx[1:]
c = 0
for i in range(len(Amx)):
	if output[i * 2] > Amn[i] and Amn[i] < Amx[i]:
		c += 1
	output.append(Amn[i])
	output.append(Amx[i])
if len(output) != n:
	output.remove(-1)
	c -= 1
print(c)
print(*output)


(N,) = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
if N % 2:
	Y = [0] * N
	for i in range(0, N, 2):
		Y[i] = X.pop()
	for i in range(1, N, 2):
		Y[i] = X.pop()
	print(N // 2)
	print(*Y)
else:
	Y = [0] * N
	for i in range(0, N, 2):
		Y[i] = X.pop()
	Y[-1] = X.pop()
	for i in range(1, N - 1, 2):
		Y[i] = X.pop()
	print((N - 1) // 2)
	print(*Y)


n = int(input())
a = sorted(map(int, input().split()))
l = [a[(1 - i % 2) * (n // 2) + i // 2] for i in range(n)]
c = 0
for i in range(1, n - 1):
	if l[i - 1] > l[i] < l[i + 1]:
		c += 1
print(c)
print(' '.join(map(str, l)))


n = int(input()) - 1
print((n - n % 2) // 2)
x = list(map(int, input().split()))
x.sort()
mx = x[(n + n % 2) // 2:]
mn = x[:(n + n % 2) // 2]
for i in range(len(mn)):
	print(mx[i], mn[i], end=' ')
if not n % 2:
	print(mx[-1])


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
order1 = [-1 for _ in range(n)]
l = 0
r = n - 1
lNext = True
for i in range(n):
	if lNext:
		order1[i] = a[l]
		l += 1
	else:
		order1[i] = a[r]
		r -= 1
	lNext = not lNext
nSpheres1 = 0
for i in range(1, n - 1):
	if order1[i - 1] > order1[i] < order1[i + 1]:
		nSpheres1 += 1
order2 = [-1 for _ in range(n)]
l = 0
if n % 2 == 0:
	r = n // 2
else:
	r = n // 2 + 1
lNext = True
for i in range(n):
	if lNext:
		order2[i] = a[l]
		l += 1
	else:
		order2[i] = a[r]
		r += 1
	lNext = not lNext
nSpheres2 = 0
for i in range(1, n - 1):
	if order2[i - 1] > order2[i] < order2[i + 1]:
		nSpheres2 += 1
if nSpheres1 > nSpheres2:
	print(nSpheres1)
	print(' '.join([str(x) for x in order1]))
else:
	print(nSpheres2)
	print(' '.join([str(x) for x in order2]))


import sys
import math
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
X = N // 2
it1 = iter(A[:X])
it2 = iter(A[X:])
x = True
y = True
ans = []
while x or y:
	try:
		ans.append(next(it2))
	except StopIteration:
		x = False
	try:
		ans.append(next(it1))
	except StopIteration:
		y = False
print((N - 1) // 2)
print(' '.join(map(str, ans)))


n = int(input())
a = list(map(int, input().strip().split()))
m = (n - 1) // 2
a.sort()
l = [a[m]]
for i in range(m):
	l.append(a[i])
	l.append(a[m + 1 + i])
for i in range(2 * m + 1, n):
	l.append(a[i])
print(m)
print(*l)


from math import ceil
n = int(input())
l = list(map(int, input().split()))
print(ceil(n / 2) - 1)
i = 0
l.sort()
while i < n - 1:
	(l[i], l[i + 1]) = (l[i + 1], l[i])
	i += 2
print(*l)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if len(a) % 2 == 0:
	ind = len(a) / 2 - 1
else:
	ind = (len(a) - 1) / 2
ind = int(ind)
print(ind)
b = a[:ind]
c = a[ind:]
k = 0
l = 0
flag = 0
for i in range(len(a)):
	if flag == 0:
		print(c[k], end=' ')
		k += 1
		flag = 1
	elif flag == 1 and l != ind:
		print(b[l], end=' ')
		l += 1
		flag = 0
if n % 2 == 0:
	print(c[k])


N = int(input())
array = [int(x) for x in input().split()]
print((N - 1) // 2)
if N == 2:
	print(*array)
	exit()
array = sorted(array)
tobeprinted = [0] * N
small = array[0:(N - 1) // 2]
large = array[(N - 1) // 2:]
counter = 0
for i in range(0, N, 2):
	tobeprinted[i] = large[counter]
	counter += 1
counter = 0
for i in range(1, N, 2):
	tobeprinted[i] = small[counter]
	counter += 1
	if counter == (N - 1) // 2:
		tobeprinted[-1] = large[-1]
		break
print(*tobeprinted)


n = int(input())
l = [int(f) for f in input().split()]
l.sort()
a = 1
i = 0
j = n - 1
if n % 2 == 1:
	print(int(n // 2))
	while i <= j:
		if a:
			print(l[j], end=' ')
			j -= 1
			a = 0
		else:
			print(l[i], end=' ')
			i += 1
			a = 1
else:
	print(int(n // 2) - 1)
	while i <= j:
		if a:
			print(l[j], end=' ')
			j -= 1
			a = 0
		else:
			print(l[i], end=' ')
			i += 1
			a = 1


import itertools
import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '5\n1 2 3\n\n\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield input()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]

def solve(a):
	a = sorted(a)
	start = len(a) // 2
	total = 0
	result = [-1 for _ in range(len(a))]
	pos = 0
	while pos < len(a):
		result[pos] = a[start + pos // 2]
		pos += 1
		if pos >= len(a):
			break
		result[pos] = a[pos // 2]
		if pos != len(a) - 1:
			total += 1
		pos += 1
	return (total, result)
n = getType(int)
a = getArray(int)
(total, result) = solve(a)
print(total)
print(' '.join([str(x) for x in result]))


n = int(input())
arr = list(map(int, input().split()))
if n > 2:
	ans = (n - 1) // 2
	arr.sort()
	my_list = []
	for i in range(n // 2):
		my_list.append(arr[n - i - 1])
		my_list.append(arr[i])
	if n % 2:
		my_list.append(arr[i + 1])
	cnt = 0
	i = 1
	for j in range(ans):
		if my_list[i] < my_list[i - 1] and my_list[i] < my_list[i + 1]:
			cnt += 1
		i += 2
	print(cnt)
	print(*my_list)
else:
	print(0)
	print(*arr)


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	ar = inpt()
	ar.sort(reverse=True)
	for i in range(1, n - 1, 2):
		(ar[i], ar[i + 1]) = (ar[i + 1], ar[i])
	ans = 0
	for i in range(1, n - 1):
		if ar[i + 1] > ar[i] < ar[i - 1]:
			ans += 1
	print(ans)
	print(*ar)
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())
a = list(map(int, input().split()))
s1 = (n - 1) // 2
print(s1)
if s1:
	a = sorted(a)
	for i in range(0, n - 1, 2):
		(a[i], a[i + 1]) = (a[i + 1], a[i])
print(*a)


n = int(input())
l = input().split()
li = [int(i) for i in l]
li.sort()
l = []
z = li[:n // 2]
y = li[n // 2:]
curr1 = 0
curr2 = 0
for i in range(n):
	if i % 2 == 0:
		l.append(y[curr1])
		curr1 += 1
		continue
	l.append(z[curr2])
	curr2 += 1
count = 0
for i in range(1, n - 1):
	if l[i] < l[i + 1] and l[i] < l[i - 1]:
		count += 1
print(count)
for i in l:
	print(i, end=' ')
print()


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
i = 0
j = n - 2
ans = [a[-1]]
count = 0
while i < j:
	ans.append(a[i])
	ans.append(a[j])
	i += 1
	j -= 1
	count += 1
if i == j:
	ans.append(a[i])
print(count)
print(*ans)


s = int(input().strip())
a = [int(x) for x in input().strip().split()]
l = len(a)
a = sorted(a)
if l % 2 != 0:
	print(l // 2)
	b = a[:l // 2 - 1]
	c = a[l // 2:]
	print(c[0], end=' ')
	for i in range(l // 2):
		print(a[i], c[i + 1], end=' ')
else:
	print(l // 2 - 1)
	b = a[:l // 2]
	c = a[l // 2:]
	for i in range(l // 2):
		print(c[i], a[i], end=' ')


def main():
	N = int(input())
	A = [int(i) for i in input().split()]
	A.sort()
	B = [0] * N
	idx = 0
	for i in range(1, N, 2):
		B[i] = A[idx]
		idx += 1
	for i in range(N):
		if B[i] != 0:
			continue
		B[i] = A[idx]
		idx += 1
	ans = 0
	for i in range(1, N - 1):
		if B[i - 1] > B[i] and B[i] < B[i + 1]:
			ans += 1
	print(ans)
	print(*B)
main()


t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	spheres = 0
	print((n - 1) // 2)
	d = 0
	for i in range(n):
		if i % 2 == 0:
			print(a[n // 2 + d], end=' ')
		else:
			print(a[d], end=' ')
			d += 1
	print()


n = int(input())
r = list(map(int, input().split()))
r = sorted(r)
i = 0
while i + 1 <= len(r) - 1:
	a = r[i]
	b = r[i + 1]
	r[i + 1] = a
	r[i] = b
	i = i + 2
print((n - 1) // 2)
print(*r)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n < 3:
	print(0)
	print(*l)
else:
	arr = [0] * n
	j = 0
	for i in range(1, n, 2):
		arr[i] = l[j]
		j += 1
	for i in range(0, n, 2):
		arr[i] = l[j]
		j += 1
	ans = 0
	for i in range(1, n - 1):
		if arr[i - 1] > arr[i] and arr[i + 1]:
			ans += 1
	print(ans)
	print(*arr)


n = int(input())
a = list(map(int, input().split()))
a.sort()
print((n + 1) // 2 - 1)
b = []
for x in range(n // 2):
	b.append(a[-x - 1])
	b.append(a[x])
if n % 2:
	b.append(a[n // 2])
print(*b)


def solve(n, ices):
	ices = sorted(ices)
	(former, latter) = (ices[:n // 2], ices[n // 2:])
	res = 0
	res_ice = []
	for i in range((n - 1) // 2):
		res_ice.append(latter[i])
		res_ice.append(former[i])
		if former[i] < latter[i]:
			res += 1
	res_ice.append(latter[-1])
	if n % 2 == 0:
		res_ice.append(former[-1])
	return (res, ' '.join(list(map(str, res_ice))))

def main():
	n = int(input())
	ices = list(map(int, input().split()))
	(res1, res2) = solve(n, ices)
	print(res1)
	print(res2)
main()


import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ind = n // 2
i = 0
j_r = ind + bisect.bisect_left(l[ind:], l[i] + 1)
j = j_r
ans = []
while i < j_r and j < n:
	ans.append(l[j])
	ans.append(l[i])
	j += 1
	i += 1
while True:
	if i < j_r:
		ans.append(l[i])
	else:
		break
	i += 1
while True:
	if j < n:
		ans.append(l[j])
	else:
		break
	j += 1
s = 0
for i in range(1, n - 1, 2):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		s += 1
print(s)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = []
c = n
while c > 0:
	ans.append(arr.pop(-1))
	c -= 1
	if c <= 0:
		break
	ans.append(arr.pop(0))
	c -= 1
print((n - 1) // 2)
print(*ans)


from sys import stdout, stdin
from collections import defaultdict, deque
import math
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
l.sort()
m = n // 2
li = l[:m]
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
for i in range(m):
	stdout.write(str(l[m + i]) + ' ' + str(l[i]) + ' ')
if n % 2 != 0:
	stdout.write(str(l[-1]) + '\n')
else:
	stdout.write('\n')


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
n = int(input())
a = sorted(list(map(int, input().split())))
k = []
if n % 2 == 0:
	print(n // 2 - 1)
	for i in range(n // 2):
		k.append(a[n // 2 + i])
		k.append(a[i])
else:
	print(n // 2)
	for i in range(n // 2):
		k.append(a[n // 2 + i])
		k.append(a[i])
	k.append(a[n - 1])
print(*k)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(math.ceil((n - 2) / 2))
print(a[n - 1], end=' ')
a.pop(n - 1)
if len(a) > 0:
	for i in range(1, n - 1):
		if i % 2 == 1:
			print(a[0], end=' ')
			a.pop(0)
		else:
			print(a[len(a) - 1], end=' ')
			a.pop(len(a) - 1)
	print(a[0])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
sys.setrecursionlimit(10 ** 8)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
try:
	FILE_POINTER = open('input.inpt')
	input = FILE_POINTER.readline
except:
	FILE_POINTER = None
n = int(input())
arr = list(map(int, input().strip().split()))
count = 0
ans = [0] * n
arr.sort()
j = 0
for i in range(1, n, 2):
	ans[i] = arr[j]
	j += 1
ans[0] = arr[j]
j += 1
for i in range(2, n, 2):
	ans[i] = arr[j]
	j += 1
	if ans[i - 1] < ans[i] and ans[i - 1] < ans[i - 2]:
		count += 1
print(count)
print(*ans)
if FILE_POINTER:
	FILE_POINTER.close()


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
n = II()
aa = LI()
aa.sort()

def ok(m):
	i = m
	for a in aa[:m]:
		while i + 1 < n and aa[i] <= a:
			i += 1
		if i + 1 >= n:
			return False
		i += 1
	return True
l = 0
r = (n - 1) // 2 + 1
while l + 1 < r:
	m = (l + r) // 2
	if ok(m):
		l = m
	else:
		r = m
ans = []
i = l
for a in aa[:l]:
	while 1:
		ans.append(aa[i])
		i += 1
		if ans[-1] > a:
			break
	ans.append(a)
for a in aa[i:]:
	ans.append(a)
print(l)
print(*ans)


def do(l, n):
	o = l[0:n // 2]
	k = l[n // 2:n]
	nlist = []
	for i in range(n // 2):
		nlist.append(str(k[i]))
		nlist.append(str(o[i]))
	if n % 2 == 1:
		nlist.append(str(k[n // 2]))
	return nlist
num = int(input())
l = list(map(int, input().split()))
l.sort()
a = do(l, num)
cnt = 0
for i in range(1, num - 1):
	if int(a[i - 1]) > int(a[i]) and int(a[i + 1]) > int(a[i]):
		cnt += 1
print(cnt)
print(' '.join(a))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
res = []
for i in range(n // 2):
	res.append(arr[n // 2 + i])
	res.append(arr[i])
if n % 2:
	res.append(arr[-1])
res2 = 0
for i in range(1, n - 1):
	if res[i] < res[i - 1] and res[i] < res[i + 1]:
		res2 += 1
print(res2)
print(' '.join([str(i) for i in res]))


import random
n = int(input())
inputString = input()
a = list(range(n))
inputList = inputString.split()
for i in range(n):
	a[i] = int(inputList[i])
a.sort()
newOrder = list(range(n))
if n % 2 == 0:
	half = round(n / 2) - 1
	for i in range(1, half + 1):
		newOrder[2 * i - 1] = a[i - 1]
	for i in range(0, half + 1):
		newOrder[2 * i] = a[i + half]
	newOrder[n - 1] = a[n - 1]
else:
	half = round((n - 1) / 2)
	for i in range(1, half + 1):
		newOrder[2 * i - 1] = a[i - 1]
	for i in range(0, half + 1):
		newOrder[2 * i] = a[i + half]
print(half)
print(*newOrder)


import sys
import math
import random
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
ara.sort()
ans = [0] * n
i = 1
j = 0
while i < n:
	ans[i] = ara[j]
	j += 1
	i += 2
i = 0
while j < n:
	ans[i] = ara[j]
	i += 2
	j += 1
tot = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i]:
		if ans[i + 1] > ans[i]:
			tot += 1
print(tot)
print(*ans)


n = int(input())
a = list(sorted(list(map(int, input().split()))))
k = (n - 1) // 2
b = []
print(k)
j = -1
l = 0
for i in range(n):
	if i % 2 == 0:
		b.append(a[j])
		j -= 1
	else:
		b.append(a[l])
		l += 1
print(*b, sep=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [0] * n
for i in range(n // 2):
	ans[1 + i * 2] = a[i]
for i in range(n // 2, n):
	ans[(i - n // 2) * 2] = a[i]
co = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		co += 1
print(co)
print(*ans)


def MI():
	return map(int, input().split())
for _ in range(1):
	n = int(input())
	arr = list(MI())
	ans = (n - 1) // 2
	arr.sort()
	out = [-1 for i in range(n)]
	for i in range(0, n, 2):
		out[i] = arr.pop()
	for i in range(1, n, 2):
		out[i] = arr.pop()
	print(ans)
	print(*out)


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

def printis(xs):
	print(' '.join(map(str, xs)))
n = int(input())
ps = readis()
if n < 3:
	print(0)
	printis(ps)
	exit(0)
k = (n - 1) // 2
ps = sorted(ps)
consumer_ps = []
i = 0
j = len(ps) - 1
while i < j:
	consumer_ps.append(ps[j])
	j -= 1
	consumer_ps.append(ps[i])
	i += 1
if i == j:
	consumer_ps.append(ps[j])
print(k)
printis(consumer_ps)


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from itertools import permutations, combinations, combinations_with_replacement
mod = 1000000007

def get_int():
	return int(sys.stdin.readline().strip())

def get_str():
	return sys.stdin.readline().strip()

def get_float():
	return float(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def get_floats():
	return map(float, sys.stdin.readline().strip().split())

def list_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def list_strs():
	return list(map(str, sys.stdin.readline().strip().split()))

def list_floats():
	return list(map(float, sys.stdin.readline().strip().split()))
n = get_int()
l = list_ints()
l.sort()
x = [0] * n
j = 1
for i in range(0, n // 2):
	x[j] = l[i]
	j += 2
j = 0
for i in range(n // 2, n):
	x[j] = l[i]
	j += 2
cnt = 0
for i in range(1, n - 1):
	if x[i - 1] > x[i] < x[i + 1]:
		cnt += 1
print(cnt)
for i in x:
	print(i, end=' ')


n = int(input())
a = [int(inp) for inp in input().split()]
a.sort()
i = 0
j = len(a) // 2
b = []
sw = 1
while j < len(a) or i < len(a) // 2:
	if sw:
		b.append(a[j])
		j += 1
	else:
		b.append(a[i])
		i += 1
	sw = 1 - sw
res = 0
i = 1
while i < len(b) - 1:
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		res += 1
		i += 1
	i += 1
print(res)
print(*b, sep=' ')


n = int(input())
ices = list(map(int, input().split()))
ices.sort()
purchase = (n - 1) // 2
l = 0
r = len(ices) - 1
mid = l + (r - l) // 2
temp = mid
res = []
while mid <= r:
	res.append(ices[mid])
	mid += 1
	if l < temp:
		res.append(ices[l])
		l += 1
print(purchase)
for i in res:
	print(i, end=' ')


import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
import heapq
INF = 10 ** 20
MOD = 998244353
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : map(int, sys.stdin.readline().rstrip().split())
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
flush = lambda : sys.stdout.flush()

def main():
	n = ni()
	a = na()
	a.sort()
	idx = n // 2
	cheap = a[:idx]
	expensive = a[idx:]
	res = []
	for i in range(n):
		if not i % 2:
			res.append(expensive[i // 2])
		else:
			res.append(cheap[i // 2])
	ans = 0
	for i in range(1, n - 1, 2):
		if res[i - 1] > res[i] < res[i + 1]:
			ans += 1
	print(ans)
	print(*res, sep=' ')
main()


import math
n = int(input())
arr = [int(x) for x in input().split()]
lis = [None for i in range(n)]
arr.sort()
if n < 3:
	print(0)
	print(*arr)
	exit()
j = 0
i = 1
for k in range(math.ceil(n / 2) - 1):
	lis[i] = arr[j]
	i += 2
	j += 1
for k in range(n):
	if lis[k]:
		continue
	else:
		lis[k] = arr[j]
		j += 1
print(math.ceil(n / 2) - 1)
print(*lis)


n = int(input())
a = sorted(map(int, input().split()))
mas = [0] * n
j = 1
for i in range(n):
	if j >= n:
		j = 0
	mas[j] = a[i]
	j += 2
ans = 0
for i in range(1, n - 1):
	ans += mas[i - 1] > mas[i] < mas[i + 1]
print(ans)
print(*mas)


n = int(input())
ch = input()
l = ch.split()
for i in range(len(l)):
	l[i] = int(l[i])
l = sorted(l)
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
ch = ''
if n % 2 == 0:
	while l != []:
		ch += str(l[len(l) - 1])
		ch += ' '
		del l[len(l) - 1]
		ch += str(l[0])
		ch += ' '
		del l[0]
else:
	for i in range(n // 2):
		ch += str(l[len(l) - 1])
		ch += ' '
		del l[len(l) - 1]
		ch += str(l[0])
		ch += ' '
		del l[0]
	ch += str(l[0])
print(ch)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
l = []
t = 0
i = 0
j = n // 2
if n == 1:
	print(0)
	print(a[0])
elif n == 2:
	print(0)
	print(a[0], a[1])
else:
	while i < n // 2 or j < n:
		if j < n:
			l.append(a[j])
			j += 1
		if i < n // 2:
			l.append(a[i])
			i += 1
	for i in range(1, n - 1):
		if l[i] < l[i - 1] and l[i] < l[i + 1]:
			t += 1
	print(t)
	for i in range(n):
		print(l[i], end=' ')
	print()


n = int(input())
A = list(map(int, input().split()))
A.sort()
B = A[:n // 2]
B.reverse()
C = A[n // 2:]
C.reverse()
ans = [-1] * n
for i in range(n):
	if i % 2 == 0:
		ans[i] = C.pop()
	else:
		ans[i] = B.pop()
if n % 2 == 1:
	temp = 0
	for i in range(n):
		if i % 2 == 1:
			if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
				temp += 1
else:
	temp = 0
	for i in range(n):
		if i % 2 == 1 and i != n - 1:
			if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
				temp += 1
print(temp)
print(*ans)


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

def create(vl, vr):
	B = [0] * n
	s = 0
	e = n - 1
	if vl is not None:
		B[s] = vl
		s += 1
	if vr is not None:
		B[-1] = vr
		e -= 1
	j = -1
	for i in range(s, e + 1, 2):
		j += 1
		while A[j] in (vl, vr):
			if vl is not None and A[j] == vl:
				vl = None
			else:
				assert vr is not None
				vr = None
			j += 1
			continue
		B[i] = A[j]
	for i in range(s + 1, e + 1, 2):
		j += 1
		while A[j] in (vl, vr):
			if vl is not None and A[j] == vl:
				vl = None
			else:
				assert vr is not None
				vr = None
			j += 1
			continue
		B[i] = A[j]
	tot = 0
	for i in range(1, n - 1):
		tot += B[i - 1] > B[i] < B[i + 1]
	return (tot, tuple(B))
ans = create(None, None)
cnt = {x: 0 for x in A}
for x in A:
	cnt[x] += 1
C = [(c, x) for (x, c) in cnt.items()]
C.sort(reverse=True)
ans = max(ans, create(C[0][1], None))
if C[0][0] > 1:
	ans = max(ans, create(C[0][1], C[0][1]))
if len(C) > 1:
	ans = max(ans, create(C[0][1], C[1][1]))
print(ans[0])
print(*ans[1])


import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def print_X(A, right, N):
	print(right)
	ans = []
	arr1 = A[:right]
	arr2 = A[N - right - 1:]
	arr3 = A[right:N - right - 1]
	for j in range(2 * right + 1):
		if j % 2 == 0:
			ans.append(arr2[j // 2])
		elif j % 2 == 1:
			ans.append(arr1[j // 2])
	ans += arr3
	print(*ans)
	return

def works(x, A, N):
	arr1 = A[:x]
	arr2 = A[N - x - 1:]
	for j in range(x):
		if arr1[j] >= arr2[j]:
			return False
	return True

def solve():
	N = getInt()
	A = getInts()
	A.sort()
	if N < 3:
		print(0)
		print(*A)
		return
	left = 1
	right = N // 2 if N % 2 == 1 else N // 2 - 1
	if works(right, A, N):
		print_X(A, right, N)
		return
	while right - left > 1:
		middle = (left + right) // 2
		if works(middle, A, N):
			left = middle
		else:
			right = middle
	print_X(A, left, N)
	return
solve()


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
l2 = list(range(n))
ind = 0
for i in range(1, n, 2):
	l2[i] = l[ind]
	ind += 1
for i in range(0, n, 2):
	l2[i] = l[ind]
	ind += 1
print((n - 1) // 2)
print(*l2)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n % 2 == 0:
	print(n // 2 - 1)
	for i in range(n // 2 - 1):
		(a[2 * i + 1], a[2 * i]) = (a[2 * i], a[2 * i + 1])
	print(*a)
else:
	print(n // 2)
	for i in range(n // 2):
		(a[2 * i + 1], a[2 * i]) = (a[2 * i], a[2 * i + 1])
	print(*a)


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

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

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	n = inp()
	a = lis()
	r = [0 for i in range(n)]
	a.sort()
	for i in range(n):
		if i % 2 == 0:
			r[i] = a[-1 - i // 2]
		else:
			r[i] = a[i // 2]
	print((n - 1) // 2)
	print(*r)


import sys
n = int(input())
spheres = list(map(int, input().split()))
spheres.sort()
small = spheres[:n // 2]
big = spheres[n // 2:]
res = []
for i in range(n):
	if i % 2 == 0:
		res.append(big[i // 2])
	else:
		res.append(small[i // 2])
print(len(small) if n % 2 == 1 else len(small) - 1)
print(*res)


import math

def f(a, x):
	b = [0 for i in range(n)]
	i = 0
	for k in range(0, 2 * x, 2):
		b[k + 1] = a[i]
		i += 1
	k = 0
	for val in a[-(x + 1):]:
		b[k] = val
		k += 2
	k = 2 * x + 1
	for val in a[x:-(x + 1)]:
		b[k] = val
		k += 1
	cnt = 0
	for i in range(1, n - 1):
		cnt += b[i] < b[i - 1] and b[i] < b[i + 1]
	return (cnt >= x, b)
n = int(input())
a = list(map(int, input().split()))
a.sort()
(low, high) = (0, n // 2 - 1 if n % 2 == 0 else n // 2)
while low < high - 1:
	mid = (low + high) // 2
	if f(a, mid)[0]:
		low = mid
	else:
		high = mid - 1
ans = f(a, high)
if ans[0]:
	print(high)
else:
	print(low)
	ans = f(a, low)
for x in ans[1]:
	print(x, end=' ')
print()


n = int(input())
l = list(map(int, input().split()))
l.sort()
ll = []
if n == 1:
	print(0)
	print(l[0])
elif n == 2:
	print(0)
	print(l[0], l[1])
elif n % 2 == 0:
	j = 0
	buys = 0
	for i in range(n // 2, n):
		ll.append(l[i])
		if j < n // 2:
			ll.append(l[j])
			j += 1
	for i in range(1, len(ll) - 2):
		if ll[i - 1] > ll[i] < ll[i + 1]:
			buys += 1
	print(buys)
	for i in ll:
		print(i, end=' ')
else:
	j = 0
	buys = 0
	for i in range(n // 2, n):
		ll.append(l[i])
		if j < n // 2:
			ll.append(l[j])
			j += 1
	for i in range(1, len(ll) - 1):
		if ll[i - 1] > ll[i] < ll[i + 1]:
			buys += 1
	print(buys)
	for i in ll:
		print(i, end=' ')


n = int(input())
lis = sorted(map(int, input().split()))
ans = [0] * n
i = j = n - 1
while j >= 0 and i >= 0:
	ans[j] = lis[i]
	i -= 1
	j -= 2
j = n - 2
while j >= 0 and i >= 0:
	ans[j] = lis[i]
	i -= 1
	j -= 2
print((n - 1) // 2)
print(*ans)


from collections import *
n = int(input())
L = sorted(map(int, input().split()))
lo = range(1, int(n / 2) + 1)
hi = range(n, int(n / 2), -1)
ans = []
for (a, b) in list(zip(hi, lo)):
	ans.append(a)
	ans.append(b)
if len(hi) > len(lo):
	ans.append(hi[-1])
ans = map(lambda x: L[x - 1], ans)
print(int(n / 2) - (n % 2 == 0))
print(' '.join(map(str, ans)))


from math import ceil
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
a = arr[:n // 2]
b = arr[n // 2:]
ans = []
while a:
	ans.append(b.pop())
	ans.append(a.pop())
if b:
	ans.append(b.pop())
print(ceil(n / 2) - 1)
print(' '.join([str(v) for v in ans]))


def fun(n, arr):
	if n % 2 == 0:
		max_take = (n - 2) / 2
	else:
		max_take = (n - 1) / 2
	max_take = int(max_take)
	arr.sort()
	mins = arr[:max_take]
	arr = arr[max_take:]
	for i in range(len(mins)):
		arr.insert(2 * i + 1, mins[i])
	print(max_take)
	for ele in arr:
		print(ele, end=' ')
n = int(input())
num = list((int(ele) for ele in input().strip().split(' ')))
fun(n, num)


import sys, os, io
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(I())
a = list(map(int, I().split()))
a.sort()
b = []
h = n // 2 + (n & 1)
(i, j) = (0, h)
while i < h or j < n:
	if j < n:
		b.append(a[j])
		j += 1
	if i < h:
		b.append(a[i])
		i += 1
c = 0
for i in range(1, n - 1):
	if b[i - 1] > b[i] < b[i + 1]:
		c += 1
print(c)
print(*b)


n = int(input())
l = list(map(int, input().split()))
l.sort()
p = l[0:n // 2]
q = l[n // 2:]
w = []
c = 0
for i in range(n // 2):
	w.append(q[i])
	w.append(p[i])
if n % 2 == 1:
	w.append(q[-1])
for i in range(1, len(w) - 1):
	if w[i] < w[i - 1] and w[i] < w[i + 1]:
		c += 1
print(c)
for i in w:
	print(i, end=' ')
print()


from sys import *
from math import *
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
if n <= 2:
	print(0)
	print(*a)
else:
	a.sort()
	if n % 2 != 0:
		x = n // 2
	else:
		x = n // 2 - 1
	s = a[:x]
	s = s[::-1]
	w = a[x:]
	w = w[::-1]
	q = []
	f = 0
	l1 = len(s)
	ans = 0
	j = k = 0
	for i in range(n):
		if f == 0 or k >= l1:
			q.append(w[j])
			f = 1
			j += 1
		elif k < l1 and f == 1:
			q.append(s[k])
			f = 0
			k += 1
	for i in range(1, n - 1):
		if q[i] < q[i - 1] and q[i] < q[i + 1]:
			ans += 1
	print(ans)
	print(*q)


N = int(input())
Ans = [0] * N
A = list(map(int, input().split()))
A.sort()
if N == 1:
	print(0)
	print(A[0])
else:
	j = 0
	for i in range(1, N, 2):
		Ans[i] = A[j]
		j += 1
	for i in range(0, N, 2):
		Ans[i] = A[j]
		j += 1
	ans = 0
	for i in range(1, N - 1):
		if Ans[i] < Ans[i - 1] and Ans[i] < Ans[i + 1]:
			ans += 1
	print(ans)
	for i in Ans:
		print(i, end=' ')


t = int(input())
arr = list(map(int, input().strip().split()))[:t]
x = t - 3
y = int(x / 2)
if t == 2 or t == 1:
	y = -1
l = []
kk = t - 1
kl = 0
arr.sort()
for i in range(0, t):
	if i % 2 == 0:
		l.append(arr[kk])
		kk -= 1
	else:
		l.append(arr[kl])
		kl += 1
print(y + 1)
print(*l, sep=' ')


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	ans = [0] * n
	i = 0
	j = 1
	while j < n:
		ans[j] = arr[i]
		i += 1
		j += 2
	j = 0
	while j < n:
		ans[j] = arr[i]
		i += 1
		j += 2
	c = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			c += 1
	print(c)
	print(*ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


import sys, os.path, math
sys.setrecursionlimit(10 ** 5)

def mod():
	return 10 ** 9 + 7

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	a = ii()
	b = sorted(lii())
	c = 0
	for i in range(1, a - 1, 2):
		if b[i - 1] < b[i] < b[i + 1]:
			c += 1
		else:
			pass
	print(c)
	if a % 2 == 0:
		for i in range(int(a / 2)):
			print(b[i + int(a / 2)], b[i], end=' ')
	else:
		b.insert(math.floor(a / 2), ' ')
		for i in range(math.ceil(a / 2)):
			print(b[i + math.ceil(a / 2)], b[i], end=' ')
for _ in range(1):
	solve()


n = int(input())
x = list(map(int, input().split()))
x.sort()
lst = list()
if n == 1:
	print(0)
	print(*x, sep=' ')
elif n == 2:
	print(0)
	print(*x, sep=' ')
else:
	for i in range(n // 2):
		lst.append(x[-1 - i])
		lst.append(x[i])
	if n % 2 != 0:
		lst.append(x[n // 2])
		print(n // 2)
		print(*lst, sep=' ')
	else:
		print(n // 2 - 1)
		print(*lst, sep=' ')


t = int(input())
l = sorted(list(map(int, input().split())))
for i in range(t // 2):
	(l[i * 2], l[i * 2 + 1]) = (l[i * 2 + 1], l[i * 2])
print((t - 1) // 2)
print(*l)


n = int(input())
l = list(map(int, input().split()))
l.sort()
(x, y) = ([], [])
z = []
if n % 2 == 1:
	for i in range(n // 2, n):
		x.append(l[i])
	for i in range(n // 2):
		y.append(l[i])
	(a, b) = (0, 0)
	for i in range(1, (n + 1) // 2):
		z.append(x[a])
		z.append(y[b])
		(a, b) = (a + 1, b + 1)
	z.append(x[a])
	c = 0
	for i in range(1, n - 1):
		if z[i] < z[i - 1] and z[i] < z[i + 1]:
			c += 1
	print(c)
	print(*z)
else:
	for i in range(n // 2, n):
		x.append(l[i])
	for i in range(n // 2):
		y.append(l[i])
	(a, b) = (0, 0)
	for i in range(n // 2):
		z.append(x[a])
		z.append(y[b])
		(a, b) = (a + 1, b + 1)
	c = 0
	for i in range(1, n - 1):
		if z[i] < z[i - 1] and z[i] < z[i + 1]:
			c += 1
	print(c)
	print(*z)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
temp = [0] * n
s = 0
for i in range(1, n, 2):
	temp[i] = arr[s]
	s += 1
for i in range(0, n, 2):
	temp[i] = arr[s]
	s += 1
ans = 0
for i in range(1, n - 1):
	if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
		ans += 1
print(ans)
print(*temp)


import sys

def solution():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	for i in range(0, n - 1, 2):
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	print((n - 1) // 2)
	print(*arr)
solution()


from collections import deque
n = int(input())
arr = sorted([int(p) for p in input().split()], reverse=True)
ans = [0] * n
p = 0
if n % 2 != 0:
	for i in range(0, n, 2):
		ans[i] = arr[p]
		p += 1
	for i in range(n):
		if ans[i] == 0:
			ans[i] = arr[p]
			p += 1
else:
	for i in range(1, n, 2):
		ans[i] = arr[p]
		p += 1
	for i in range(n):
		if ans[i] == 0:
			ans[i] = arr[p]
			p += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
n = len(l)
ans = l[:]
if n % 2:
	slots = n // 2
else:
	slots = n // 2 - 1
for i in range(slots):
	ans[i * 2 + 1] = l[i]
no_index = slots
for i in range(n // 2):
	ans[i * 2] = l[no_index]
	no_index += 1
print(slots)
print(' '.join(map(str, ans)).strip())


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

def scanf(datatype=str):
	return datatype(sys.stdin.readline().rstrip())

def printf(answer=''):
	return sys.stdout.write(str(answer) + '\n')

def prints(answer):
	return sys.stdout.write(str(answer) + ' ')

def map_input(datatype=str):
	return map(datatype, sys.stdin.readline().split())

def list_input(datatype=str):
	return list(map(datatype, sys.stdin.readline().split()))

def testcase(number: int, solve_function):
	for _ in range(number):
		solve_function()

def solve():
	n = scanf(int)
	arr = list_input(int)
	if n <= 2:
		printf(0)
		for i in arr:
			prints(i)
		return
	arr = sorted(arr, reverse=True)
	i = 1
	while i < n - 1:
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		i += 2
	printf(n // 2) if n & 1 else printf((n - 1) // 2)
	for i in arr:
		prints(i)
solve()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	print((n - 1) // 2)
	ans = []
	r = n - 1
	l = 0
	alst.sort()
	if n == 1:
		print(alst[0])
		return
	while 1:
		ans.append(alst[r])
		r -= 1
		if r == l:
			break
		ans.append(alst[l])
		l += 1
		if r == l:
			break
	ans.append(alst[r])
	print(*ans)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	l = []
	if n < 3:
		print(0)
		print(*a)
		return
	if n % 2 == 0:
		print(n // 2 - 1)
	else:
		print(n // 2)
	for i in range(n // 2):
		l.append(a[n - i - 1])
		l.append(a[i])
	if n % 2 != 0:
		l.append(a[n // 2])
	print(*l)
main()


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

def printis(xs):
	print(' '.join(map(str, xs)))
n = int(input())
ps = readis()
if n < 3:
	print(0)
	printis(ps)
	exit(0)
k = (n - 1) // 2
ps = sorted(ps)
consumer_ps = []
for (small, big) in zip(ps[:k], ps[k:]):
	consumer_ps.append(big)
	consumer_ps.append(small)
consumer_ps.extend(ps[2 * k:])
print(k)
printis(consumer_ps)


def winner(nums, n):
	nums = sorted(nums)
	ans = []
	i = 0
	j = n // 2
	count = 0
	while j < n:
		ans.append(nums[j])
		if i < n // 2:
			ans.append(nums[i])
			if j != n - 1 and nums[i] != nums[j]:
				count += 1
		j += 1
		i += 1
	return (ans, count)
n = int(input())
(nums, count) = winner([int(i) for i in input().split()], n)
print(count)
for num in nums:
	print(num, end=' ')


n = int(input())
F = [int(i) for i in input().split()]
F.sort()
if n % 2 != 0:
	A = F[:int((n - 1) / 2)]
	B = F[int((n - 1) / 2):]
	for i in range(int((n + 1) / 2)):
		F[2 * i] = B[i]
	for i in range(int((n - 1) / 2)):
		F[2 * i + 1] = A[i]
	print(int((n - 1) / 2))
	print(*F)
else:
	A1 = F[:int(n / 2)]
	B1 = F[int(n / 2):]
	for i in range(int(n / 2)):
		F[2 * i] = A1[i]
	for i in range(int(n / 2)):
		F[2 * i + 1] = B1[i]
	print(int(n / 2) - 1)
	print(*F)


n = int(input())
a = list(map(int, input().split()))
print((n - 1) // 2)
a.sort()
big = n - 1
small = 0
ans = []
for i in range(n):
	if i % 2 == 0:
		ans.append(a[big])
		big -= 1
	else:
		ans.append(a[small])
		small += 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
b = [0] * n
b[:n:2] = a[0:(n + 1) // 2]
last = []
idx = (n + 1) // 2
for i in range(1, n, 2):
	if i == n - 1:
		continue
	while idx < n and (not (b[i - 1] > a[idx] < b[i + 1] and i < n - 1)):
		last.append(a[idx])
		idx += 1
	if idx < n:
		b[i] = a[idx]
		idx += 1
idx = 0
for i in range(n):
	if b[i] != 0:
		a[idx] = b[i]
		idx += 1
for x in last:
	a[idx] = x
	idx += 1
b = a
res = sum((1 if b[i - 1] > b[i] < b[i + 1] else 0 for i in range(1, n - 1)))
print(res)
print(' '.join((str(x) for x in b)))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [None for i in range(n)]
s = 1
cur = 0
while s < n:
	ans[s] = arr[cur]
	s += 2
	cur += 1
s = 0
while s < n:
	ans[s] = arr[cur]
	s += 2
	cur += 1
count = 0
for i in range(n - 1):
	if i > 0 and i < n:
		if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
			count += 1
print(count)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
arr = [0 for i in range(n)]
ind = 0
for i in range(1, n, 2):
	arr[i] = a[ind]
	ind += 1
for i in range(0, n, 2):
	arr[i] = a[ind]
	ind += 1
count = 0
for i in range(1, n - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		count += 1
print(count)
print(*arr)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = []
for i in range(len(a) // 2):
	b.append(a[len(a) // 2 + i])
	b.append(a[i])
if len(a) % 2 != 0:
	b.append(a[-1])
count = 0
for i in range(1, len(b), 2):
	if b[i] < b[i - 1]:
		if i + 1 < len(b):
			if b[i] < b[i + 1]:
				count += 1
print(count)
print(*b)


from __future__ import division, print_function
import os
import sys
from difflib import SequenceMatcher
from io import BytesIO, IOBase
from collections import Counter, deque
from heapq import heapify, heappush, heappop
from math import gcd, ceil, sqrt, log2, log
from itertools import accumulate, repeat, permutations, compress
from operator import itemgetter
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def arp(arr):
	return ' '.join([str(i) for i in arr])
n = int(input())
arr = rl()
arr.sort()
if n <= 2:
	print(0)
	print(arp(arr))
else:
	ans = deque([])
	ans1 = deque([])
	for i in range(n):
		if i <= n // 2 - 1:
			ans.append(arr[i])
		else:
			ans1.append(arr[i])
	array = []
	for i in range(n):
		if i & 1:
			array.append(ans.popleft())
		else:
			array.append(ans1.popleft())
	cnt = 0
	if n & 1:
		for i in range(1, n, 2):
			if array[i - 1] > array[i] < array[i + 1]:
				cnt += 1
		print(cnt)
		print(arp(array))
	else:
		for i in range(1, n - 1, 2):
			if array[i - 1] > array[i] < array[i + 1]:
				cnt += 1
		print(cnt)
		print(arp(array))
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')


l = []
if 1 == 1:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	s = []
	if n % 2 == 0:
		if a[n // 2 - 1] != a[n // 2]:
			print(n // 2 - 1)
			for i in range(n):
				if i % 2 == 0:
					s.append(str(a[i // 2 + n // 2]))
				else:
					s.append(str(a[i // 2]))
			print(' '.join(s))
		else:
			c1 = a[:n // 2].count(a[n // 2])
			c2 = a[n // 2:].count(a[n // 2])
			if n // 2 - c2 - c1 >= 1:
				print(n // 2 - 1)
				for i in range(n):
					if i % 2 == 0:
						s.append(str(a[n - 1 - i // 2]))
					else:
						s.append(str(a[n // 2 - 1 - i // 2]))
				print(' '.join(s))
			else:
				print((n // 2 - c2 + 1) // 2 + n // 2 - c1)
				for i in range(n):
					if i % 2 == 0:
						s.append(str(a[n // 2 + i // 2]))
					else:
						s.append(str(a[i // 2]))
				print(' '.join(s))
	elif a[n // 2] != a[n // 2 - 1]:
		print(n // 2)
		for i in range(n):
			if i % 2 == 0:
				s.append(str(a[n // 2 + i // 2]))
			else:
				s.append(str(a[i // 2]))
		print(' '.join(s))
	else:
		c1 = a[:n // 2].count(a[n // 2])
		c2 = a[n // 2:].count(a[n // 2])
		if n // 2 - c2 - c1 + 1 >= 1:
			print(n // 2)
		else:
			print((n // 2 + 1 - c2 + 1) // 2 + n // 2 - c1)
		for i in range(n):
			if i % 2 == 0:
				s.append(str(a[n // 2 + i // 2]))
			else:
				s.append(str(a[i // 2]))
		print(' '.join(s))


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
lst = [0 for x in range(n)]
k = 0
for i in range(n // 2, n):
	lst[k] = ar[i]
	k += 2
k = 1
for i in range(0, n // 2):
	lst[k] = ar[i]
	k += 2
c = 0
for i in range(1, n - 1):
	if lst[i - 1] > lst[i] < lst[i + 1]:
		c += 1
print(c)
print(*lst)


k = int(input())
lst = list(map(int, input().split()))
out = []
lst = sorted(lst)
z = int(k / 2)
d = k % 2
if d == 0:
	z -= 1
if k > 2:
	for i in range(z):
		out.append(lst[z + i])
		out.append(lst[i])
	if d == 0:
		out.append(lst[k - 2])
		out.append(lst[k - 1])
	else:
		out.append(lst[k - 1])
	print(z)
	print(*out)
else:
	print(0)
	print(*lst)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
from itertools import permutations as permu

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = 1
for _ in range(num):
	n = int(z())
	arr = szzz()
	l = 0
	r = n - 1
	x = len(set(arr))
	print((x - 1) // 2)
	while l < r:
		print(arr[r], arr[l], end=' ')
		r -= 1
		l += 1
	if n % 2 == 1:
		print(arr[l])


n = int(input())
l = list(map(int, input().split()))
l.sort()
t = (n - 1) // 2
print(t)
a = []
for i in range(t):
	a.append(l[i])
z = 0
for i in range(t, n):
	a.insert(z, l[i])
	z = z + 2
print(*a)


n = int(input())
l = sorted([int(i) for i in input().split()])
c = 0
l1 = []
(k1, k2) = (0, n // 2)
for i in range(n):
	if i % 2 == 0:
		l1 += [l[k2]]
		k2 += 1
	else:
		l1 += [l[k1]]
		k1 += 1
for i in range(1, n - 1):
	if l1[i] < l1[i - 1] and l1[i] < l1[i + 1]:
		c += 1
print(c)
print(*l1)


import sys

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

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
n = I()
A = LI()
if n <= 2:
	print(0)
	print(*A)
	exit()
r = (n - 1) // 2
print(r)
A.sort()
ANS = [0] * n
for i in range(r):
	ANS[2 * i + 1] = A[i]
if n % 2 == 1:
	for i in range(r, n):
		ANS[2 * i - 2 * r] = A[i]
else:
	for i in range(r, n - 1):
		ANS[2 * i - 2 * r] = A[i]
	ANS[-1] = A[-1]
print(*ANS)


n = int(input())
values = list(map(int, input().split()))
values.sort()
ans = []
for i in range(1, len(values), 2):
	ans.append(values[i])
	ans.append(values[i - 1])
if n % 2 == 1:
	ans.append(values[len(values) - 1])
print((n - 1) // 2)
print(' '.join([str(x) for x in ans]))


n = int(input())
aaa = list(map(int, input().split()))
aaa.sort()
m0 = (n - 1) // 2
m1 = n // 2
ans = 0
order = [0] * n
for i in range(m1, n):
	order[2 * (i - m1)] = aaa[i]
for i in range(m1):
	order[2 * i + 1] = aaa[i]
	if order[2 * i] > order[2 * i + 1]:
		ans += 1
if n % 2 == 0 and order[-2] > order[-1]:
	ans -= 1
print(ans)
print(*order)


from collections import deque
from math import ceil
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
print(ceil(n / 2) - 1)
q = deque(arr)
big = True
rez = []
while q:
	if big:
		rez.append(q.pop())
	else:
		rez.append(q.popleft())
	big = not big
print(*rez)


import math

def solve(n, arr):
	if n < 3:
		return (0, arr)
	arr.sort()
	ans = []
	if n % 2 == 0:
		for i in range(n // 2):
			ans.append(arr[n - i - 1])
			ans.append(arr[i])
	else:
		for i in range(n // 2):
			ans.append(arr[n - i - 1])
			ans.append(arr[i])
		ans.append(arr[n // 2])
	return (math.ceil((n - 2) / 2), ans)
t = 1
ans = []
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans.append(solve(n, arr))
for test in ans:
	print(test[0])
	for ele in test[1]:
		print(ele, end=' ')
	print()


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters[:26]
input = stdin.readline
n = int(input())
arr = list(sorted(map(int, input().split())))
res = []
ln = n // 2
sln = n // 2 + n % 2
for i in range(n):
	if not i % 2:
		res.append(arr[ln + i // 2])
	else:
		res.append(arr[i // 2])
ans = 0
for i in range(1, n - 1):
	if res[i] < res[i + 1] and res[i] < res[i - 1]:
		ans += 1
print(ans)
print(*res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0 for i in range(n)]
i = 1
j = 0
while i < n:
	b[i] = a[j]
	i += 2
	j += 1
for k in range(n):
	if b[k] == 0:
		b[k] = a[j]
		j += 1
if n % 2 == 1:
	print(n // 2)
else:
	print(n // 2 - 1)
for i in range(n):
	print(b[i], end=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort()
j = 0
k = 0
ans = []
for i in range(1, n + 1):
	if i & 1:
		j += 1
		ans.append(l[n // 2 + j - 1])
	else:
		k += 1
		ans.append(l[k - 1])
ans = [int(1000000000.0)] + ans + [int(1000000000.0)]
cnt = 0
for i in range(n):
	if ans[i] < ans[i + 1] and ans[i] < ans[i - 1]:
		cnt += 1
print(cnt)
print(*ans[1:n + 1])


n = int(input(''))
arr = list(map(int, input().split()))
arr.sort()
i = 0
sol = [0] * n
for j in range(1, n, 2):
	sol[j] = arr[i]
	i += 1
for j in range(0, n, 2):
	sol[j] = arr[i]
	i += 1
cnt = 0
for j in range(1, n - 1):
	if sol[j] < sol[j - 1] and sol[j] < sol[j + 1]:
		cnt += 1
print(cnt)
print(*sol)


def main(prices, n):
	min_price = sorted(prices)
	max_price = sorted(prices, reverse=True)
	res = []
	i = j = 0
	round1 = 1
	while len(res) != n:
		if round1 == 1:
			res.append(max_price[i])
			i += 1
			round1 = 0
		else:
			res.append(min_price[j])
			j += 1
			round1 = 1
	count = 0
	for i in range(1, n - 1):
		if res[i - 1] > res[i] < res[i + 1]:
			count += 1
	return (count, res)
n = int(input())
prices = list(map(int, input().split()))
(count, order) = main(prices, n)
print(count)
print(*order)


from collections import defaultdict

def solve(l, n):
	l.sort()
	if n <= 2:
		print('0')
		for i in range(0, n):
			print(l[i], end=' ')
	else:
		ans = [0] * n
		index = defaultdict(int)
		count = 0
		first = 0
		ansj = 1
		temp = []
		for i in range(n - 1, -1, -1):
			if len(temp) < 2:
				temp.append(l[i])
			elif temp[-1] > l[i]:
				ans[ansj] = l[i]
				ansj += 2
				count += 1
				index[i] = 1
				if first == 0:
					temp.pop()
					first = 1
				else:
					t = temp.pop()
					temp.pop()
					temp.append(t)
			else:
				temp.append(l[i])
		newcount = 0
		j = 0
		flag = 0
		for i in range(n - 1, -1, -1):
			if index[i] == 0:
				ans[j] = l[i]
				newcount += 1
				if flag == 0:
					j += 2
				else:
					j += 1
				if newcount == count:
					flag = 1
		print(count)
		for i in range(0, n):
			print(ans[i], end=' ')
n = int(input())
l = list(map(int, input().split()))
solve(l, n)


n = input()
nums = [int(num) for num in input().split(' ')]
nums = sorted(nums)
mid = int(len(nums) / 2)
ans = []
count = 0
for i in range(mid):
	count += 1
	ans.append(nums[mid + i])
	ans.append(nums[i])
if len(ans) != len(nums):
	ans.append(nums[-1])
else:
	count -= 1
print(count)
for num in ans:
	print(num, end=' ')


n = int(input())
a = list(map(int, input().split()))
if n > 2:
	a.sort()
	fg = 0
	m = n // 2
	if n % 2 == 0:
		fg = n
		m -= 1
		n -= 1
	k = 0
	print(n // 2)
	for i in range(0, n - 1, 2):
		print(a[m], a[k], end=' ')
		m += 1
		k += 1
	if fg > 0:
		print(a[fg - 2], a[fg - 1])
	else:
		print(a[n - 1])
else:
	print(0)
	print(*a)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
res = [0] * n
res[::2] = a[n // 2:]
res[1::2] = a[:n // 2]
acc = 0
for i in range(1, n - 1):
	acc += res[i - 1] > res[i] < res[i + 1]
print(acc)
print(*res)


import math
n = int(input())
singleList = [int(x) for x in input().split()]
print(math.floor((n - 1) / 2))
singleList.sort()
upperBound = len(singleList) - 1
lowerBound = 0
for i in range(0, n):
	if (i + 1) % 2 == 0:
		print(singleList[lowerBound], end=' ')
		lowerBound += 1
	else:
		print(singleList[upperBound], end=' ')
		upperBound -= 1


import sys
n = int(sys.stdin.readline().strip())
arr = []
line = list(map(int, sys.stdin.readline().split()))
kk = False
line.sort()
while len(line) > 0:
	if not kk:
		arr.append(line[len(line) - 1])
		line.pop(-1)
	else:
		arr.append(line[0])
		line.pop(0)
	if not kk:
		kk = True
	else:
		kk = False
count = 0
for i in range(n - 1):
	if arr[i] < arr[i + 1] and arr[i] < arr[i - 1]:
		count += 1
print(count)
for i in range(n):
	print(arr[i], end=' ')
print('')


import sys
input = sys.stdin.readline
n = int(input())
A = sorted(map(int, input().split()))
print((n - 1) // 2)
for i in range(0, n - 1, 2):
	(A[i], A[i + 1]) = (A[i + 1], A[i])
print(*A)


n = int(input())
l = sorted(list(map(int, input().split())))
x = (n - 1) // 2
for i in range(1, n, 2):
	(l[i], l[i - 1]) = (l[i - 1], l[i])
print(x)
print(*l)


def solve():
	n = int(input())
	p = list(map(int, input().split()))
	if n <= 2:
		print(0)
		print(*p)
		return
	p.sort()
	a = [0] * n
	l = 0
	k = n
	if n % 2 == 0:
		k -= 1
	for i in range(1, k, 2):
		a[i] = p[l]
		l += 1
	l = n - 1
	for i in range(k - 1, -1, -2):
		a[i] = p[l]
		l -= 1
	if n % 2 == 0:
		a[-1] = p[l]
	cnt = 0
	for i in range(1, n - 1):
		if a[i] < a[i - 1] and a[i] < a[i + 1]:
			cnt += 1
	print(cnt)
	print(*a)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


n = int(input())
A = sorted(list(map(int, input().split())))
right_lst = []
for (x, y) in zip(A[n // 2:], A[:n // 2]):
	right_lst.append(x)
	right_lst.append(y)
if n % 2 != 0:
	right_lst.append(A[-1])
res = 0
for i in range(1, len(right_lst) - 1):
	if right_lst[i - 1] > right_lst[i] and right_lst[i] < right_lst[i + 1]:
		res += 1
print(res)
print(*right_lst)


def f():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	newarr = []
	for i in range(n // 2):
		newarr.append(arr[i + n // 2])
		newarr.append(arr[i])
	if n % 2:
		newarr.append(arr[n - 1])
	total = 0
	i = 1
	while i + 1 < n:
		if newarr[i - 1] > newarr[i] and newarr[i] < newarr[i + 1]:
			total += 1
		i += 2
	newarr = list(map(str, newarr))
	newarr = ' '.join(newarr)
	print(total)
	print(newarr)
f()


from math import ceil, log, floor, sqrt
import math
k = 1

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def min_subs(n, binary):
	(a, b) = (1, 1)
	mx = 0
	prev = not int(binary[0])
	res = [0] * n
	for i in range(n):
		if int(binary[i]) == 1:
			if int(binary[i]) == prev:
				a += 1
				b = a
			res[i] = a
		else:
			if int(binary[i]) == prev:
				b += 1
				a = b
			res[i] = b
		prev = int(binary[i])
		mx = max(mx, max(a, b))
	print(mx)
	print(*res, sep=' ')

def steps(n):
	return n // 2 + 1

def find_winner(n):
	if n % 2:
		print('black')
	else:
		print('white')
		print('1 2')

def dp_dy(x, y):
	return (125 * pow(x, 2) - pow(x, 3) - 2 * pow(x, 2) * y - 5000 * x + 150 * x * y - x * pow(y, 2) + 25 * pow(y, 2)) / (pow(x + y, 2) * pow(100 - x - y, 2))

def all_neg():
	for x in range(0, 51):
		for y in range(0, 51):
			if x + y != 100 and x + y != 0:
				print(dp_dy(x, y), x, y)
				if dp_dy(x, y) > 0:
					return False
	return True

def can_palindrome(r, g, b, w):
	no = 0
	mn = pow(10, 9) + 1
	mn = min(mn, r)
	mn = min(mn, g)
	mn = min(mn, b)
	if r % 2 == 1:
		no += 1
	if g % 2 == 1:
		no += 1
	if b % 2 == 1:
		no += 1
	if w % 2 == 1:
		no += 1
	if no <= 1:
		return True
	if no == 3 and mn > 0:
		return True
	return False

def max_find(n, k, z, a):
	res = 0
	s = 0
	mx = 0
	for t in range(z + 1):
		pos = k - 2 * t
		if pos < 0:
			continue
		mx = 0
		s = 0
		for i in range(pos + 1):
			if i < n - 1:
				mx = max(mx, a[i] + a[i + 1])
			s += a[i]
		res = max(res, s + mx * t)
	return res

def stair_count(n):
	return n * (n + 1) // 2

def count_total(n):
	count = 0
	start = 1
	while n >= stair_count(start):
		cells = stair_count(start)
		n -= cells
		count += 1
		start = 2 * start + 1
	return count

def get_cnt(n, arr):
	j = 0
	arr.sort()
	b = []
	for i in range(n):
		b.append(-1)
	for i in range(n - 1):
		if i % 2 == 1:
			b[i] = arr[j]
			j += 1
	for i in range(n):
		if b[i] == -1:
			b[i] = arr[j]
			j += 1
	if n % 2 == 0:
		n -= 1
	print(n // 2)
	print(*b, sep=' ')
t = 1
while t:
	t = t - 1
	n = int(input())
	arr = list(map(int, input().split()))
	get_cnt(n, arr)


def s(a):
	ma = max(a)
	mi = min(a)
	mid = 0
	for i in range(3):
		if a[i] != ma and a[i] != mi:
			mid = a[i]
			break
	(a[0], a[1], a[2]) = (ma, mi, mid)
	return a
n = int(input())
a = [int(x) for x in input().split(' ')]
count = 0
if n < 3:
	print(0)
	print(*a)
else:
	for i in range(1, n - 1, 2):
		count += 1
		a[i - 1:i + 2] = s(a[i - 1:i + 2])
	print(count)
	print(*a)


import sys
from collections import deque

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

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
N = INT()
A = LIST()
A.sort()
que = deque(A)
ans = []
for i in range(N):
	if i % 2 == 0:
		ans.append(que.pop())
	else:
		ans.append(que.popleft())
print(ceil(N, 2) - 1)
print(*ans)


n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
res = [None] * n
b = (n - 1) // 2
for i in range(1, n, 2):
	res[i] = nums.pop()
for i in range(0, n, 2):
	res[i] = nums.pop()
print(b)
for x in res:
	print(x, end=' ')
print()


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = sorted(inl())
ans = []
count = 0
for i in range(n // 2):
	ans.append(a[i + n // 2])
	ans.append(a[i])
if n % 2:
	ans.append(a[-1])
for i in range(1, n - 1):
	count += 1 if ans[i] < ans[i - 1] and ans[i] < ans[i + 1] else 0
print(count)
print(*ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
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 JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		a.sort()
		b = a[:n // 2]
		c = a[n // 2:]
		d = []
		for i in range(len(c)):
			d.append(c[i])
			if i < len(b):
				d.append(b[i])
		r = 0
		for i in range(1, n - 1):
			if d[i - 1] > d[i] and d[i + 1] > d[i]:
				r += 1
		rr.append(r)
		rr.append(JA(d, ' '))
	return JA(rr, '\n')
print(main())


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = []
if n % 2 == 1:
	ans = n // 2
if n % 2 == 0:
	ans = n // 2 - 1
for i in range(n // 2):
	c.append(b[n - i - 1])
	c.append(b[i])
if n % 2 == 1:
	c.append(b[n // 2])
print(ans)
for i in range(n):
	print(c[i], end=' ')


import sys, math
try:
	(sys.stdin, sys.stdout) = (open('input.txt', 'r'), open('out.txt', 'w'))
except:
	pass
from sys import stdin, stdout
mod = int(1000000000.0 + 7)
from statistics import mode
from collections import *
from math import ceil, floor, inf, factorial, gcd, log2, sqrt, log
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()

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

def setbits(n):
	return bin(n).count('1')

def resetbits(n):
	return bin(n).count('0')

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r):
	(num, den) = (1, 1)
	r = min(n, n - r)
	for i in range(r):
		num *= n - i
		den *= i + 1
	return num // den

def ncr_p(n, r, p):
	(num, den) = (1, 1)
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * modinv(den, p) % p

def isPrime(num):
	if num <= 1:
		return False
	if num == 2 or n == 3:
		return True
	if num % 2 == 0 or num % 3 == 0:
		return False
	m = int(num ** 0.5) + 1
	for i in range(5, m, 6):
		if num % i == 0 or num % (i + 2) == 0:
			return False
	return True

def bin_search(s, low, high, val):
	while low <= high:
		mid = low + (high - low) // 2
		if s[mid] == val:
			return mid
		elif s[mid] < val:
			low = mid + 1
		else:
			high = mid - 1
	return -1

def sumofdigit(num):
	count = 0
	while num:
		count += num % 10
		num //= 10
	return count

def inputmatrix():
	(r, c) = iia()
	mat = [0] * r
	for i in range(r):
		mat[i] = iia()
	return (r, c, mat)

def prefix_sum(n, s):
	for i in range(1, n):
		s[i] += s[i - 1]
	return s

def binomial(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def divisors(n):
	res = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i == n // i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
	return res
n = ii1()
arr = iia()
arr.sort()
ans = [0] * n
if n == 1:
	print(0)
	print(*arr)
elif n == 2:
	print(0)
	print(*arr)
elif n == 3:
	ans[0] = arr[1]
	ans[1] = arr[0]
	ans[2] = arr[2]
	print(1)
	print(*ans)
else:
	i = 0
	j = 0
	while i < n:
		ans[i] = arr[n // 2 + j]
		j += 1
		i += 2
	i = 1
	j = 0
	while i < n:
		ans[i] = arr[j]
		j += 1
		i += 2
	print((n - 1) // 2)
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
count = 0
a = sorted(a, reverse=True)
i = 2
while i < len(a):
	if a[i - 1] > a[i]:
		(a[i - 1], a[i]) = (a[i], a[i - 1])
		count += 1
	i += 2
print(count)
print(' '.join((str(k) for k in a)))


def buy(n, a):
	a.sort()
	m = n // 2
	l = 0
	i = 0
	ans = []
	while i < n:
		if i % 2 == 0:
			ans.append(a[m])
			m += 1
		else:
			ans.append(a[l])
			l += 1
		i += 1
	count = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			count += 1
	print(count)
	print(*ans)
n = int(input())
a = list(map(int, input().split()))
buy(n, a)


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
ans1 = []
ans2 = []
cnt1 = 0
cnt2 = 0
if n == 1:
	print('0')
	print(arr[0])
elif n == 2:
	print('0')
	print(arr[0], arr[1])
elif n % 2 == 0:
	for i in range(n // 2):
		ans1.append(arr[i + n // 2])
		ans1.append(arr[i])
	for i in range(1, n - 1):
		if ans1[i] < ans1[i - 1] and ans1[i] < ans1[i + 1]:
			cnt1 += 1
	for i in range(n // 2):
		ans2.append(arr[i])
		ans2.append(arr[i + n // 2])
	for i in range(1, n - 1):
		if ans2[i] < ans2[i - 1] and ans2[i] < ans2[i + 1]:
			cnt2 += 1
	print(max(cnt1, cnt2))
	if cnt1 >= cnt2:
		print(' '.join(map(str, ans1)))
	else:
		print(' '.join(map(str, ans2)))
else:
	for i in range(n // 2):
		ans1.append(arr[i + n // 2])
		ans1.append(arr[i])
	ans1.append(arr[n - 1])
	for i in range(n // 2):
		ans2.append(arr[i])
		ans2.append(arr[i + n // 2])
	ans2.append(arr[(n - 1) // 2])
	for i in range(1, n - 1):
		if ans1[i] < ans1[i - 1] and ans1[i] < ans1[i + 1]:
			cnt1 += 1
	for i in range(1, n - 1):
		if ans2[i] < ans2[i - 1] and ans2[i] < ans2[i + 1]:
			cnt2 += 1
	print(max(cnt1, cnt2))
	if cnt1 >= cnt2:
		print(' '.join(map(str, ans1)))
	else:
		print(' '.join(map(str, ans2)))


n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
a.sort()
ind = n - 1
ind1 = 0
c = 0
for i in range(n):
	if i % 2 == 0:
		ans[i] = a[ind]
		ind -= 1
	else:
		c += 1
		ans[i] = a[ind1]
		ind1 += 1
if n % 2 == 0:
	print(c - 1)
else:
	print(c)
print(*ans)


import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	n = scan_int()
	aa = read_list()
	a = aa
	a.sort()
	ans = [0 for i in range(n)]
	j = 0
	for i in range(1, n, 2):
		ans[i] = a[j]
		j += 1
	for i in range(0, n, 2):
		ans[i] = a[j]
		j += 1
	count = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			count += 1
	print(count)
	print(*ans)
for _ in range(1):
	solve()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = 10 ** 9 + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
arr.sort()
arr = deque(arr)
answer = []
while arr:
	if not answer:
		answer.append(arr.pop())
		continue
	answer.append(arr.popleft())
	if arr:
		answer.append(arr.pop())
result = 0
for i in range(1, n - 1):
	if answer[i - 1] > answer[i] and answer[i + 1] > answer[i]:
		result += 1
out(result)
outa(*answer)


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 abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj
import sys
import threading
from math import *
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 2:
		print(0)
		print(*a)
	else:
		li = [0] * n
		a.sort()
		ans = 0
		j = 0
		for i in range(1, n, 2):
			li[i] = a[j]
			j += 1
		for i in range(0, n, 2):
			li[i] = a[j]
			j += 1
		for i in range(1, n - 1):
			if li[i - 1] > li[i] < li[i + 1]:
				ans += 1
		print(ans)
		print(*li)


def main():
	n = int(input())
	array = list(map(int, input().split()))
	resposta = list()
	append = resposta.append
	array.sort()
	(i, f) = (0, len(array) - 1)
	while True:
		append(array[f])
		if i != f:
			append(array[i])
		if i >= f - 1:
			break
		i += 1
		f -= 1
	qtd = 0
	for i in range(1, len(resposta) - 1):
		if resposta[i] < resposta[i - 1] and resposta[i] < resposta[i + 1]:
			qtd += 1
	print(qtd)
	for i in range(len(resposta)):
		end = ' ' if i < len(resposta) - 1 else ''
		print(resposta[i], end=end)
main()


import sys

def input():
	return sys.stdin.readline()[:-1]

def getInt():
	return int(input())

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

def getIntList():
	return list(getIntIter())

def flush():
	sys.stdout.flush()
n = getInt()
nums = getIntList()
nums.sort()
mid = len(nums) // 2
newNums = []
for x in range(len(nums)):
	if x % 2 == 0:
		newNums.append(nums[mid + x // 2])
	else:
		newNums.append(nums[x // 2])
ans = 0
for x in range(1, len(nums) - 1, 2):
	ans += newNums[x + 1] > newNums[x] < newNums[x - 1]
print(ans)
print(' '.join(map(str, newNums)))


def main():
	n = int(input())
	arr = list(sorted(map(int, input().split())))
	na = [0] * n
	index = 0
	for i in range(1, n, 2):
		na[i] = arr[index]
		index += 1
	for i in range(0, n, 2):
		na[i] = arr[index]
		index += 1
	cnt = 0
	for i in range(1, n - 1):
		if na[i] < na[i - 1] and na[i] < na[i + 1]:
			cnt += 1
	print(cnt)
	for c in na:
		print(c, end=' ')
	print('')
main()


def f(n, prices):
	prices.sort()
	left = 0
	right = n - 1
	arr = []
	while left < right:
		arr.append(prices[right])
		right -= 1
		arr.append(prices[left])
		left += 1
	if left == right:
		arr.append(prices[right])
	return arr
n = int(input())
prices = list(map(int, input().split()))
if n % 2 == 0:
	print(int(n / 2 - 1))
else:
	print(n // 2)
for i in f(n, prices):
	print(i, end=' ')
print('')
pass


from sys import stdin
from collections import defaultdict, Counter
from math import ceil

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = 1
while t:
	t -= 1
	n = iinput()
	a = linput()
	a.sort()
	b = [0] * n
	j = 0
	for i in range(1, n, 2):
		b[i] = a[j]
		j += 1
	for i in range(0, n, 2):
		b[i] = a[j]
		j += 1
	ice = 0
	for i in range(1, n - 1):
		if b[i - 1] > b[i] < b[i + 1]:
			ice += 1
	print(ice)
	print(*b)


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	a = ' '.join(map(str, a))
	print(0)
	print(a)
else:
	a.sort(reverse=True)
	poped = None
	if n % 2 == 0:
		poped = a.pop()
		n -= 1
	ans = [0] * n
	(i, j) = (0, n - 1)
	for k in range(0, n // 2 + 1, 2):
		if i == j:
			ans[i] = a[k]
			break
		ans[i] = a[k]
		ans[j] = a[k + 1]
		i += 2
		j -= 2
	k = n // 2 + 1
	for i in range(n):
		if not ans[i]:
			ans[i] = a[k]
			k += 1
	if poped:
		n += 1
		ans.append(poped)
	print((n + 1) // 2 - 1)
	ans = ' '.join(map(str, ans))
	print(ans)


n = int(input())
ns = list(map(int, input().split()))
ns.sort()
if n % 2 == 0:
	print(n // 2 - 1)
	(first, second) = (ns[:n // 2], ns[n // 2:])
	n2 = ns
	n2[::2] = second
	n2[1::2] = first
	print(' '.join(map(str, n2)))
else:
	print(n // 2)
	(first, second) = (ns[:n // 2], ns[n // 2:])
	n2 = ns
	n2[::2] = second
	n2[1::2] = first
	print(' '.join(map(str, n2)))


n = int(input())
(*arr,) = map(int, input().split())
arr.sort()
half = n // 2
res = [-1] * n
print((n - 1) // 2)
if n % 2 == 0:
	res[::2] = arr[-half:]
	res[1::2] = arr[:-half]
else:
	res[::2] = arr[-half - 1:]
	res[1::2] = arr[:-half - 1]
print(*res)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, nums):
	nums.sort()
	mid = len(nums) // 2
	ret = []
	if len(nums) % 2 == 1:
		for (x, y) in zip(nums[:mid], nums[mid:-1]):
			ret.append(y)
			ret.append(x)
		ret.append(nums[-1])
	else:
		for (x, y) in zip(nums[:mid], nums[mid:]):
			ret.append(y)
			ret.append(x)
	count = 0
	for i in range(1, N - 1):
		if ret[i - 1] > ret[i] and ret[i] < ret[i + 1]:
			count += 1
	if DEBUG:
		assert set(nums) == set(ret)
	return str(count) + '\n' + ' '.join(map(str, ret))
DEBUG = False
if DEBUG:
	import random
	from itertools import permutations
	random.seed(0)
	for _ in range(100000):
		N = random.randint(1, 7)
		A = [random.randint(1, 10) for i in range(N)]
		print('tc', _, N, A)
		ans1 = solve(N, A)
		brute = 0
		for ret in permutations(A):
			count = 0
			for i in range(1, N - 1):
				if ret[i - 1] > ret[i] and ret[i] < ret[i + 1]:
					count += 1
			brute = max(brute, count)
		ansInt = int(ans1.split('\n')[0])
		print('brute', brute, 'mine', ans1)
		assert brute == ansInt
		print(ans1)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 1 or n == 2:
	print(0)
	print(' '.join((str(num) for num in a)))
else:
	t = (n - 1) // 2
	print(t)
	f = 0
	l = n // 2
	start = l
	while l < n:
		print(a[l], end=' ')
		if f == start:
			break
		print(a[f], end=' ')
		l += 1
		f += 1


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n <= 2:
	print(0)
	for i in range(n):
		print(a[i], end=' ')
elif n % 2 == 0:
	k = n // 2
	if a[k - 2] != a[k - 1]:
		print(k - 1)
		for i in range(k):
			print(a[i + k], end=' ')
			print(a[i], end=' ')
	else:
		j = k - 2
		while j >= 1 and a[j] == a[j - 1]:
			j -= 1
		x = k - 2 - j + 1
		i = k - 1
		while i + 1 < n and a[i] == a[i + 1]:
			i += 1
		y = k + 1 - (i + 1 - (k - 1))
		if y >= x + 1:
			print(k - 1)
			for i in range(k):
				print(a[i + k], end=' ')
				print(a[i], end=' ')
		else:
			print(k - 1 - (x - max(y - 1, 0)))
			for i in range(k):
				print(a[i + k], end=' ')
				print(a[i], end=' ')
else:
	k = n // 2
	if a[k - 1] != a[k]:
		print(k)
		for i in range(k):
			print(a[i + k], end=' ')
			print(a[i], end=' ')
		print(a[2 * k])
	else:
		j = k - 1
		while j >= 1 and a[j - 1] == a[j]:
			j -= 1
		x = k - 1 - j + 1
		i = k
		while i + 1 < n and a[i + 1] == a[i]:
			i += 1
		y = k + 1 - (i - k + 1)
		if y >= x + 1:
			print(k)
			for i in range(k):
				print(a[i + k], end=' ')
				print(a[i], end=' ')
			print(a[2 * k])
		else:
			print(k - (x - max(y - 1, 0)))
			for i in range(k):
				print(a[i + k], end=' ')
				print(a[i], end=' ')
			print(a[2 * k])


n = int(input())
A = sorted([int(i) for i in input().split()])
print((n - 1) // 2)
upper = A[n // 2:]
lower = A[:n // 2]
ans = []
for i in range(n // 2):
	ans.append(upper[i])
	ans.append(lower[i])
if len(ans) < n:
	ans.append(upper[-1])
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
hi = []
lo = []
if n % 2 != 0:
	bp = n // 2
	for q in range(bp):
		lo.append(l[q])
	for q in range(bp, n):
		hi.append(l[q])
	print(bp)
	i = 0
	j = 0
	for k in range(n):
		if k % 2 == 0:
			print(hi[i], end=' ')
			i += 1
		else:
			print(lo[j], end=' ')
			j += 1
elif n % 2 == 0:
	bp = n // 2 - 1
	for q in range(bp):
		lo.append(l[q])
	for q in range(bp, n):
		hi.append(l[q])
	print(bp)
	i = 0
	j = 0
	for k in range(n):
		if k % 2 == 0:
			print(hi[i], end=' ')
			i += 1
		elif k == n - 1:
			print(hi[i], end=' ')
		else:
			print(lo[j], end=' ')
			j += 1


n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
a = A[0:n // 2]
b = A[n // 2:]
c = [0] * n
for i in range(n):
	if i % 2 == 0:
		c[i] = b[i // 2]
	else:
		c[i] = a[i // 2]
print((n - 1) // 2)
print(*c)


n = int(input())
A = list(map(int, input().split()))
A.sort()
res = n - 1 >> 1
print(res)
B = [0] * n
e = n - 1
for i in range(0, n, 2):
	B[i] = A[e]
	e -= 1
for i in range(1, n, 2):
	B[i] = A[e]
	e -= 1
print(' '.join(map(str, B)))


n = int(input())
l = [int(i) for i in input().split()]
l = sorted(l)
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print((n - 1) // 2)
ans = [0] * n
if n % 2 == 0:
	for i in range(n // 2 - 1):
		ans[1 + 2 * i] = l[i]
	for i in range(n - (n // 2 - 1) - 1):
		ans[2 * i] = l[i + n // 2 - 1]
	ans[n - 1] = l[n - 1]
else:
	for i in range((n - 1) // 2):
		ans[1 + 2 * i] = l[i]
	for i in range(n - (n - 1) // 2):
		ans[2 * i] = l[i + (n - 1) // 2]
s = ''
for i in ans:
	s += str(i) + ' '
print(s)


n = int(input())
l = sorted(map(int, input().split()))
f = []
(j, cnt) = (n // 2, 0)
for i in range(n // 2):
	f.extend([l[j + i], l[i]])
if n % 2:
	f.append(l[-1])
for i in range(1, n - 1, 2):
	if f[i - 1] > f[i] and f[i] < f[i + 1]:
		cnt += 1
print(cnt)
print(*f)


from sys import stdin

def get_int():
	return int(stdin.readline())

def get_str():
	return stdin.readline().strip()

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

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_array2d(row):
	return [list(map(int, stdin.readline().strip().split())) for _ in range(row)]
N = get_int()
A = get_array()
A.sort()
for i in range(0, N - (N & 1), 2):
	(A[i], A[i + 1]) = (A[i + 1], A[i])
print((N - 1) // 2)
print(*A)


import math as m
n = int(input())
p = input()
Precios = []
numero = ''
for i in range(0, len(p)):
	if i == len(p) - 1:
		numero += p[i]
		Precios.append(int(numero))
	elif p[i] == ' ':
		Precios.append(int(numero))
		numero = ''
	else:
		numero += p[i]
Precios.sort()
if n % 2 == 0:
	print(max((n - 2) // 2, 0))
if n % 2 != 0:
	print(max((n - 1) // 2, 0))
j = n // 2
i = 0
orden = []
while i < n // 2:
	orden.append(Precios[j])
	orden.append(Precios[i])
	i += 1
	j += 1
	if len(orden) == n - 1:
		orden.append(Precios[j])
if n // 2 == 0:
	orden.append(Precios[0])
o = ''
o += str(orden[0]) + ' '
for i in range(1, n):
	o += str(orden[i])
	o += ' '
print(o)


t = int(input())
l1 = input().split(' ')
l1 = [int(x) for x in l1]
l1.sort()
l2 = [0 for i in range(t)]
print((t - 1) // 2)
for i in range(t):
	if i % 2 == 0:
		l2[i] = str(l1[-(i // 2 + 1)])
	else:
		l2[i] = str(l1[i // 2])
print(' '.join(l2))


from sys import stdin
from collections import deque
input = stdin.readline
n = int(input())
a = sorted([*map(int, input().split())])
beg = a[:n // 2]
end = a[n // 2:]
ans = []
for (i, j) in zip(beg, end):
	ans.append(j)
	ans.append(i)
if n % 2:
	ans.append(end[-1])
print(sum((x > y < z for (x, y, z) in zip(ans[:-2], ans[1:], ans[2:]))))
print(*ans)


from math import ceil
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(ceil((n - 2) / 2))
mi = a[:n // 2]
ma = a[n // 2:]
for i in range(n):
	if i % 2 == 0:
		print(ma[i // 2], end=' ')
	else:
		print(mi[i // 2], end=' ')


n = int(input())
if n % 2 == 0:
	n -= 1
n //= 2
A = list(map(int, input().split()))
A = sorted(A)
B = [] * 5
for i in range(0, len(A) // 2):
	s = len(A) - 1 - i
	B.append(A[s])
	B.append(A[i])
if len(A) % 2 != 0:
	B.append(A[(len(A) + 1) // 2 - 1])
print(n)
print(*B)


from sys import stdin, stdout
import math
t = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.sort()
k = 0
res = []
count = 0
if t % 2 != 0:
	k = (t + 1) // 2
	i = 0
	while i < k - 1:
		if arr[i] < arr[i + k - 1]:
			count += 1
		if i == 0:
			res.append(arr[i + k - 1])
		res.append(arr[i])
		res.append(arr[i + k])
		i += 1
else:
	k = t // 2
	i = 0
	while i < k - 1:
		if arr[i] < arr[i + k - 1] or (i == k - 2 and arr[i] < arr[i + k]):
			count += 1
		if arr[i] >= arr[i + k - 1] and (i == k - 2 and arr[i] < arr[i + k]):
			if i == 0:
				res.append(arr[i + k - 1])
			res.append(arr[i + k])
			res.append(arr[i])
			res.append(arr[i + k + 1])
		else:
			if i == 0:
				res.append(arr[i + k - 1])
			res.append(arr[i])
			res.append(arr[i + k])
			if i == k - 2:
				res.append(arr[i + k + 1])
		i += 1
print(count)
if count == 0:
	print(' '.join((str(i) for i in arr)))
else:
	print(' '.join((str(i) for i in res)))


from sys import stdout, stdin
(_input, _print) = (stdin.readline, stdout.write)
(_sorted, _range, _int) = (sorted, range, int)
from collections import deque

def solution():
	n = _int(_input())
	arr = [_int(i) for i in _input().split()]
	d = deque(_sorted(arr))
	ans = []
	i = 0
	while d:
		if i == 0:
			ans.append(d.pop())
		else:
			ans.append(d.popleft())
		i = (i + 1) % 2
	counter = 0
	for i in _range(1, n - 1):
		if ans[i - 1] > ans[i] < ans[i + 1]:
			counter += 1
	print(counter)
	print(*ans)
solution()


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
arr = list(map(int, input().split()))
res = [0] * n
arr.sort()
j = 1
for i in range(n // 2):
	res[j] = arr[i]
	j += 2
j = 0
for i in range(n // 2, n):
	res[j] = arr[i]
	j += 2
x = 0
for i in range(1, n - 1):
	x += res[i - 1] > res[i] < res[i + 1]
print(x)
print(*res)


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	lst = sorted(lst)
	new_lst = []
	for i in range(n // 2):
		new_lst.append(lst[n // 2 + i])
		new_lst.append(lst[i])
	if n % 2 == 1:
		new_lst.append(lst[n - 1])
	cnt = 0
	for i in range(1, n - 1):
		if new_lst[i] < new_lst[i - 1] and new_lst[i] < new_lst[i + 1]:
			cnt += 1
	print(cnt)
	line = ''
	for i in new_lst:
		line += str(i) + ' '
	print(line)
t = 1
for i in range(t):
	main()


n = int(input())
price = [int(x) for x in input().split()]
price.sort()
firstHalf = price[0:n // 2]
secondHalf = price[n // 2:]
optimal = []
for i in range(n // 2):
	optimal.append(secondHalf[i])
	optimal.append(firstHalf[i])
if n % 2 != 0:
	optimal.append(secondHalf[-1])
canBuy = 0
for i in range(1, n - 1):
	if optimal[i - 1] > optimal[i] < optimal[i + 1]:
		canBuy += 1
print(canBuy)
print(*optimal)


def ans(a, n):
	if n % 2 == 1:
		print(n // 2)
	else:
		print(n // 2 - 1)
	arr = [0] * n
	a.sort()
	mi = []
	ma = []
	for i in range(1, n + 1):
		if i <= n // 2:
			mi.append(a[i - 1])
		else:
			ma.append(a[i - 1])
	i = 0
	j = 0
	k = 0
	while k < n:
		if k % 2 == 0:
			arr[k] = ma[j]
			j += 1
			k += 1
		else:
			arr[k] = mi[i]
			i += 1
			k += 1
	for i in arr:
		print(i, end=' ')
	return
n = int(input())
arr = input().split()
a = []
for i in arr:
	a.append(int(i))
ans(a, n)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
result = lst[n // 2:]
for i in range(n // 2):
	result.insert(2 * i + 1, lst[i])
cnt = 0
for i in range(1, n - 1):
	if result[i - 1] > result[i] and result[i] < result[i + 1]:
		cnt += 1
print(cnt)
print(' '.join(map(str, result)))


n = int(input())
a = list(map(int, input().strip().split(' ')))
a.sort()
if n < 3:
	print(0)
	print(*a)
else:
	p = n // 2
	if n % 2 == 0:
		p -= 1
	q = a[:p]
	r = a[p:]
	c = 0
	cc = 0
	m = list(set(q))
	pp = m[len(m) - 1]
	for j in r:
		if j > pp:
			c += 1
	for j in q:
		if j == pp:
			cc += 1
	rr = len(q) - cc
	if c > 1:
		c -= 1
	else:
		c = 0
	rr += min(c, cc)
	print(rr)
	l = []
	k = len(q) - 1
	g = len(r) - 1
	while k >= 0:
		l.append(r[g])
		l.append(q[k])
		g -= 1
		k -= 1
	while g >= 0:
		l.append(r[g])
		g -= 1
	print(*l)


from collections import *
n = int(input())
L = sorted(map(int, input().split()))
lo = range(int(n / 2), 0, -1)
hi = range(n, int(n / 2), -1)
(ans, ans2) = ([], [])
for (a, b) in list(zip(hi, lo)):
	ans.append(L[a - 1])
	ans.append(L[b - 1])
	ans2.append(L[b - 1])
	ans2.append(L[a - 1])
if len(hi) > len(lo):
	ans.append(L[hi[-1] - 1])
	ans2.append(L[hi[-1] - 1])
x = len([x for (i, x) in enumerate(ans) if i > 0 and i < len(ans) - 1 and (ans[i - 1] > ans[i]) and (ans[i + 1] > ans[i])])
y = len([x for (i, x) in enumerate(ans2) if i > 0 and i < len(ans2) - 1 and (ans2[i - 1] > ans2[i]) and (ans2[i + 1] > ans2[i])])
if x > y:
	print(x)
	print(' '.join(map(str, ans)))
else:
	print(y)
	print(' '.join(map(str, ans2)))


import sys

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	ans = 0
	B = [0 for i in range(N)]
	j = 0
	for i in range(1, N, 2):
		B[i] = A[j]
		j = j + 1
	for i in range(0, N, 2):
		B[i] = A[j]
		j = j + 1
	for i in range(1, N - 1):
		if B[i] < B[i - 1] and B[i] < B[i + 1]:
			ans = ans + 1
	print(ans)
	print(*B)
main()


import sys
import math
input = sys.stdin.readline

def solve():
	n = int(input())
	L = list(map(int, input().split()))
	L.sort()
	if n < 3:
		print(0)
		print(*L)
		sys.exit()
	res = [0] * n
	ans = (n - 1) // 2
	l = 0
	r = 0
	for i in range(n):
		if i & 1 == 0:
			res[i] = L[-1 - r]
			r += 1
		else:
			res[i] = L[l]
			l += 1
	print(ans)
	print(*res)
solve()


from sys import stdin
input = stdin.readline
for _ in range(1):
	n = int(input())
	a = sorted([*map(int, input().split())])
	ans = []
	i = 0
	while i < len(a):
		ans.append(a[-1])
		a.pop()
		if i < len(a):
			ans.append(a[i])
			i += 1
	print((n - 1) // 2)
	print(*ans)


n = int(input())
a = [int(tok) for tok in input().split()]
ordered1 = [0] * n
for (i, ai) in enumerate(sorted(a, reverse=True)):
	j = 2 * i
	if j >= n:
		j -= n - (n % 2 == 0)
	ordered1[j] = ai
ordered2 = [0] * n
for (i, ai) in enumerate(sorted(a, reverse=True)):
	j = 2 * i + 1
	if j >= n:
		j -= n + (n % 2 == 0)
	ordered2[j] = ai
sum1 = sum((ai > aj < ak for (ai, aj, ak) in zip(ordered1, ordered1[1:], ordered1[2:])))
sum2 = sum((ai > aj < ak for (ai, aj, ak) in zip(ordered2, ordered2[1:], ordered2[2:])))
if sum1 > sum2:
	print(sum1)
	print(*ordered1)
else:
	print(sum2)
	print(*ordered2)


from collections import Counter, defaultdict as dft

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

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

def solve():
	n = int(input())
	arr = ml()
	res = [0] * n
	arr.sort()
	if n % 2:
		print(n // 2)
	else:
		print((n - 2) // 2)
	x = -1
	for i in range(0, n, 2):
		res[i] = arr[x]
		x -= 1
	x = 0
	for i in range(1, n, 2):
		res[i] = arr[x]
		x += 1
	print(*res)
t = 1
for _ in range(t):
	solve()


n = int(input())
a = sorted(list(map(int, input().split())))
arr = [0] * n
i = 0
for j in range(n // 2, n):
	arr[i] = a[j]
	i += 2
i = 1
for j in range(n // 2):
	arr[i] = a[j]
	i += 2
cnt = 0
for i in range(1, n - 1):
	if arr[i - 1] > arr[i] < arr[i + 1]:
		cnt += 1
print(cnt)
print(*arr)


import math

def sol():
	am = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	new = [0] * am
	if am == 1 or am == 2:
		print(0)
		print(*arr)
		return 0
	smallPos = am - math.ceil(am / 2)
	for i in range(am - 1, -1, -1):
		d = am - i - 1
		if d % 2 == 0:
			d += 1
			new[i] = arr[am - d // 2 - 1]
		else:
			new[i] = arr[smallPos - d // 2 - 1]
	t = 0
	for i in range(1, am - 1):
		if new[i] < new[i - 1] and new[i] < new[i + 1]:
			t += 1
	print(t)
	print(*new)
sol()


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = [0] * n
for i in range(0, n, 2):
	l1[i] = l.pop()
for i in range(1, n, 2):
	l1[i] = l.pop()
if n % 2:
	print(n // 2)
else:
	print(n // 2 - 1)
print(*l1)


from collections import deque
n = int(input())
a = sorted(list(map(int, input().split())))
ans = []
a = deque(a)
for i in range(n):
	if i % 2 == 0:
		ans.append(a.pop())
	else:
		ans.append(a.popleft())
boom = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		boom += 1
print(boom)
print(*ans)


n = int(input())
z = list(map(int, input().split()))
z.sort()
arr = []
if len(z) == 2:
	print(0)
	print(*z)
	exit()
if len(z) % 2 == 0:
	count = 0
	for i in range(len(z) // 2):
		arr.append(z[2 * i + 1])
		arr.append(z[2 * i])
		count += 1
	print(count - 1)
	print(*arr)
else:
	count = len(z) // 2
	for i in range(len(z) // 2):
		arr.append(z[2 * i + 1])
		arr.append(z[2 * i])
	arr.append(z[-1])
	print(count)
	print(*arr)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0 for _ in range(n)]
i = 1
j = 0
while i < n:
	b[i] = a[j]
	j += 1
	i += 2
i = 0
while i < n:
	b[i] = a[j]
	j += 1
	i += 2
print((n - 1) // 2)
print(*b)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	n = ip()
	arr = list(inp())
	if n % 2 == 0:
		ans = n // 2 - 1
	else:
		ans = n // 2
	a = [None] * n
	arr.sort()
	ct = 0
	i = 1
	while i < n:
		a[i] = arr[ct]
		i += 2
		ct += 1
	i = 0
	while i < n:
		a[i] = arr[ct]
		i += 2
		ct += 1
	ans = 0
	for i in range(n):
		if i == 0 or i == n - 1:
			pass
		elif a[i] < a[i + 1] and a[i] < a[i - 1]:
			ans += 1
	out(ans)
	print(*a)


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	if len(l) == 1:
		print(0)
		print(l[0])
	else:
		l.sort()
		m = [0] * n
		ind = 0
		for i in range(1, n, 2):
			m[i] = l[ind]
			ind += 1
		for i in range(0, n, 2):
			m[i] = l[ind]
			ind += 1
		ans = 0
		for i in range(1, len(m) - 1):
			if m[i - 1] > m[i] and m[i] < m[i + 1]:
				ans += 1
		m1 = [0] * n
		ind = 0
		for i in range(1, n, 2):
			m1[i] = l[ind]
			ind += 1
		ind = n - 1
		for i in range(0, n, 2):
			m1[i] = l[ind]
			ind -= 1
		ans1 = 0
		for i in range(1, len(m) - 1):
			if m1[i - 1] > m1[i] and m1[i] < m1[i + 1]:
				ans1 += 1
		if ans > ans1:
			print(ans)
			print(' '.join((str(x) for x in m)))
		else:
			print(ans1)
			print(' '.join((str(x) for x in m1)))


n = int(input())
l = [int(i) for i in input().split()][:n]
l.sort()
final = []
if n == 1 or n == 2:
	print(0)
	print(*l)
elif n % 2 != 0:
	temp = (n - 1) // 2
	print(temp)
	i = -1
	for i in range(temp, n - 1):
		final.append(l[i])
		final.append(l[temp - 1])
		temp -= 1
	final.append(l[i + 1])
	print(*final)
else:
	temp = (n - 2) // 2
	print(temp)
	final.append(l[temp])
	i = -1
	for i in range(temp + 1, n - 1):
		final.append(l[i])
		final.append(l[temp - 1])
		temp -= 1
	final.append(l[i + 1])
	print(*final)


n = int(input())
arr = [int(i) for i in input().split()]
counter = 0
arr.sort()
if len(arr) != 2:
	for i in range(0, n - 1, 1):
		if i == 1:
			continue
		if i == 0:
			tmp0 = arr[i]
			tmp1 = arr[i + 1]
			arr[i] = arr[i + 2]
			arr[i + 1] = tmp0
			arr[i + 2] = tmp1
			counter += 1
		elif i != 0 and i + 1 < n - 1:
			if arr[i - 1] > arr[i] and arr[i + 1] > arr[i]:
				continue
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			counter += 1
print(counter)
for i in range(n):
	if i + 1 == n:
		print(arr[i])
	else:
		print(arr[i], end=' ')


import sys
input = sys.stdin.readline
n = int(input())
ar = list(map(int, input().split()))
ar.sort(reverse=True)
ans = [0] * n
jj = 0
count = 0
for i in range(0, n, 2):
	ans[i] = ar[jj]
	jj += 1
if n >= 2:
	for i in range(1, n, 2):
		count += 1
		ans[i] = ar[jj]
		jj += 1
if n % 2 == 0:
	count -= 1
print(count)
print(*ans)


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
from collections import deque
import threading
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')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
j = 0
for i in range(1, n, 2):
	b[i] = a[j]
	j += 1
for i in range(0, n, 2):
	b[i] = a[j]
	j += 1
r = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		r += 1
print(r)
print(*b)


n = int(input())
ll = list(map(int, input().split()))
ll.sort()
kk = []
for i in range(n // 2):
	kk.append(ll[-i - 1])
	kk.append(ll[i])
if n % 2 != 0:
	kk.append(ll[n // 2])
	print(n // 2)
	print(*kk)
else:
	print(n // 2 - 1)
	print(*kk)


n = int(input())
d = [int(i) for i in input().split()]
d.sort()
if n < 3 or d.count(d[0]) >= n - 1:
	print(0)
	print(' '.join(map(str, d)))
	exit()
mxd = [min(d[i], d[i + 1]) for i in range(n - 1)]
hi = (n - 3) // 2
lo = 0
while lo < hi:
	mid = (lo + hi + 1) // 2
	kk = n - mid - 2
	if sum((mxd[kk + i] > d[i] for i in range(mid + 1))) == mid + 1:
		lo = mid
	else:
		hi = mid - 1
print(lo + 1)
ans = []
for i in range(lo + 1):
	ans.append(d[n - lo - 2 + i])
	ans.append(d[i])
ans.append(d[-1])
ans.extend(d[lo + 1:n - lo - 2])
print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
n = int(input())
x = sorted(list(map(int, input().split())))
(a, b) = (x[:n // 2], x[n // 2:])
tmp = []
for i in range(n // 2):
	tmp.append(b[i])
	tmp.append(a[i])
if n % 2:
	tmp.append(b[-1])
cnt = 0
for i in range(1, n - 1, 2):
	if tmp[i + 1] > tmp[i] < tmp[i - 1]:
		cnt += 1
print(cnt)
print(*tmp)


n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
a.sort()
j = 0
for i in range(1, n, 2):
	b[i] = a[j]
	j += 1
for i in range(0, n, 2):
	b[i] = a[j]
	j += 1
count = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i + 1] > b[i]:
		count += 1
print(count)
print(*b)


def ice_spheres():
	n = int(input())
	array = [int(x) for x in input().split()]
	array.sort()
	print((n - 1) // 2)
	for i in range(n // 2):
		print(str(array[i + n // 2]) + ' ' + str(array[i]), end=' ')
	if n % 2 == 1:
		print(str(array[-1]))
ice_spheres()


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = []
if n % 2 == 0:
	p = (n - 1) // 2
else:
	p = n // 2
a1 = l[:p]
a2 = l[p:]
i = 0
(j, k) = (0, 0)
while j < len(a1) and k < len(a2):
	if i % 2 == 0:
		ans += [a2[k]]
		k += 1
	else:
		ans += [a1[j]]
		j += 1
	i += 1
if k < len(a2):
	ans += a2[k:]
print(p)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = a.copy()
b.sort()
ans = 0
b1 = b[n // 2:]
b2 = b[:n // 2]
ans = []
for i in range(len(b2)):
	ans.append(b1[i])
	ans.append(b2[i])
if len(b1) > len(b2):
	ans.append(b1[-1])
if n % 2 == 0:
	print(len(b2) - 1)
else:
	print(len(b2))
print(*ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = [0 for _ in range(n)]
if n % 2 == 0:
	print((n - 1) // 2)
else:
	print(n // 2)
j = 0
k = 1
for i in range(n - 1, n // 2 - 1, -1):
	ans[j] = A[i]
	j += 2
for i in range(n // 2):
	ans[k] = A[i]
	k += 2
print(*ans)


def check(arr, n):
	low = arr[:n]
	high = arr[-n - 1:]
	flag = True
	for i in range(n):
		if low[i] < high[i] and low[i] < high[i + 1]:
			continue
		else:
			flag = False
			break
	return flag
N = int(input())
array = list(map(int, input().split()))
sorts = sorted(array)
low = 0
top = (N - 1) // 2
cand = (low + top) // 2
while low < top:
	if check(sorts, cand):
		low = cand
		cand = (low + top) // 2 + 1
	else:
		top = cand - 1
		cand = (low + top) // 2
print(low)
n = low
lows = sorts[:n]
highs = sorts[-n - 1:]
for i in range(n):
	print(highs[i], lows[i], end=' ')
print(highs[n], end=' ')
print(*sorts[n:-n - 1])


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
(arr[0::2], arr[1::2]) = (arr[n // 2:], arr[:n // 2])
ans = 0
for i in range(1, n - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		ans += 1
print(ans)
print(*arr)


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	j = 0
	ans = [-1] * n
	for i in range(1, n, 2):
		ans[i] = l[j]
		j += 1
	for i in range(n):
		if ans[i] == -1:
			ans[i] = l[j]
			j += 1
	print((n - 1) // 2)
	print(*ans)


n = int(input())
s = input()
myList = s.split()
for i in range(len(myList)):
	myList[i] = int(myList[i])
myLen = len(myList)
if myLen <= 2:
	print(0)
	print(s)
	quit()
myList.sort(reverse=True)
myList1 = [0 for i in range(myLen)]
myList1[0] = myList[0]
myList1[-1] = myList[1]
k = 2
for i in range(2, myLen - 1, 2):
	myList1[i] = myList[k]
	k += 1
for i in range(1, myLen - 1, 2):
	myList1[i] = myList[k]
	k += 1
if myList1[-2] == 0:
	myList1[-2] = myList[-1]
print((myLen - 1) // 2)
myList1 = [str(e) for e in myList1]
print(' '.join(myList1))


n = int(input())
ice = sorted([int(i) for i in input().split(' ')])
new_ices = [-1] * n
c = 0
for i in range(1, n, 2):
	new_ices[i] = ice[c]
	c += 1
for i in range(0, n, 2):
	new_ices[i] = ice[c]
	c += 1
cheapest = 0
for i in range(1, n, 2):
	if new_ices[i - 1] > new_ices[i] and n > i + 1 and (new_ices[i + 1] > new_ices[i]):
		cheapest += 1
print(cheapest)
for x in new_ices:
	print(x, end=' ')


n = int(input())
l = list(sorted(map(int, input().split())))
left = l[0:n // 2]
right = l[n // 2:n]
arr = [-1 for x in range(n)]
count = 0
flag = True
j = 0
k = 0
for i in range(n):
	if flag == True:
		arr[i] = right[j]
		j += 1
		flag = False
	elif flag == False:
		arr[i] = left[k]
		k += 1
		flag = True
for a in range(1, n - 1):
	if arr[a] < arr[a - 1] and arr[a] < arr[a + 1]:
		count += 1
print(count)
print(*arr)


import sys as _sys

def main():
	(spheres_n,) = _read_ints()
	spheres_costs = tuple(_read_ints())
	result_costs = tuple(find_best_spheres_permutation(spheres_costs))
	print(how_many_spheres_will_buy(result_costs))
	print(*result_costs)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split(' '))

def how_many_spheres_will_buy(costs):
	costs = tuple(costs)
	result = 0
	for i in range(1, len(costs) - 1):
		if costs[i] < costs[i - 1] and costs[i] < costs[i + 1]:
			result += 1
	return result

def find_best_spheres_permutation(costs):
	costs = sorted(costs, reverse=True)
	i_from_left = i_from_right = -1
	for _ in range(len(costs)):
		if i_from_left <= i_from_right:
			i_from_left += 1
			cost_selected = costs[i_from_left]
		else:
			i_from_right += 1
			cost_selected = costs[len(costs) - 1 - i_from_right]
		yield cost_selected
main()


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	a.sort()
	ans = [0] * n
	j = n - 1
	for i in range(0, n, 2):
		ans[i] = a[j]
		j -= 1
	ans2 = list(ans)
	not_used = deque()
	for i in range(1, n, 2):
		while ans[i] == 0 and j >= 0:
			if a[j] < ans[i - 1] and a[j] < ans[min(i + 1, n - 1)]:
				ans[i] = a[j]
			else:
				not_used.append(j)
			j -= 1
		if j < 0:
			break
	for i in range(n):
		if ans[i] == 0:
			ans[i] = a[not_used.pop()]
		fin = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i + 1] and ans[i] < ans[i - 1]:
			fin += 1
	P(fin)
	print(*ans)
	return
t = 1
for i in range(t):
	solve()


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
k = 0
for j in range(1, n, 2):
	b[j] = a[k]
	k = k + 1
for j in range(0, n, 2):
	b[j] = a[k]
	k = k + 1
m = 0
for j in range(1, n - 1, 2):
	if b[j] != b[j - 1] and b[j] != b[j + 1]:
		m = m + 1
print(m)
print(' '.join(map(str, b)))


n = int(input())
l = list(map(int, input().split()))
l.sort()
high = n // 2
a = []
low = 0
temp = high
while low < temp:
	a.append(l[high])
	a.append(l[low])
	low += 1
	high += 1
while high < n:
	a.append(l[high])
	high += 1
ans = 0
for i in range(1, n - 1, 2):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ans += 1
print(ans)
for i in a:
	print(i, end=' ')


def solve(arr):
	resArray = []
	arr = sorted(arr)
	mid = len(arr) // 2
	i = 0
	j = mid
	while i < mid and j < len(arr):
		resArray.append(arr[j])
		resArray.append(arr[i])
		i += 1
		j += 1
	while j < len(arr):
		resArray.append(arr[j])
		j += 1
	return resArray
n = int(input())
arr = list(map(int, input().split()))
resArray = solve(arr)
res = n // 2 + (n % 2 - 1)
print(res)
print(*resArray)


import sys, os, io

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

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = ria()
		a = sorted(a)
		a1 = a[:n // 2]
		a2 = a[n // 2:]
		z = []
		for i in range(n // 2):
			z.append(a2[i])
			z.append(a1[i])
		if n % 2:
			z.append(a2[-1])
		c = 0
		for i in range(1, n - 1):
			if z[i] < z[i + 1] and z[i] < z[i - 1]:
				c += 1
		print(c)
		print(*z)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
arr = sorted(list(map(int, input().split())), reverse=True)
for i in range(1, n if n % 2 == 1 else n - 1, 2):
	temp = arr[i]
	arr[i] = arr[i + 1]
	arr[i + 1] = temp
print(n // 2 if n % 2 == 1 else n // 2 - 1)
print(' '.join(map(str, arr)))


from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.read().splitlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx]
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

class Problem:

	def __init__(self):
		self.oo = float('inf')

	def gcd(self, a, b):
		return a if b == 0 else self.gcd(b, a % b)

	def modpow(self, a, n, m):
		ans = 1
		while n:
			if n & 1:
				ans = ans * a % m
			n >>= 1
			a = a * a % m
		return ans

	def solve(self, n, a):
		a.sort(reverse=True)
		i = 1
		count = 0
		while i + 1 < n:
			count += 1
			(a[i], a[i + 1]) = (a[i + 1], a[i])
			i += 2
		print(count)
		print(*a)
try:
	p = Problem()
	for tc in Input().unknown_tests():
		p.solve(*tc.array(), tc.array())
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


from sys import stdin
n = int(stdin.readline())
a = sorted(map(int, input().split()))
m = (n - 1) // 2
c = 0
b = []
for i in range(n):
	b.append(a[(1 - i % 2) * (n // 2) + i // 2])
for i in range(1, m + 1):
	if b[i * 2 - 1] < min(b[i * 2 - 2], b[i * 2]):
		c += 1
print(c)
for i in range(n):
	print(b[i], end=' ')


n = int(input())
s = list(map(int, input().split()))
s.sort()
if n <= 2:
	print(0)
	print(*s)
	exit()
p = [0] * n
i = 0
j = n - 1
while j >= 0:
	p[i] = s[j]
	i += 1
	if i % 2:
		j -= 3
	else:
		j += 1
if n % 2 == 0:
	p[-2] = s[1]
else:
	p[-2] = s[0]
p[-1] = s[n - 2]
ans = 0
for i in range(1, n - 1):
	if p[i] < p[i + 1] and p[i] < p[i - 1]:
		ans += 1
print(ans)
print(*p)


from sys import stdin, stdout, maxsize
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
from math import ceil, floor
from _collections import defaultdict
from bisect import bisect_left, bisect_right
n = I()
ls = lint()
ls.sort()
print((n - 1) // 2)
for i in range(0, n - 1, 2):
	(ls[i], ls[i + 1]) = (ls[i + 1], ls[i])
star(ls)


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 = sorted(array())
small = a[:n // 2]
large = a[n // 2:]
ans = [0] * n
si = 0
li = 0
for i in range(n):
	if i % 2:
		ans[i] = small[si]
		si += 1
	else:
		ans[i] = large[li]
		li += 1
c = n // 2
if n % 2 == 0:
	c -= 1
print(c)
print(*ans)


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = set(x)
if len(q) % 2 == 1:
	print(len(q) // 2)
	for i in range(n // 2):
		print(x[n // 2 + i], end=' ')
		print(x[i], end=' ')
	print(x[n - 1])
else:
	print((len(q) - 1) // 2)
	for i in range(n // 2 - 1):
		print(x[n // 2 + i - 1], end=' ')
		print(x[i], end=' ')
	print(x[n - 2], x[n - 1])


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	l = []
	if n < 3:
		print(0)
		print(*a)
		return
	half = n // 2
	for i in range(half):
		l.append(a[half + i])
		l.append(a[i])
	if n % 2 != 0:
		l.append(a[-1])
	total = 0
	for j in range(1, n - 1):
		if l[j] < l[j - 1] and l[j] < l[j + 1]:
			total += 1
	print(total)
	print(*l)
main()


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = 0
y = x
if n % 2 != 0:
	p = n // 2
	for i in range(1, n - 2, 2):
		(a[i], a[i + 2]) = (a[i + 2], a[i])
	(a[n - 2], a[n - 1]) = (a[n - 1], a[n - 2])
	print(p)
	for i in a:
		print(i, end=' ')
else:
	p = n // 2 - 1
	for i in range(1, n - 2, 2):
		(a[i], a[i + 2]) = (a[i + 2], a[i])
	print(p)
	for i in a:
		print(i, end=' ')


import math
n = int(input())
arr = [int(item) for item in input().split()]
arr.sort()
brr = []
i = 0
j = n // 2
while j < n:
	brr.append(arr[j])
	j = j + 1
	if i < n // 2:
		brr.append(arr[i])
		i = i + 1
count = 0
for i in range(1, n - 1):
	if brr[i] < brr[i - 1] and brr[i] < brr[i + 1]:
		count = count + 1
print(count)
print(*brr)


n = int(input())
price = list(map(int, input().split()))
price.sort()
ans = (n - 1) // 2
first = ans + 1
print(ans)
cheap = price[:first - 1]
high = price[first - 1:]
fin = []
for i in range(len(cheap)):
	fin.append(high[i])
	fin.append(cheap[i])
high = high[len(cheap):]
while high:
	x = high.pop()
	fin.append(x)
print(' '.join(map(str, fin)))


n = int(input())
l = list(map(int, input().split()))
print((n - 1) // 2)
l.sort(reverse=True)
ans = []
ans.append(l[0])
for i in range(0, n, 2):
	if i + 2 < n:
		ans.append(l[i + 2])
	if i + 1 < n:
		ans.append(l[i + 1])
for i in range(n):
	print(ans[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
cheap = int((n - 1) / 2)
j = cheap
result = [0]
while i < cheap or j < n:
	if i < cheap:
		if j < n:
			if a[j] == result[-1] or a[i] == a[j]:
				result.append(a[j])
				j += 1
			else:
				result.append(a[j])
				result.append(a[i])
				i += 1
				j += 1
		else:
			result.append(a[i])
			i += 1
	else:
		result.append(a[j])
		j += 1
count = 0
for i in range(2, n):
	if result[i - 1] > result[i] and result[i] < result[i + 1]:
		count += 1
print(count)
print(' '.join((str(val) for val in result[1:n + 1])))


from collections import deque
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
q = deque([])
for i in range(N):
	q.append(a[i])
if N % 2 == 1:
	print(N // 2)
else:
	print(-1 + N // 2)
X = []
i = 0
while len(q) > 0:
	if i % 2 == 0:
		X.append(q.pop())
	else:
		X.append(q.popleft())
	i += 1
print(*X)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
p = 0
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
for i in range(n // 2, n):
	print(l[i], end=' ')
	if p < n // 2:
		print(l[p], end=' ')
		p += 1


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')
n = int(input())
arr = sorted(list(map(int, input().split())))
if n == 0:
	print(0)
	print(*arr)
elif n == 2:
	print(0)
	arr.sort()
	print(*arr)
else:
	ls = [0] * n
	var = 0
	var2 = n // 2
	for i in range(n):
		if (i + 1) % 2 == 0:
			ls[i] = arr[var]
			var += 1
		else:
			ls[i] = arr[var2]
			var2 += 1
	cntt = 0
	for i in range(1, n - 1):
		if ls[i] < ls[i + 1] and ls[i] < ls[i - 1]:
			cntt += 1
	print(cntt)
	print(*ls)


a = int(input())
b = input()
deshovie = []
dorogie = []
bb = [int(k) for k in b.split(' ')]
bb.sort()
bbres = sorted(bb, reverse=True)
for i in range(int(((a - 2) / 2 + 0.5) // 1)):
	deshovie.append(bb[i])
for i in range(int(a // 2 + 1)):
	dorogie.append(bbres[i])
dorogie.sort()
print(int(((a - 2) / 2 + 0.5) // 1))
print(dorogie[0], end=' ')
for i in range(int(((a - 2) / 2 + 0.5) // 1)):
	print(deshovie[i], dorogie[i + 1], end=' ')
if a // 2 - ((a - 2) / 2 + 0.5) // 1 == 1:
	print(dorogie[a // 2], end=' ')


n = int(input())
arr = list(map(int, input().split()))
if n > 2:
	if not n % 2 == 0:
		print(n // 2)
	else:
		print(n // 2 - 1)
	arr.sort(reverse=True)
	i = 1
	if n % 2 == 0:
		n -= 1
	while i < n:
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		i += 2
	for num in arr:
		print(num, end=' ')
else:
	print(0)
	for num in arr:
		print(num, end=' ')


n = int(input())
arr = [int(num) for num in input().split(' ')]
arr.sort()
ans = [-1] * n
if n % 2 != 0:
	i = 1
	j = 0
	while i < n:
		ans[i] = arr[j]
		i = i + 2
		j = j + 1
	i = 2
	while i < n:
		ans[i] = arr[j]
		i = i + 2
		j = j + 1
	ans[0] = arr[-1]
	print(n // 2)
	for item in ans:
		print(item, end=' ')
else:
	i = 0
	j = 0
	while i < n:
		ans[i] = arr[j]
		i = i + 2
		j = j + 1
	i = 1
	while i < n:
		ans[i] = arr[j]
		i = i + 2
		j = j + 1
	print(n // 2 - 1)
	for item in ans:
		print(item, end=' ')


def solve(N, list1):
	list1.sort()
	answer = [0 for i in range(len(list1))]
	answer[0] = list1.pop(-1)
	j = -1
	temp = 0
	ans = 0
	while True:
		if temp == 0:
			j += 3
			if len(list1) != 0 and 0 < j < len(answer):
				answer[j] = list1.pop(-1)
			elif len(list1) > 0:
				answer += list1
				break
			else:
				break
			temp = 1
		elif temp == 1:
			j -= 1
			if len(list1) != 0 and 0 < j < len(answer):
				answer[j] = list1.pop(-1)
				ans += 1
			elif len(list1) > 0:
				answer += list1
				break
			else:
				break
			temp = 0
		if answer[-1] != 0 and answer[-2] != 0:
			break
	return [answer, ans]
N = int(input())
list1 = list(map(int, input().split()))
answer = solve(N, list1)
print(answer[1])
for i in range(len(answer[0])):
	if answer[0][i] != 0:
		print(answer[0][i], end=' ')


from math import ceil, floor
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
(gl, sl) = ([], [])
if n & 1:
	print(n // 2)
else:
	print(n // 2 - 1)
for i in range(ceil(n / 2)):
	gl.append(l[i])
for i in range(ceil(n / 2), n):
	sl.append(l[i])
sl.reverse()
oc = ec = 0
for i in range(n):
	if i % 2 == 0:
		print(gl[oc], end=' ')
		oc += 1
	else:
		print(sl[ec], end=' ')
		ec += 1
print()


n = int(input())
a = list(map(int, input().split()))
a.sort()
from collections import deque
b = deque(a[:n // 2])
c = deque(a[n // 2:])
ans = []
while len(b) or len(c):
	ans.append(c.popleft())
	if len(b) > 0:
		ans.append(b.popleft())
l = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		l += 1
print(l)
print(' '.join(map(str, ans)))


n = int(input())
l = list(map(int, input().split()))
l.sort()
f = 0
for i in range(n - 1):
	if f == 0:
		(l[i], l[i + 1]) = (l[i + 1], l[i])
		f = 1
	else:
		f = 0
ans = (n - 1) // 2
print(ans)
print(*l)


import sys
readline = sys.stdin.readline
INF = 1 << 60

def read_int():
	return int(readline())

def read_int_n():
	return list(map(int, readline().split()))

def read_float():
	return float(readline())

def read_float_n():
	return list(map(float, readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def ep(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.perf_counter()
		ret = f(*args, **kwargs)
		e = time.perf_counter()
		ep(e - s, 'sec')
		return ret
	return wrap
from collections import deque

def ref(N, A):
	from itertools import permutations
	ans = 0
	for B in permutations(A, r=N):
		t = 0
		for i in range(1, N - 1):
			if B[i - 1] > B[i] < B[i + 1]:
				t += 1
		ans = max(t, ans)
	print(ans)

def slv(N, A):
	A.sort()
	A = deque(A)
	B = deque()
	while A:
		a = A.pop()
		B.append(a)
		if A:
			a = A.popleft()
			B.append(a)
	ans = 0
	for i in range(1, N - 1):
		if B[i - 1] > B[i] < B[i + 1]:
			ans += 1
	print(ans)
	print(*B)

def main():
	N = read_int()
	A = read_int_n()
	slv(N, A)
main()


N = int(input())
X = sorted(list(map(int, input().split())))
Y = []
Length = len(X)
for I in range(0, Length):
	J = int(I // 2)
	if I % 2 == 0:
		Y.append(str(X[Length - J - 1]))
	else:
		Y.append(str(X[J]))
print((N - 1) // 2)
print(' '.join(Y))


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = []
if n % 2 == 1:
	ans.append(l[n // 2])
	for i in range(n // 2):
		ans.append(l[i])
		ans.append(l[(n + 1) // 2 + i])
else:
	for i in range(n // 2):
		ans.append(l[(n + 1) // 2 + i])
		ans.append(l[i])
num = 0
for i in range(1, n - 1):
	if ans[i] < min(ans[i - 1], ans[i + 1]):
		num += 1
print(num)
print(' '.join(map(str, ans)))


import collections
n = int(input())
num = collections.deque(sorted(map(int, input().split())))
ans = []
while num:
	ans.append(num.pop())
	if num:
		ans.append(num.popleft())
print((n - 1) // 2)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = [-1] * n
m = y = n // 2
for x in range(0, n, 2):
	b[x] = a[y]
	y += 1
y = 0
for x in range(1, n, 2):
	b[x] = a[y]
	y += 1
ans = 0
for x in range(1, n - 1):
	if b[x] < b[x - 1] and b[x] < b[x + 1]:
		ans += 1
print(ans)
for x in range(n):
	print(b[x], end=' ')


def read_line(type=int):
	return list(map(type, input().split()))
n = int(input())
d = read_line()
d = sorted(d)[::-1]
ans = [0] * n
ans[::2] = d[:(n + 1) // 2]
ans[1::2] = d[(n + 1) // 2:]
answer = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		answer += 1
answer1 = 0
ans1 = ans[1:] + ans[0:1]
for i in range(1, n - 1):
	if ans1[i - 1] > ans1[i] < ans1[i + 1]:
		answer1 += 1
answer2 = 0
ans2 = ans[-1:] + ans[:-1]
for i in range(1, n - 1):
	if ans2[i - 1] > ans2[i] < ans2[i + 1]:
		answer2 += 1
print(max([answer, answer1, answer2]))
print(*[ans, ans1, ans2][[answer, answer1, answer2].index(max([answer, answer1, answer2]))])


import sys
from copy import *
from bisect import *

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	a.sort()
	ans = [a[-1]]
	l = c = 0
	r = n - 2
	while l <= r:
		ans.append(a[l])
		l += 1
		if r >= l:
			ans.append(a[r])
			r -= 1
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			c += 1
	print(c)
	print(*ans)


def solve(n, arr):
	arr.sort()
	res = [0 for i in range(n)]
	for i in range(n // 2):
		res[2 * i + 1] = arr[i]
	for i in range((n + 1) // 2):
		res[2 * i] = arr[i + n // 2]
	count = 0
	for i in range(1, n - 1, 2):
		if res[i] < min(res[i - 1], res[i + 1]):
			count += 1
	print(count)
	print(*res)
n = int(input())
arr = list(map(int, input().split()))
solve(n, arr)


def main(n, a):
	spheres = n // 2
	new = []
	i = 0
	while i < spheres:
		new.append(str(a[spheres + i]))
		new.append(str(a[i]))
		i += 1
	if n % 2 != 0:
		new.append(str(a[-1]))
		return f"{str(spheres)}\n{' '.join(new)}"
	else:
		return f"{str(spheres - 1)}\n{' '.join(new)}"
n = int(input())
a = sorted(list(map(int, input().split())))
print(main(n, a))


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = [0] * n
for i in range(n):
	if 1 + 2 * i < n:
		m[1 + 2 * i] = l[i]
	else:
		m[(2 * i + n % 2) % n] = l[i]
c = 0
for i in range(1, n - 1):
	if m[i + 1] > m[i] and m[i - 1] > m[i]:
		c += 1
print(c)
print(*m)


import sys
n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))
lst.sort()
result = lst[n // 2:]
for i in range(n // 2):
	result.insert(2 * i + 1, lst[i])
cnt = 0
for i in range(1, n - 1):
	if result[i - 1] > result[i] and result[i] < result[i + 1]:
		cnt += 1
print(cnt)
print(' '.join(map(str, result)))


n = int(input())
arr = sorted([int(n) for n in input().split(' ')])
res = [0 for _ in range(n)]
j = 0
for i in range(1, n, 2):
	res[i] = arr[j]
	j += 1
for i in range(0, n, 2):
	res[i] = arr[j]
	j += 1
total = 0
for i in range(1, n - 1):
	if res[i] < res[i - 1] and res[i] < res[i + 1]:
		total += 1
print(total)
print(' '.join([str(s) for s in res]))


import sys, collections, math

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
result = [arr[0]]
i = 2
while i < n:
	result.append(arr[i])
	result.append(arr[i - 1])
	i += 2
if n % 2 != 0:
	print(n // 2)
	print(*result)
else:
	n -= 1
	print(n // 2)
	result.append(arr[-1])
	print(*result)


(lambda N, n: (lambda nn: (print(sum((1 for i in range(1, N - 1) if nn[i - 1] > nn[i] and nn[i + 1] > nn[i]))), print(*nn)))([n[i >> 1] if i & 1 else n[(i >> 1) + (N >> 1)] for i in range(N)]))(int(input()), sorted(map(int, input().split())))


n = int(input())
list1 = list(map(int, input().split()))
list1.sort()
list2 = [-1] * len(list1)
count = 0
for i in range(1, len(list2), 2):
	if i > len(list2):
		break
	list2[i] = list1[count]
	count += 1
for i in range(0, len(list2), 2):
	if i > len(list2):
		break
	list2[i] = list1[count]
	count += 1
s = 0
for i in range(1, len(list2) - 1):
	if list2[i] < list2[i - 1] and list2[i] < list2[i + 1]:
		s += 1
print(s)
print(*list2)


N = int(input())
A = list(map(int, input().split()))
A.sort()
result = [0 for _ in range(N)]
i = 0
j = N - 1
while i < N:
	result[i] = A[j]
	i += 2
	j -= 1
i = 1
c = 0
while i < N:
	result[i] = A[j]
	j -= 1
	if i != N - 1:
		c += 1
	i += 2
print(c)
for r in result:
	print(r, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = [None for _ in range(n)]
i = 0
j = 0
while j < n:
	ans[j] = a[i]
	j += 2
	i += 1
k = i
j = 1
while k < n:
	ans[j] = a[k]
	j += 2
	k += 1
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i + 1] and ans[i] < ans[i - 1]:
		count += 1
print(count)
print(' '.join(map(str, ans)))


n = int(input())
l = list(map(int, input().split()))
a = sorted(l)
ans = (n - 1) // 2
j = -1
for i in range(0, n, 2):
	l[i] = a[j]
	j -= 1
for i in range(1, n, 2):
	l[i] = a[j]
	j -= 1
print(ans)
print(' '.join(list(map(str, l))))


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
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 = int(input())
arr = list(map(int, input().split()))
arr.sort()
i = 0
c = n
n = n // 2 * 2
print((c - 1) // 2)
while i < n:
	print(arr[i + 1], arr[i], end=' ')
	i += 2
if c % 2 == 1:
	print(arr[-1])


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = n // 2
sl = l[:m]
ll = l[m:]
if n % 2 == 0:
	out = []
	c = 0
	for i in range(m):
		out.append(ll[i])
		out.append(sl[i])
	for i in range(1, len(out) - 1):
		if out[i] < out[i + 1] and out[i] < out[i - 1]:
			c += 1
	print(c)
	for i in out:
		print(i, end=' ')
	print()
else:
	out = [ll[0]]
	c = 0
	for i in range(m):
		out.append(sl[i])
		out.append(ll[i + 1])
	for i in range(1, len(out) - 1):
		if out[i] < out[i + 1] and out[i] < out[i - 1]:
			c += 1
	print(c)
	for i in out:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
A.sort()
ANS = [-1] * n
if n % 2 == 0:
	print(n // 2 - 1)
	ind = 1
	aind = 0
	for i in range(n // 2 - 1):
		ANS[ind] = A[aind]
		aind += 1
		ind += 2
	ind = 0
	while aind < n:
		if ANS[ind] == -1:
			ANS[ind] = A[aind]
			aind += 1
		ind += 1
	print(*ANS)
else:
	print(n // 2)
	ind = 1
	aind = 0
	for i in range(n // 2):
		ANS[ind] = A[aind]
		aind += 1
		ind += 2
	ind = 0
	while aind < n:
		if ANS[ind] == -1:
			ANS[ind] = A[aind]
			aind += 1
		ind += 1
	print(*ANS)


t = int(input())
l = list(map(int, input().split()))
l.sort()
print((t - 1) // 2)
s = 0
e = t - 1
while s < e:
	print(l[e], l[s], end=' ')
	s += 1
	e -= 1
if s == e:
	print(l[s])


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k, modulus=1):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
		res %= modulus
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = sorted(int_array())
if n < 3:
	print(0)
	print(*a)
else:
	ans = (n - 1) // 2
	i = 0
	while i < n - 1:
		temp = a[i]
		a[i] = a[i + 1]
		a[i + 1] = temp
		i += 2
	print(ans)
	print(*a)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
if n & 1 == 1:
	l = n // 2
	ans = l
	li = []
	left = arr[:l]
	arr = arr[l:]
else:
	l = n // 2 - 1
	ans = l
	left = arr[:l]
	arr = arr[l:]
print(ans)
for i in range(len(left)):
	print(arr[i], left[i], end=' ')
for i in range(len(left), len(arr)):
	print(arr[i], end=' ')


for t in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = []
	pos = 1
	while len(arr) > 0:
		if pos % 2 == 1:
			ele = arr.pop(-1)
		else:
			ele = arr.pop(0)
		ans.append(ele)
		pos += 1
	count = 0
	if n > 2:
		for i in range(1, n - 1):
			if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
				count += 1
	print(count)
	print(*ans)


n = int(input())
spi = sorted(list(map(int, input().split())))
z = spi[:n // 2]
q = spi[n // 2:]
count = 0
itog = [q[0]]
qw = 0
if n % 2 == 0:
	qw = n // 2
else:
	qw = len(z)
for i in range(qw):
	try:
		if z[i] < q[i] and z[i] < q[i + 1]:
			count += 1
			itog.append(z[i])
			itog.append(q[i + 1])
	except:
		itog.append(z[i])
print(count)
print(*itog)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
l = 0
r = n - 1
ans = []
f = 0
while l <= r:
	ans.append(arr[r])
	if r == l:
		break
	ans.append(arr[l])
	l += 1
	r -= 1
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		f += 1
print(f)
print(*ans)


def solve():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	a.sort()
	a1 = a[:n // 2]
	a2 = a[n // 2:]
	flag = True
	cursor1 = 0
	cursor2 = 0
	prevPrice = -100
	ans = 0
	for i in range(len(a2)):
		if i + 1 < len(a2):
			ans += 1 if a2[i] > a1[i] and a1[i] < a2[i + 1] else 0
	print(ans)
	for i in range(n):
		if not flag:
			print(a1[cursor1], end=' ')
			cursor1 += 1
		else:
			print(a2[cursor2], end=' ')
			cursor2 += 1
		flag = not flag
t = 1
for _ in range(t):
	solve()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	l = 0
	r = n - 1
	print((n - 1) // 2)
	for i in range(n):
		if i % 2 > 0:
			print(a[l], end=' ')
			l += 1
		else:
			print(a[r], end=' ')
			r -= 1
t = 1
while t > 0:
	solve()
	t -= 1


from math import ceil
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(ceil(n / 2) - 1)
(b, c) = (a[:n // 2], a[n // 2:])
for i in range(len(b)):
	print(c[i], b[i], end=' ')
print('' if len(c) == len(b) else c[len(b)])


def solve(arr, n):
	arr = sorted(arr, reverse=True)
	i = 1
	while i + 1 < n:
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		i += 2
	print((n - 1) // 2)
	for x in arr:
		print(x, end=' ')
	print()
n = int(input())
arr = list(map(int, input().split()))
solve(arr, n)


N = int(input())
prices = list(map(int, input().split()))
sortedPrices = sorted(prices)
sortedIdx = 0
modifiedPrices = [None for _ in sortedPrices]
for i in range(1, len(sortedPrices), 2):
	modifiedPrices[i] = sortedPrices[sortedIdx]
	sortedIdx += 1
for i in range(0, len(prices), 2):
	modifiedPrices[i] = sortedPrices[sortedIdx]
	sortedIdx += 1
maxIceCreams = 0
for i in range(1, len(modifiedPrices) - 1):
	if modifiedPrices[i] < modifiedPrices[i - 1] and modifiedPrices[i] < modifiedPrices[i + 1]:
		maxIceCreams += 1
print(maxIceCreams)
for i in range(len(modifiedPrices)):
	print(modifiedPrices[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
num = (n - 1) // 2
print(num)
a.sort()
s = a[:n // 2]
l = a[n // 2:]
ans = [None for i in range(n)]
ans[0:n:2] = l
ans[1:n:2] = s
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [-1] * n
k = 0
c = 0
for i in range(1, n, 2):
	ans[i] = arr[k]
	k += 1
for i in range(n):
	if ans[i] == -1:
		ans[i] = arr[k]
		k += 1
for i in range(1, n - 1, 2):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		c += 1
print(c)
for i in range(n):
	print(ans[i], end=' ')


def main():
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	b1 = l[:n // 2]
	b2 = l[n // 2:]
	if n % 2 == 0:
		print(n // 2 - 1)
	else:
		print(n // 2)
	i1 = 0
	i2 = 0
	for i in range(n):
		if i % 2 == 1:
			print(b1[i1], end=' ')
			i1 += 1
		else:
			print(b2[i2], end=' ')
			i2 += 1
main()


from sys import stdin, stdout
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')
for _ in range(1):
	n = inp()
	l = li()
	l.sort()
	a = l[:n // 2]
	b = l[n // 2:]
	k = []
	(x, y) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			k.append(b[x])
			x += 1
		else:
			k.append(a[y])
			y += 1
	ans = 0
	for i in range(1, n - 1, 2):
		if k[i] < k[i - 1] and k[i] < k[i + 1]:
			ans += 1
	pr(ans)
	print(*k)


from math import sqrt
n = int(input())
li = list(map(int, input().split()))
max = (n - 2) / 2
if max == int(max):
	num = int(max)
elif max != int(max):
	num = int(max) + 1
if n == 1 or n == 2:
	print(0)
	print(*li)
else:
	li.sort(reverse=True)
	if n % 2 != 0:
		l = []
		l.append(li[0])
		l.append(li[2])
		for i in range(1, n, 2):
			l.append(li[i])
			if i == n - 2:
				break
			else:
				l.append(li[i + 3])
	elif n % 2 == 0:
		l = []
		l.append(li[0])
		l.append(li[2])
		for j in range(1, n, 2):
			l.append(li[j])
			if j == n - 3:
				break
			else:
				l.append(li[j + 3])
		l.append(li[-1])
	print(num)
	print(*l)


n = int(input())
arr = list(map(int, input().split()))
if n % 2 == 0:
	print((n - 1) // 2)
else:
	print(n // 2)
arr.sort()
i = 0
j = n - 1
while i <= j:
	if i == j:
		print(arr[i])
	else:
		print(arr[j], arr[i], end=' ')
	i += 1
	j -= 1


from sys import stdin
_ = int(stdin.readline())
nums = sorted(map(lambda x: int(x), stdin.readline().split()))
cheap = nums[:len(nums) // 2]
expensive = nums[len(cheap):]
result = []
for i in range(len(cheap)):
	result.append(str(expensive[i]))
	result.append(str(cheap[i]))
if len(cheap) < len(expensive):
	result.append(str(expensive[-1]))
print(len(expensive) - 1)
print(' '.join(result))


n = int(input())
l = input().split()
for i in range(len(l)):
	l[i] = int(l[i])
l = sorted(l)
print((n - 1) // 2)
small = l[0:(n - 1) // 2]
big = l[(n - 1) // 2:]
ans = []
if n % 2 == 0:
	ans.append(str(big[-1]))
	ans.append(str(big[-2]))
	for i in range((n - 1) // 2):
		ans.append(str(small[i]))
		ans.append(str(big[i]))
else:
	ans.append(str(big[-1]))
	for i in range((n - 1) // 2):
		ans.append(str(small[i]))
		ans.append(str(big[i]))
print(' '.join(ans))


import math
n = int(input())
arr = [int(i) for i in input().split()]
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
arr.sort()
ans2 = []
ans2.append(arr[-1])
for i in range(n - 2, 0, -2):
	ans2.append(arr[i - 1])
	ans2.append(arr[i])
if n % 2 == 0:
	ans2.append(arr[0])
print(ans)
print(*ans2)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [0] * n
if n < 3:
	print(0)
	print(*arr)
else:
	for i in range(1, n, 2):
		ans[i] = arr.pop(0)
	for i in range(0, n, 2):
		ans[i] = arr.pop(0)
	cnt = 0
	for i in range(1, n - 1):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			cnt += 1
	print(cnt)
	print(*ans)


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si():
	return input()

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

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

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

def out(v):
	print(v)

def spout():
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
n = ii()
a = li()
a.sort()
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
m = n // 2
print(a[m], end=' ')
l = 1
i = 0
j = n - 1
while l < n:
	print(a[i], end=' ')
	if j != m:
		print(a[j], end=' ')
	i += 1
	j -= 1
	l += 2


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	a.sort()
	an = (n - 1) // 2
	ind = an + 1
	ans = [a[an]]
	for i in range(an):
		ans.append(a[i])
		ans.append(a[ind])
		ind += 1
	while ind < n:
		ans.append(a[ind])
		ind += 1
	print(an)
	print(*ans)


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
take = a[:(n - 1) // 2].copy()
op = a[(n - 1) // 2:].copy()
na = len(op)
ans = []
ansP = 0
n1 = 0
nt = n - na
prev = 0
for i in take:
	p = bisect.bisect_right(op, i, prev)
	if p < na - 1:
		ansP += 1
		ans.append(op[p])
		ans.append(i)
		op[p] = -1
		n1 += 1
		prev = p
	else:
		ans.append(op[na - 1])
		op[na - 1] = -1
		break
for i in op[::-1]:
	if i != -1:
		if n1 < nt:
			ans.append(take[n1])
			n1 += 1
		ans.append(i)
print(ansP)
for i in ans:
	print(i, end=' ')
print('')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
import math
from math import *

def main():
	n = int(input())
	a = sorted(map(int, input().split()))
	ans = [0] * n
	j = 0
	for i in range(1, n, 2):
		ans[i] = a[j]
		j += 1
	for i in range(n):
		if ans[i] == 0:
			ans[i] = a[j]
			j += 1
	j = 0
	for i in range(1, n - 1, 2):
		if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
			j += 1
	print(j)
	print(*ans)
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()


from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)
ans = deque([])
while len(a):
	ans.append(a.pop())
	if len(a):
		ans.append(a.popleft())
print((n - 1) // 2)
print(*ans)


import math
n = int(input())
a = sorted(list(map(int, input().split())))
if n >= 3:
	l = []
	l.append(a[n - 2])
	k = a[:n - 2]
	fh = k[:math.ceil((n - 2) / 2)]
	sh = k[math.ceil((n - 2) / 2):n - 2]
	ff = 0
	ss = 0
	for i in range(n - 2):
		if i % 2 == 0:
			l.append(fh[ff])
			ff += 1
		else:
			l.append(sh[ss])
			ss += 1
	l.append(a[n - 1])
	if n % 2 == 0:
		print(int((n - 2) / 2))
	else:
		print(int((n - 2) // 2 + 1))
	print(*l)
else:
	print(0)
	print(*a)


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(1):
	(n,) = I()
	l = I()
	l.sort()
	j = 1
	temp = [0] * n
	for i in range(n):
		if j >= n:
			j = 0
		temp[j] = l[i]
		j += 2
	ans = 0
	for i in range(1, n - 1):
		if temp[i - 1] > temp[i] < temp[i + 1]:
			ans += 1
	print(ans)
	print(*temp)


n = int(input())
arr = sorted(list(map(int, input().split())))
t = (n - 1) // 2
ans = [0 for _ in range(n)]
j = 1
for i in arr[:t]:
	ans[j] = i
	j += 2
j = 0
for i in arr[t:]:
	ans[j] = i
	j += 2
	if j == n:
		j -= 1
print((n - 1) // 2)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = []
f = 0
less = arr[:n // 2]
gre = arr[n // 2:]
l = 0
while l != n // 2:
	ans.append(gre[l])
	ans.append(less[l])
	l += 1
if n % 2 != 0:
	ans.append(gre[-1])
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		f += 1
print(f)
print(*ans)


import math
n = int(input())
l = list(map(int, input().split()))
if len(l) <= 2:
	print(0)
	print(*l)
else:
	l.sort()
	(i, j) = (0, len(l) - 1)
	c = 0
	k = [l[j]]
	j -= 1
	while j > i:
		k.append(l[i])
		i += 1
		k.append(l[j])
		j -= 1
		c += 1
	while j >= i:
		k.append(l[j])
		j -= 1
	print(c)
	print(*k)


def rearrange(arr, n):
	temp = n * [None]
	(small, large) = (0, n - 1)
	flag = True
	for i in range(n):
		if flag is True:
			temp[i] = arr[large]
			large -= 1
		else:
			temp[i] = arr[small]
			small += 1
		flag = bool(1 - flag)
	for i in range(n):
		arr[i] = temp[i]
	return arr
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = rearrange(a, n)
print((n - 1) // 2)
for i in ans:
	print(i, end=' ')


import math
from decimal import *
import random
n = int(input())
arr = sorted(list(map(int, input().split())))
add = 0
sub = 0
if n % 2 == 1:
	add += 1
if n % 2 == 0:
	sub += 1
(pnt1, pnt2) = (0, 0)
(a1, a2) = (arr[int(math.ceil(n / 2)) - add:], arr[:n // 2])
ans = []
pos = True
for i in range(n):
	if pos:
		ans.append(str(a1[pnt1]))
		pos = False
		pnt1 += 1
	elif not pos:
		ans.append(str(a2[pnt2]))
		pos = True
		pnt2 += 1
print(n // 2 - sub)
print(' '.join(ans))


import sys
input = sys.stdin.readline
N = int(input())
A = [int(_) for _ in input().split()]
sA = sorted(A)
B = ['?'] * N
for i in range(N // 2):
	B[2 * i + 1] = sA[i]
for i in range(N // 2, N):
	B[2 * (i - N // 2)] = sA[i]
answer = 0
for i in range(N // 2):
	if 2 * i + 2 < N:
		if B[2 * i + 1] < B[2 * i] and B[2 * i + 1] < B[2 * i + 2]:
			answer += 1
print(answer)
print(' '.join(map(str, B)))


def testcase():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = (n - 1) // 2
	print(ans)
	arr.sort()
	ans = [0 for _ in arr]
	ans[0] = n - 2
	ans[-1] = n - 1
	for i in range(1, n - 1, 2):
		ans[i] = i // 2
	for i in range(2, n - 1, 2):
		ans[i] = i // 2 + (n - 1) // 2 - 1
	for i in range(n):
		ans[i] = arr[ans[i]]
	for element in ans:
		print(element, end=' ')
	print()
	return
testcase()


n = int(input())
s = list(map(int, input().split()))
s.sort()
p = [-1] * n
j = 0
for i in range(1, n, 2):
	p[i] = s[j]
	j += 1
for i in range(0, n, 2):
	p[i] = s[j]
	j += 1
ans = 0
for i in range(1, n - 1):
	if p[i] < p[i + 1] and p[i] < p[i - 1]:
		ans += 1
print(ans)
print(*p)


n = int(input())
prices = map(int, input().split())
prices = list(prices)
prices.sort()
cheaps = (n - 1) // 2
first = prices[:n // 2]
last = prices[n // 2:]
inter = [x for t in zip(last, first) for x in t]
if len(last) > len(first):
	inter.append(last[-1])
print(cheaps)
print(*inter, sep=' ')


N = int(input())
List = [int(x) for x in input().split()]
List.sort()
count = 0
arr = [0] * N
index = 0
for i in range(1, N, 2):
	arr[i] = List[index]
	index += 1
for i in range(0, N, 2):
	arr[i] = List[index]
	index += 1
count = 0
for i in range(1, N - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		count += 1
print(count)
print(*arr)


n = int(input())
arr = list(map(int, input().strip().split()))[:n]
arr.sort()
c = 0
if n % 2 == 0:
	x = n // 2 - 1
	lst = arr[:x]
else:
	x = n // 2
	lst = arr[:x]
print(x)
for i in range(x, len(arr)):
	print(arr[i], end=' ')
	if c != len(lst):
		print(lst[c], end=' ')
		c += 1


n = int(input())
arr = sorted(list(map(int, input().split())))
arr1 = arr[:n // 2]
arr2 = arr[n // 2:]
llstr = ''
for i in range(len(arr1)):
	llstr += str(arr2[i]) + ' '
	llstr += str(arr1[i]) + ' '
if n % 2 != 0:
	llstr += str(arr2[len(arr2) - 1])
	print(len(arr1))
else:
	print(len(arr1) - 1)
print(llstr)


def fun(ls, n):
	if n == 1 or n == 2:
		print(0)
		print(*ls)
		return
	position = n // 2
	index = position - 1
	ls = sorted(ls)
	ans = [0 for i in range(n)]
	even = n - 1
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			ans[i] = ls[even]
			even -= 1
		else:
			ans[i] = ls[odd]
			odd += 1
	if n % 2 != 0:
		print(n // 2)
	else:
		print(n // 2 - 1)
	print(*ans)
n = int(input())
ls = list(map(int, input().split()))
fun(ls, n)


n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
res = [0] * n
(i, j) = (0, n // 2)
k = 0
while k < n:
	if k % 2 == 0:
		res[k] = l[j]
		j += 1
	else:
		res[k] = l[i]
		i += 1
	k += 1
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
for i in range(n):
	print(res[i], end=' ')
print()


t = 1
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	print((n - 1) // 2)
	arr.sort()
	ans = []
	for i in range(n):
		if i % 2 == 0:
			ans += [arr[-1 - i // 2]]
		else:
			ans += [arr[i // 2]]
	print(*ans)


n = int(input())
l = list(map(int, list(input().split())))
l.sort()
left = [l[i] for i in range(n // 2)]
right = [l[i] for i in range(n // 2, n)]
s = []
if n % 2 != 0:
	print(n // 2)
else:
	print(n // 2 - 1)
while len(left) > 0 and len(right) > 0:
	s.append(right.pop(0))
	s.append(left.pop(0))
while len(right) > 0:
	s.append(right.pop(0))
while len(left) > 0:
	s.append(left.pop(0))
for i in range(n - 1):
	print(s[i], end=' ')
print(s[-1])


n = int(input())
array = list(map(int, input().split()))
array.sort()
output = []
array1 = array[0:n // 2]
array2 = array[n // 2:]
i = 0
j = 0
count = 0
while i < n // 2 and j < (n - 1) // 2:
	b = array2[j]
	a = array1[i]
	output.append(b)
	output.append(a)
	if b > a:
		count += 1
	i += 1
	j += 1
if n % 2 != 0:
	output.append(array2[-1])
else:
	output.append(array2[-1])
	output.append(array1[-1])
print(count)
print(' '.join(map(str, output)))


from collections import deque as dq
n = int(input())
l = list(map(int, input().split()))
l.sort()
l = dq(l)
r = []
while l:
	r.append(l.pop())
	if len(l) > 0:
		r.append(l.popleft())
if n % 2 == 0:
	print(n // 2 - 1)
	print(*r)
else:
	print(n // 2)
	print(*r)


n = int(input())
l = sorted(list(map(int, input().split())))
x = []
if n <= 2:
	print(0)
	print(*l)
elif n % 2 == 0:
	a = l[:n // 2]
	b = l[n // 2:]
	ans = 0
	for i in range(n // 2):
		x.append(b[i])
		x.append(a[i])
	for j in range(1, n - 1, 2):
		if x[j] < x[j + 1] and x[j] < x[j - 1]:
			ans += 1
	print(ans)
	print(*x)
else:
	a = l[:n // 2]
	b = l[n // 2:]
	ans = 0
	for i in range(n // 2):
		x.append(b[i])
		x.append(a[i])
	x.append(b[-1])
	for j in range(1, n, 2):
		if x[j] < x[j + 1] and x[j] < x[j - 1]:
			ans += 1
	print(ans)
	print(*x)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
k = 0
if n % 2 == 0:
	a1 = a[:n // 2 - 1]
	a2 = a[n // 2 - 1:]
	l = []
	for i in range(n):
		if i % 2 == 1 and len(a1) > 0:
			l.append(a1.pop())
		else:
			l.append(a2.pop())
	k = 0
	for i in range(1, n - 1, 2):
		if l[i - 1] > l[i] < l[i + 1]:
			k += 1
	print(k)
	print(*l)
else:
	a1 = a[:n // 2]
	a2 = a[n // 2:]
	l = []
	for i in range(n):
		if i % 2 == 1 and len(a1) > 0:
			l.append(a1.pop())
		else:
			l.append(a2.pop())
	k = 0
	for i in range(1, n - 1, 2):
		if l[i - 1] > l[i] < l[i + 1]:
			k += 1
	print(k)
	print(*l)


import sys
readline = sys.stdin.readline

def inlt():
	return list(map(int, readline().split()))

def ingen():
	return map(int, readline().split())

def insr():
	s = readline()
	return list(s)

def inn():
	return int(readline())
M = inn()
items = inlt()
res = [0 for i in range(M)]
items.sort()
max_idx = (M - 1) // 2
bound = items[max_idx]
ret = 0
idx = 0
for i in range(1, M, 2):
	res[i] = items[idx]
	idx += 1
for i in range(0, M, 2):
	res[i] = items[idx]
	idx += 1
for i in range(1, M - 1):
	if res[i] < res[i - 1] and res[i] < res[i + 1]:
		ret += 1
print(ret)
print(' '.join(map(str, res)))


n = int(input())
a = [int(x) for x in input().split()]
b = [0] * n
a.sort()
k = 0
c = 0
for i in range(1, n, 2):
	b[i] = a[k]
	k += 1
for i in range(0, n, 2):
	b[i] = a[k]
	k += 1
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		c += 1
print(c)
print(*b)


from collections import deque
n = int(input())
a = deque(sorted(map(int, input().split())))
b = []
while a:
	b.append(a.pop())
	if a:
		b.append(a.popleft())
ct = 0
for i in range(1, n - 1):
	if b[i] < b[i + 1] and b[i] < b[i - 1]:
		ct += 1
print(ct)
print(*b)


n = int(input())
a = sorted(map(int, input().split()))
if n < 3:
	print(0)
	print(' '.join(map(str, a)))
else:
	k = n // 2
	cheap = a[:k]
	expensive = a[k:]
	print(k if n % 2 else k - 1)
	arr = [0] * n
	for i in range(n):
		if i % 2 == 0:
			arr[i] = expensive[i // 2]
		else:
			arr[i] = cheap[i // 2]
	print(' '.join(map(str, arr)))


n = int(input())
arr = [int(j) for j in input().split()]
arr.sort()
start = arr[:n // 2]
end = arr[n // 2:]
neww = []
for i in range(len(start)):
	neww.append(end[i])
	neww.append(start[i])
if n % 2 == 1:
	neww.append(end[-1])
if n <= 2:
	print(0)
	print(*arr)
elif n % 2 == 1:
	print(n // 2)
	print(*neww)
else:
	print(n // 2 - 1)
	print(*neww)


n = int(input())
l = list(map(int, input().split()))
l.sort()
j = 0
mid = len(l) // 2
a = [0] * (n + 2)
for i in range(mid):
	(a[i + j], a[i + 1 + j]) = (l[mid + i], l[i])
	j += 1
if n % 2 != 0:
	a[n - 1] = l[n - 1]
p = 0
for i in range(1, n):
	if a[i - 1] > a[i] and a[i] < a[i + 1]:
		p += 1
print(p)
a = a[:n]
s = ' '.join(map(str, a))
print(s)


n = int(input())
a = sorted([int(x) for x in input().split()])
r = (n - 1) // 2
R = [None] * n
R[1::2] = a[:n // 2]
R[0::2] = a[n // 2:]
print(r)
print(*R)


n = int(input())
a = sorted([int(i) for i in input().split()])
b = []
for i in range(n // 2):
	b.append(a[-1 - i])
	b.append(a[i])
if n % 2 == 1:
	b.append(a[n // 2])
print((n - 1) // 2)
print(' '.join([str(i) for i in b]))


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
ans = [-1 for _ in range(n)]
if n % 2 == 0:
	ans[n - 1] = a[n // 2]
	l = 0
	r = n // 2 + 1
	lNext = True
	for i in range(n - 1):
		if lNext:
			ans[i] = a[l]
			l += 1
		else:
			ans[i] = a[r]
			r += 1
		lNext = not lNext
else:
	l = 0
	r = n // 2 + 1
	lNext = True
	for i in range(n):
		if lNext:
			ans[i] = a[l]
			l += 1
		else:
			ans[i] = a[r]
			r += 1
		lNext = not lNext
cnts = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		cnts += 1
print(cnts)
print(' '.join([str(x) for x in ans]))


from sys import stdin, stdout, maxsize
from bisect import bisect_right
import math
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
n = int(R())
a = RL(int)
a.sort()

def f(x):
	ind = bisect_right(a, a[x - 1])
	if x + 1 <= n - ind:
		return True
	return False
ans = n * [-1]
j = 0
for i in range(n):
	if i % 2:
		ans[i] = a[j]
		j += 1
for i in range(n):
	if ans[i] == -1:
		ans[i] = a[j]
		j += 1
cnt = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


import sys
import collections as cc
import bisect as bi
I = lambda : list(map(int, input().split()))
for tc in range(1):
	(n,) = I()
	l = I()
	l.sort()
	i = 0
	j = n - 1
	ar = []
	cur = 0
	while i <= j:
		if cur % 2 == 1:
			cur += 1
			ar.append(l[i])
			i += 1
		else:
			cur += 1
			ar.append(l[j])
			j -= 1
	ans = 0
	for i in range(1, n - 1):
		if ar[i] < ar[i - 1] and ar[i] < ar[i + 1]:
			ans += 1
	print(ans)
	print(*ar)


from sys import stdin, stdout
n = int(stdin.readline())
lst = [int(i) for i in stdin.readline().split()]
lst.sort()
ans = (n - 1) // 2
if n % 2 == 0:
	ans2 = ans + 1
else:
	ans2 = ans
pt1 = lst[:ans2]
pt2 = lst[ans2:]
anslst = []
for i in range(len(pt2)):
	anslst += [str(pt2[i])]
	if i == len(pt1):
		break
	anslst += [str(pt1[i])]
stdout.write(str(ans) + '\n')
out = ' '.join(anslst)
stdout.write(str(out))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
c = a[:n // 2]
d = a[n // 2:]
if n % 2 == 1:
	print(n // 2)
else:
	print(n // 2 - 1)
s = []
for i in range(n):
	if i % 2 == 0:
		s.append(str(d[i // 2]))
	else:
		s.append(str(c[i // 2]))
print(' '.join(s))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = [0] * n
c = 0
for i in range(1, n, 2):
	b[i] = a[c]
	c += 1
for i in range(0, n, 2):
	b[i] = a[c]
	c += 1
s = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		s += 1
print(s)
print(*b)


n = int(input())
array = list(map(int, input().split()))
array.sort()
output = []
i = n - 1
j = 0
while i > j:
	output.append(array[i])
	output.append(array[j])
	i -= 1
	j += 1
if i == j:
	output.append(array[i])
print((n - 1) // 2)
print(' '.join(map(str, output)))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
ansarr = []
if n < 3:
	print(0)
	print(' '.join([str(x) for x in a]))
elif n % 2 == 0:
	for i in range(n // 2):
		ansarr.append(a[n // 2 + i])
		ansarr.append(a[i])
	for i in range(1, len(a) - 1, 2):
		if ansarr[i] < ansarr[i - 1] and ansarr[i] < ansarr[i + 1]:
			ans += 1
	print(ans)
	print(' '.join([str(x) for x in ansarr]))
else:
	for i in range(n // 2):
		ansarr.append(a[n // 2 + i])
		ansarr.append(a[i])
	ansarr.append(a[len(a) - 1])
	for i in range(1, len(a), 2):
		if ansarr[i] < ansarr[i - 1] and ansarr[i] < ansarr[i + 1]:
			ans += 1
	print(ans)
	print(' '.join([str(x) for x in ansarr]))


n = int(input())
l = list(map(int, input().split()))
print((n - 1) // 2)
l.sort()
for i in range(1, n, 2):
	(l[i], l[i - 1]) = (l[i - 1], l[i])
print(*l)


n = int(input())
a = list(map(int, input().split()))
a.sort()
p1 = 0
p2 = n // 2
b = []
for i in range(n):
	if i % 2 == 0:
		b.append(a[p2])
		p2 = p2 + 1
	else:
		b.append(a[p1])
		p1 = p1 + 1
ans = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		ans = ans + 1
print(ans)
for i in range(n):
	if i == n - 1:
		print(b[i])
	else:
		print(b[i], end=' ')


n = int(input())
d = [*map(int, input().split())]
d.sort()
p = []
for i in range(n // 2 + n % 2):
	p.append(d[n - i - 1])
	if n - i - 1 != i:
		p.append(d[i])
ans = 0
for i in range(1, n, 2):
	if i > 0 and i < n - 1 and (p[i] < p[i + 1]) and (p[i] < p[i - 1]):
		ans += 1
print(ans)
print(*p)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
l.sort()
t = 0
l1 = []
for i in range(n // 2):
	l1.append(l[n - i - 1])
	l1.append(l[i])
if n % 2 != 0:
	l1.append(l[n // 2])
if (n - 2) % 2 == 0:
	d = (n - 2) // 2
else:
	d = (n - 2) // 2 + 1
print(d)
print(*l1)


n = int(input())
lst = sorted(list(map(int, input().split())))
if n >= 3 and n % 2 != 0:
	print(n // 2)
elif n >= 3 and n % 2 == 0:
	print(n // 2 - 1)
else:
	print(0)
list1 = []
list2 = []
for (m, i) in enumerate(lst):
	if m < n // 2:
		list1.append(i)
	else:
		list2.append(i)
new = []
for i in range(n // 2):
	new.append(list2[i])
	new.append(list1[i])
if len(list1) > len(list2):
	new.append(list1[-1])
elif len(list2) > len(list1):
	new.append(list2[-1])
for i in new:
	print(i, end=' ')


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, recursion_limit, stack_size):
		setrecursionlimit(recursion_limit)
		threading.stack_size(stack_size)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		n = int(R())
		a = [int(x) for x in R().split()]
		l = (n - 1) // 2
		ans.append(str(l))
		a.sort()
		ice = a[:l]
		s = ''
		(i, j) = (0, l)
		while j < n:
			if i < l:
				s += str(a[j]) + ' ' + str(a[i]) + ' '
			else:
				s += str(a[j]) + ' '
			i += 1
			j += 1
		ans.append(s)
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
Tail_Recursion_Optimization(10 ** 7, 2 ** 26)
threading.Thread(target=main).start()


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
result = []
if n % 2 == 1:
	print(n // 2)
else:
	print(n // 2 - 1)
result = lst[n // 2:]
for i in range(n // 2):
	result.insert(2 * i + 1, lst[i])
print(' '.join(map(str, result)))


n = int(input())
arr = list(map(int, input().split()))
arr1 = []
print((n - 1) // 2)
a = sorted(arr)
for i in range(0, n - 1, 2):
	(a[i], a[i + 1]) = (a[i + 1], a[i])
print(*a, sep=' ')


import math
import sys
input = sys.stdin.readline
n = int(input())
l = sorted(list(map(int, input().split())))
print(n // 2 - 1 + n % 2)
i = 0
j = n // 2
p = []
while i < n // 2 and j < n:
	p.append(l[j])
	p.append(l[i])
	j += 1
	i += 1
while i < n // 2:
	p.append(l[i])
	i += 1
while j < n:
	p.append(l[j])
	j += 1
print(*p)


def maxsell(n):
	if n % 2 == 0:
		e = n // 2 - 1
	else:
		e = n // 2
	return e
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = maxsell(n)
c = c - 1
d = c
i = c + 1
u = 0
if c > 0:
	while i < len(a):
		if a[c] == a[i]:
			i = i + 1
		else:
			break
	if len(a) - i <= c:
		o = len(a) - i
		i = c - 1
		while i >= 0:
			if a[c] == a[i]:
				i = i - 1
			else:
				break
		c = i + o // 2
		if c > d:
			c = d
print(c + 1)
d = c
i = len(a) - 1
while i > d:
	print(a[i], end=' ')
	if c >= 0:
		print(a[c], end=' ')
	i = i - 1
	c = c - 1


n = int(input())
s = input()
m = [int(s) for s in s.split()]
m = sorted(m)
if len(m) % 2 == 0:
	l = n // 2 - 1
else:
	l = n // 2
f = m[:n // 2]
s = m[n // 2:]
z = 0
b = []
for i in range(len(f)):
	b.append(s[i])
	b.append(f[i])
if n % 2 != 0:
	b.append(s[-1])
print(l)
print(*b)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = []
j = 0
for i in range(int(n // 2), n):
	x.append(a[i])
	if j < int(n // 2):
		x.append(a[j])
		j += 1
ans = 0
for i in range(1, n - 1):
	if x[i] < x[i + 1] and x[i] < x[i - 1]:
		ans += 1
print(ans)
for i in x:
	print(i, end=' ')
print()


n = int(input())
s = input()
s1 = s.split()
l = [int(i) for i in s1]
l.sort()
maxi = (n - 1) // 2
j = 0
final = [0 for i in range(len(l))]
for i in range(1, len(final), 2):
	final[i] = l[j]
	j = j + 1
if len(l) % 2 == 1:
	x = len(l) - 1
else:
	x = len(l) - 2
j = len(l) - 1
for i in range(x, -1, -2):
	final[i] = l[j]
	j = j - 1
cnt = 0
for i in range(1, len(l), 2):
	if i + 1 < len(l) and final[i] < final[i - 1] and (final[i] < final[i + 1]):
		cnt = cnt + 1
print(cnt)
print(*final)


import sys
input = sys.stdin.readline
n = int(input())
A = sorted(map(int, input().split()))
B = A[:(n - 1) // 2]
C = A[(n - 1) // 2:]
ANS = [-1] * n
for i in range((n - 1) // 2):
	ANS[i * 2 + 1] = B[i]
indl = 0
indr = n - 1
ind = 0
while ind < len(C):
	while ANS[indl] != -1:
		indl += 1
	while ANS[indr] != -1:
		indr -= 1
	if indl < n - 1 and C[ind] > ANS[indl + 1]:
		ANS[indl] = C[ind]
	else:
		ANS[indr] = C[ind]
	ind += 1
SC = 0
for i in range(1, n - 1):
	if ANS[i - 1] > ANS[i] and ANS[i] < ANS[i + 1]:
		SC += 1
print(SC)
print(*ANS)


n = int(input())
b = input().split()
a = sorted([int(num) for num in b])
greedy = []
if n < 3:
	print('0')
	if n == 1:
		print(a[0])
	else:
		print('{} {}'.format(a[0], a[1]))
else:
	maxbuy = n // 2
	if n % 2 == 0:
		maxbuy = maxbuy - 1
	print(maxbuy)
	for i in range(maxbuy):
		greedy.append(a[i + maxbuy])
		greedy.append(a[i])
	for i in range(len(greedy), n):
		greedy.append(a[i])
	for num in greedy:
		print(num, end=' ')


n = int(input())
l = input().split()
li = [int(i) for i in l]
li.sort()
print((n - 1) // 2)
z = li[:(n - 1) // 2]
y = li[(n - 1) // 2:]
curr1 = 0
curr2 = 0
for i in range(n):
	if i == 0 or i == n - 1:
		print(y[curr1], end=' ')
		curr1 += 1
		continue
	if i % 2 == 0:
		print(y[curr1], end=' ')
		curr1 += 1
		continue
	print(z[curr2], end=' ')
	curr2 += 1


R = lambda : map(int, input().split())
n = int(input())
arr = sorted(R(), reverse=True)
vst = [0] * n
res = []
j = 0
k = (n + 1) // 2
cnt = 0
for i in range(n):
	if not vst[i]:
		res.append(arr[i])
		j = max(j, i + 1)
		while j < n and vst[j]:
			j += 1
		k = max(k, j + 1)
		while k < n and (vst[k] or arr[k] >= arr[j]):
			k += 1
		if k < n:
			res.append(arr[k])
			vst[k] = 1
			cnt += 1
print(cnt)
print(' '.join(map(str, res)))


n = int(input())
A = sorted([int(_) for _ in input().split()])
i = 0
j = n // 2
X = []
for _ in range(n):
	if _ % 2 == 0:
		X.append(A[j])
		j += 1
	else:
		X.append(A[i])
		i += 1
print((n - 1) // 2)
print(*X)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
b = [0] * n
count = 0
for x in range(0, n, 2):
	b[x] = a[count]
	count += 1
for x in range(1, n, 2):
	b[x] = a[count]
	count += 1
count = 0
for x in range(1, n - 1):
	if b[x] < b[x - 1] and b[x] < b[x + 1]:
		count += 1
print(count)
for x in range(n):
	print(b[x], end=' ')


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	A.sort()
	x = N // 2
	if N % 2 == 0:
		print(N // 2 - 1)
	else:
		print(N // 2)
		print(str(A[N // 2]), end=' ')
		x += 1
	for i in range(N // 2):
		print(A[i], A[x + i], end=' ')
main()


def solve(n, A):
	A.sort()
	v = [0] * n
	j = 0
	for i in range(1, n, 2):
		v[i] = A[j]
		j += 1
	for i in range(0, n, 2):
		v[i] = A[j]
		j += 1
	count = 0
	for i in range(1, n - 1):
		pre = i - 1
		cur = i
		next = i + 1
		if v[pre] > v[cur] and v[next] > v[cur]:
			count += 1
	print(count)
	return v
res = []
n = int(input())
in_ = map(int, input().split(' '))
for c in in_:
	res.append(int(c))
print(*solve(n, res))


import math
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(math.ceil(n / 2) - 1)
if n >= 3:
	for i in range(0, n - 1, 2):
		(l[i], l[i + 1]) = (l[i + 1], l[i])
	print(*l)
else:
	print(*l)


from sys import stdin, stdout
from math import ceil

def find(arr, N):
	arr.sort()
	K = N // 2 + 1
	R = [arr[K - 1]]
	i = -1
	for i in range(ceil(N / 2) - 1):
		R.append(arr[i])
		R.append(arr[K])
		K += 1
	if N % 2 == 0:
		R.append(arr[i + 1])
	C = 0
	for i in range(1, len(R) - 1):
		if R[i - 1] > R[i] < R[i + 1]:
			C += 1
	print(C)
	print(' '.join(map(str, R)))

def main():
	N = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	find(arr, N)
main()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr2 = []
z = n // 2
if n % 2 == 0:
	print(n // 2 - 1)
	for (k, kk) in zip(arr[:z], arr[z:]):
		arr2.append(kk)
		arr2.append(k)
else:
	print(n // 2)
	for (k, kk) in zip(arr[:z], arr[z:]):
		arr2.append(kk)
		arr2.append(k)
	arr2.insert(len(arr), arr[-1])
for i in arr2:
	print(i, end=' ')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	L = sorted(map(int, input().split()))
	ans = (n - 1) // 2
	for i in range(0, n - 1, 2):
		(L[i], L[i + 1]) = (L[i + 1], L[i])
	print(ans)
	print(*L)
solve()


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
(arr[0::2], arr[1::2]) = (arr[n // 2:], arr[:n // 2])
if n % 2 == 1:
	print(n // 2)
	print(*arr)
else:
	print((n - 1) // 2)
	print(*arr)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
n = II()
aa = LI()
aa.sort()
l = (n - 1) // 2
ans = []
i = l
for a in aa[:l]:
	while 1:
		ans.append(aa[i])
		i += 1
		if ans[-1] > a:
			break
	ans.append(a)
for a in aa[i:]:
	ans.append(a)
print(l)
print(*ans)


from sys import stdin, stdout
from math import sqrt, floor
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.sort()
for i in range(1, n - 1, 2):
	(arr[i], arr[i - 1]) = (arr[i - 1], arr[i])
ans = 0
for i in range(1, n - 1, 2):
	if arr[i] < min(arr[i - 1], arr[i + 1]):
		ans += 1
stdout.write('{}\n'.format(ans))
stdout.write(' '.join(map(str, arr)))


n = int(input())
a = list(map(int, input().split()))
a.sort()
cheap = int((n - 1) / 2)
print(int((n - 1) / 2))
i = cheap
j = 0
while j < cheap:
	print('{} {} '.format(a[i], a[j]), end='')
	i += 1
	j += 1
while i < n:
	print('{} '.format(a[i]), end='')
	i += 1
print('')


n = int(input())
A = list(map(int, input().split()))
if n % 2 != 0:
	print(n // 2)
	A.sort()
	i = 0
	j = n - 1
	while i < n // 2 and j >= n // 2:
		print(A[j], A[i], end=' ')
		i += 1
		j -= 1
	if i < n // 2:
		print(A[i])
	elif j >= n // 2:
		print(A[j])
else:
	print(n // 2 - 1)
	A.sort()
	i = 0
	j = n - 1
	while i < n // 2 and j >= n // 2:
		print(A[j], A[i], end=' ')
		i += 1
		j -= 1
	if i < n // 2:
		print(A[i])
	elif j >= n // 2:
		print(A[j])


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
while i < n - 1:
	temp = a[i]
	a[i] = a[i + 1]
	a[i + 1] = temp
	i += 2
ans = 0
for j in range(1, n - 1):
	if a[j] < a[j - 1] and a[j] < a[j + 1]:
		ans += 1
print(ans)
for n in a:
	print(n, end=' ')
print()


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
print((n - 1) // 2)
i = n - 1
j = 0
c = 0
p = 1
while c < n:
	if p > 0:
		print(a[i], end=' ')
		i -= 1
		c += 1
		p *= -1
	else:
		print(a[j], end=' ')
		j += 1
		c += 1
		p *= -1
print()


n = int(input())
arr = list(map(int, input().strip().split()))
i = 0
ans = 0
arr.sort()
while i + 2 < n:
	(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	i += 2
	ans += 1
print(ans)
print(*arr)


n = int(input())
a = sorted(list(map(int, input().split())))
val = 0
(b, c) = (a[:n // 2], a[n // 2:-1])
sol = [a[-1]]
d = []
(b_ptr, c_ptr) = (len(b) - 1, len(c) - 1)
while True:
	if b_ptr < 0 or c_ptr < 0:
		break
	cc = c[c_ptr]
	while b_ptr >= 0:
		if b[b_ptr] >= cc:
			d.append(b[b_ptr])
			b_ptr -= 1
		else:
			break
	if b_ptr < 0:
		break
	else:
		sol.append(b[b_ptr])
		b_ptr -= 1
		sol.append(c[c_ptr])
		c_ptr -= 1
		val += 1
sol += b[:max(b_ptr + 1, 0)] + c[:max(c_ptr + 1, 0)] + d
print(val)
print(' '.join([str(i) for i in sol]))


n = int(input())
a = list(map(int, input().split()))
while False:
	break
a.sort()
ans = [0] * n
ind = 0
for j in range(1, n, 2):
	ans[j] = a[ind]
	ind += 1
for j in range(0, n, 2):
	ans[j] = a[ind]
	ind += 1
cnt = 0
for j in range(1, n - 1):
	if ans[j - 1] > ans[j] and ans[j + 1] > ans[j]:
		cnt += 1
print(cnt)
for j in ans:
	print(j, end=' ')


def get_int():
	return int(input())

def get_ints():
	return [int(x) for x in input().split()]
n = get_int()
spheres = get_ints()
spheres.sort(reverse=True)
reorder = []
i = 0
j = len(spheres) - 1
while i <= j:
	reorder.append(spheres[i])
	i += 1
	if i <= j:
		reorder.append(spheres[j])
		j -= 1
print((len(spheres) - 1) // 2)
print(*reorder, sep=' ')


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
l.sort()
t = 0
l1 = []
c = 0
for i in range(n // 2, n):
	l1.append(l[i])
	if i != n - 1 or n % 2 == 0:
		l1.append(l[c])
	c += 1
c = 0
for i in range(1, n - 1):
	if l1[i] < l1[i - 1] and l1[i] < l1[i + 1]:
		c += 1
print(c)
print(*l1)


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
firstPart = []
secondPart = []
firstPartLength = math.floor((n - 1) / 2)
secondPartLength = n - firstPartLength
for i in range(firstPartLength):
	firstPart.append(a[i])
for i in range(firstPartLength, n):
	secondPart.append(a[i])
c = []
secondPartPointer = 0
ans = 0
secondPart.reverse()
firstPart.reverse()
for i in range(firstPartLength):
	before = secondPart[secondPartPointer]
	c.append(before)
	secondPartPointer += 1
	main = firstPart[i]
	c.append(main)
	after = secondPart[secondPartPointer]
	if main < after and main < before:
		ans += 1
for i in range(secondPartPointer, secondPartLength):
	c.append(secondPart[i])
print(ans)
for i in range(n - 1):
	print(c[i], end=' ')
print(c[n - 1])


from sys import stdin
input = stdin.readline
n = int(input())
a = sorted(map(int, input().split()))
b = [0] * n
print((n - 1) // 2)
for i in range(n):
	if i < n // 2:
		b[2 * i + 1] = a[i]
	else:
		b[(i - n // 2) * 2] = a[i]
print(*b)


def MI():
	return map(int, input().split())
import copy
for _ in range(1):
	n = int(input())
	arr = list(MI())
	ans = 0
	arr.sort()
	out = [-1 for i in range(n)]
	for i in range(0, n, 2):
		out[i] = arr.pop()
	k = copy.deepcopy(out)
	h = copy.deepcopy(arr)[::-1]
	op = 0
	for i in range(1, n, 2):
		k[i] = h.pop()
		if i + 1 < n:
			if k[i] < k[i + 1] and k[i] < k[i - 1]:
				op += 1
	for i in range(1, n, 2):
		out[i] = arr.pop()
		if i + 1 < n:
			if out[i] < out[i + 1] and out[i] < out[i - 1]:
				ans += 1
	if ans > op:
		print(ans)
		print(*out)
	else:
		print(op)
		print(*k)


def buy(n, a):
	a.sort()
	m = n // 2
	l = 0
	i = 0
	ans = []
	while i < n:
		if i % 2 == 0:
			ans.append(a[m])
			m += 1
		else:
			ans.append(a[l])
			l += 1
		i += 1
	print(n // 2 - (n + 1) % 2)
	print(*ans)
n = int(input())
a = list(map(int, input().split()))
buy(n, a)


from math import *
from cmath import *
from decimal import *
from fractions import *
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
a.sort()
b[0] = a[n // 2]
(i, ans) = (1, 0)
(l, r) = (0, n // 2 + 1)
while i <= n - 1:
	if i == n - 1:
		b[i] = a[l]
		break
	elif i > n - 1:
		break
	else:
		b[i] = a[l]
		b[i + 1] = a[r]
		i += 2
		if b[i - 2] < b[i - 3] and b[i - 2] < b[i - 1]:
			ans += 1
	r += 1
	l += 1
print(ans)
for _ in b:
	print(_, end=' ')


n = int(input())
arr = list(map(int, input().split()))
print((n - 1) // 2)
split_index = (n - 1) // 2
arr.sort()
l = arr[:split_index]
r = arr[split_index:]
if n % 2 == 0:
	for i in range(split_index):
		print(r[i], l[i], end=' ')
	print(r[-2], r[-1])
else:
	for i in range(split_index):
		print(r[i], l[i], end=' ')
	print(r[-1])


n = int(input())
list1 = list(map(int, input().split()))
list1.sort()
if n <= 2:
	print(0)
	print(*list1)
else:
	temp = [-1] * len(list1)
	count = 0
	for i in range(1, len(list1), 2):
		temp[i] = list1[count]
		count += 1
	for i in range(0, len(list1), 2):
		temp[i] = list1[count]
		count += 1
	s = 0
	for i in range(1, len(list1) - 1):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			s += 1
	print(s)
	print(*temp)


n = int(input())
inputArr = list(map(int, input().split()))
sortedArray = sorted(inputArr)
finalarray = [0 for _ in inputArr]
localMinIdx = 0
ans = 0
for i in range(1, len(inputArr), 2):
	finalarray[i] = sortedArray[localMinIdx]
	localMinIdx += 1
for j in range(0, len(inputArr)):
	if finalarray[j] == 0:
		finalarray[j] = sortedArray[localMinIdx]
		localMinIdx += 1
for k in range(1, len(inputArr) - 1, 2):
	if finalarray[k - 1] > finalarray[k] and finalarray[k + 1] > finalarray[k]:
		ans += 1
print(ans)
for x in finalarray:
	print(x, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = ''
t = 0
for i in range(n):
	if i % 2 != 0:
		t = a[i]
		a[i] = a[i - 1]
		a[i - 1] = t
for i in a:
	s += str(i) + ' '
print((n - 1) // 2)
print(s[:len(s) - 1])


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort()
k = math.ceil(n / 2) - 1
lst1 = lst[:k]
lst2 = lst[k:]
l = []
i1 = 0
i2 = 0
for i in range(n):
	if i % 2 != 0 and i1 < k:
		l.append(lst1[i1])
		i1 += 1
	else:
		l.append(lst2[i2])
		i2 += 1
print(k)
for i in range(n):
	print(l[i], end=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n < 3:
	print(0)
	print(*l)
else:
	k = []
	for i in range(n // 2):
		k.append(l[i])
	u = []
	for i in range(n // 2, n):
		u.append(l[i])
	o = []
	l = []
	if n % 2 == 0:
		print(n // 2 - 1)
		for j in range(n // 2):
			if j < n // 2:
				o.append(u[j])
				o.append(k[j])
			else:
				o.append(u[j])
		print(*o)
	else:
		print(n // 2)
		for j in range(n // 2 + 1):
			if j < n // 2:
				o.append(u[j])
				o.append(k[j])
			else:
				o.append(u[j])
		print(*o)


n = int(input())
arr = list(map(int, input().split()))
print((n - 1) // 2)
arr.sort()
res = []
res.append(arr[n - 1])
index = n - 2
while index >= 0:
	if index - 1 >= 0:
		res.append(arr[index - 1])
	res.append(arr[index])
	index -= 2
print(*res)


import math
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = math.floor((n - 1) / 2)
an = []
odd = 0
eve = -1
for i in range(n):
	if i % 2 == 0:
		an.append(a[eve])
		eve -= 1
	else:
		an.append(a[odd])
		odd += 1
print(ans)
print(*an)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = []
(i, j) = (0, n - 1)
c = 0
while i <= j:
	if i <= j:
		b.append(a[j])
		j -= 1
	if i <= j:
		b.append(a[i])
		i += 1
		if len(b) <= n - 1:
			c += 1
print(c)
print(*b)


n = int(input())
v = sorted(map(int, input().split()))
print((n - 1) // 2)
x = []
for (a, b) in zip(v[0::2], v[1::2]):
	x.append(b)
	x.append(a)
if len(x) < len(v):
	x += [v[-1]]
print(*x, sep=' ')


n = int(input())
a = list(map(int, input().split()))
a.sort()
print((n - 1) // 2)
for i in range(n // 2):
	(a[2 * i], a[2 * i + 1]) = (a[2 * i + 1], a[2 * i])
for values in a:
	print(values, end=' ')


n = int(input())
ls = list(map(int, input().split()))
print((n - 1) // 2)
ls.sort()
ReturnLs = []
i = 0
for j in range(n // 2, n):
	ReturnLs.append(ls[j])
	if i != n // 2:
		ReturnLs.append(ls[i])
	i += 1
print(*ReturnLs)


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
if len(arr) % 2 != 0:
	anchor = len(arr) // 2
	left = []
	right = []
	for i in range(anchor):
		left.append(arr[i])
	for i in range(anchor, len(arr)):
		right.append(arr[i])
	right.sort(reverse=True)
	left.sort(reverse=True)
	ans = []
	cnt = 0
	while left and right:
		cnt += 1
		ans.append(right.pop())
		ans.append(left.pop())
	while right:
		ans.append(right.pop())
	while left:
		ans.append(left.pop())
else:
	anchor = len(arr) // 2 - 1
	left = []
	right = []
	for i in range(anchor):
		left.append(arr[i])
	for i in range(anchor, len(arr)):
		right.append(arr[i])
	right.sort(reverse=True)
	left.sort(reverse=True)
	ans = []
	cnt = 0
	while left and right:
		cnt += 1
		ans.append(right.pop())
		ans.append(left.pop())
	while right:
		ans.append(right.pop())
	while left:
		ans.append(left.pop())
print(cnt)
print(' '.join(map(str, ans)))


n = int(input())
a = list(map(int, input().split()))
if len(a) <= 2:
	print(0)
elif n % 2 == 0:
	print(int(len(a) / 2) - 1)
else:
	print(int(len(a) / 2))
a.sort()
count = 0
counted = int(len(a) / 2)
b = ''
for i in range(0, len(a)):
	if i % 2 != 0:
		b += str(a[count])
		b += ' '
		count += 1
	else:
		b += str(a[counted])
		b += ' '
		counted += 1
print(b)


n = int(input())
a = [int(tok) for tok in input().split()]
ordered = [0] * n
for (i, ai) in enumerate(sorted(a, reverse=True)):
	j = 2 * i
	if j >= n:
		j -= n - (n % 2 == 0)
	ordered[j] = ai
print((n - 1) // 2)
print(*ordered)


n = int(input())
l = list(map(int, input().split()))
lena = len(l)
print((lena - 1) // 2)
l.sort()
left = l[:lena // 2]
right = l[lena // 2:]
answer = []
for i in range(len(right)):
	answer.append(right[i])
	if i < len(left):
		answer.append(left[i])
print(*answer)


n = int(input())
arr = list(map(int, input().split()))
Count = 0
for i in range(n - 1):
	if i % 2 == 0 and arr[i] < arr[i + 1]:
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
for i in range(n - 1):
	if i % 2 == 1 and arr[i] > arr[i + 1]:
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	if i % 2 == 1:
		Count += 1
if n <= 2:
	Count = 0
print(Count)
print(*arr)


def f():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	newarr = []
	for i in range(n // 2):
		newarr.append(str(arr[i + n // 2]))
		newarr.append(str(arr[i]))
	if n % 2:
		newarr.append(str(arr[n - 1]))
	newarr = ' '.join(newarr)
	print((n - 1) // 2)
	print(newarr)
f()


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
c = 0
for i in range(1, n, 2):
	b[i] = a[c]
	c += 1
for i in range(0, n, 2):
	b[i] = a[c]
	c += 1
s = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		s += 1
print(s)
print(*b)


n = int(input())
arr = list(map(int, input().split()))
print((n - 1) // 2)
arrS = sorted(arr)
arr1 = []
arr2 = []
for i in range(n // 2):
	arr1.append(arrS[i])
for i in range(1, (n + 1) // 2 + 1):
	arr2.append(arrS[-i])
for i in range(n):
	if i % 2 == 0:
		x = arr2[i // 2]
		print(x, end=' ')
	else:
		x = arr1[i // 2]
		print(x, end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
cnt = 0
i = 0
while i < n - 2:
	(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	i = i + 2
	cnt = cnt + 1
print(cnt)
for i in arr:
	print(i, end=' ')


from math import ceil
n = int(input())
z = list(map(int, input().split()))
if n < 2:
	print(0)
	for i in z:
		print(i, end=' ')
else:
	print(ceil(n / 2) - 1)
	z.sort()
	i = n - 1
	j = 0
	while i > j:
		print(z[i], end=' ')
		print(z[j], end=' ')
		i -= 1
		j += 1
		if n % 2 == 1:
			if i == j:
				print(z[i])
				break


def cheap_ice_spheres(n, order):
	if n <= 2:
		print(0)
		print(' '.join(list(map(str, order))))
	else:
		order.sort()
		new_arrangement = []
		right_end = order[-1]
		left_end = order[-2]
		order.pop(-1)
		order.pop(-1)
		if (n - 2) % 2 == 0:
			buy = (n - 2) // 2
		else:
			buy = (n - 2) // 2 + 1
		new_arrangement.append(left_end)
		sphere_buy = order[:buy]
		sphere_neighbour = order[buy:]
		if len(sphere_buy) != len(sphere_neighbour):
			sphere_neighbour.append(None)
		for (x, y) in list(zip(sphere_buy, sphere_neighbour)):
			new_arrangement.append(x)
			if y != None:
				new_arrangement.append(y)
		new_arrangement.append(right_end)
		print(buy)
		for x in new_arrangement:
			print(str(x), end=' ')
x = int(input())
n = list(map(int, input().split()))
cheap_ice_spheres(x, n)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ind = n // 2
res = []
i = 0
f = True
for j in range(n):
	if f == True:
		res.append(a[ind])
		ind += 1
		f = False
	else:
		res.append(a[i])
		i += 1
		f = True
ans = 0
for i in range(1, n - 1):
	if res[i - 1] > res[i] and res[i] < res[i + 1]:
		ans += 1
print(ans)
print(*res)


from heapq import *
from collections import *
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
tt = []
c1 = Counter(arr)
for key in c1:
	tt.append([c1[key], key])
tt.sort()
arr2 = []
for (i, j) in tt:
	arr2.append(j)
nn = len(arr2)

def score(arr):
	ans = 0
	for i in range(1, len(arr) - 1):
		if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			ans += 1
	return ans
narr = []

def update(i, minCount):
	global narr
	if minCount == 0:
		return
	tt = arr2[i:]
	tt.sort()
	n = len(tt)
	l = n // 2 + 1
	need = n - l
	if n <= 2:
		temp = tt
	else:
		i = 0
		j = need
		temp = []
		for k in range(nn - i):
			if k % 2 == 0 or need == 0:
				temp.append(tt[j])
				j += 1
			else:
				temp.append(tt[i])
				need -= 1
				i += 1
	narr += temp * minCount

def func(arr):
	c = Counter(arr)
	q = []
	for (i, e) in enumerate(arr2):
		heappush(q, (c[e], e, i))
	var = 0
	l = len(arr)
	while q:
		p = heappop(q)
		minCount = p[0] + var
		var -= minCount
		update(p[2], minCount)
		l -= 1
func(arr)
print(score(narr))
print(*narr)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
resArr = [0] * n
count = 0
j = 0
for i in range(1, n, 2):
	resArr[i] = arr[j]
	j += 1
for i in range(0, n, 2):
	resArr[i] = arr[j]
	j += 1
for i in range(1, n - 1):
	if resArr[i] < resArr[i - 1] and resArr[i] < resArr[i + 1]:
		count += 1
print(count)
print(' '.join(map(str, resArr)))


from collections import defaultdict as dd
import math
import sys
import heapq
import copy
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

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

def solve():
	n = nn()
	ice = lm()
	ice.sort()
	out = []
	for i in range(n):
		if i % 2 == 1:
			out.append(ice[i // 2])
		else:
			out.append(ice[i // 2 + n // 2])
	good = 0
	for i in range(n - 1):
		if i % 2 == 1:
			if out[i] < out[i + 1] and out[i] < out[i - 1]:
				good += 1
	print(good)
	print(*out)
solve()


n = int(input())
ar = [int(k) for k in input().split()]
ar.sort()
print((n - 1) // 2)
for i in range(n // 2):
	(ar[2 * i], ar[2 * i + 1]) = (ar[2 * i + 1], ar[2 * i])
for k in ar:
	print(k, end=' ')


n = int(input())
a = list(map(int, input().split()))
print((n - 1) // 2)
e = (n - 1) // 2
a.sort()
b = a[:e]
c = a[e:]
d = []
for i in range(e):
	d.append(c[i])
	d.append(b[i])
d.extend(c[e:])
d = list(map(str, d))
print(' '.join(d))


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
import threading
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')
t = 1
while t != 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = n // 2
	if n % 2 == 0:
		print(x - 1)
	else:
		print(x)
	j = 0
	if n == 2:
		print(a[1], a[0])
		exit()
	for i in range(n):
		if i % 2 == 0:
			print(a[x], end=' ')
			x += 1
		else:
			print(a[j], end=' ')
			j += 1


n = int(input())
a = sorted([int(x) for x in input().split()])
(p1, p2) = (0, n // 2)
counter = 0
res = []
for _ in range(n // 2):
	res.append(a[p2])
	res.append(a[p1])
	p1 += 1
	p2 += 1
if p2 < n:
	res.append(a[p2])
for i in range(1, n - 1):
	if res[i - 1] > res[i] < res[i + 1]:
		counter += 1
print(counter)
for e in res:
	print(e, end=' ')


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
for i in range(0, len(a) - 1, 2):
	(a[i], a[i + 1]) = (a[i + 1], a[i])
ans = 0
for i in range(0, len(a) - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ans += 1
print(ans)
for i in range(len(a)):
	if i != len(a) - 1:
		print(a[i], end=' ')
	else:
		print(a[i])


n = int(input())
li = [int(i) for i in input().split()]
li.sort()
if n & 1:
	p1 = li[:n >> 1]
	p2 = li[n >> 1:]
	print(n >> 1)
	for i in range(n):
		if i & 1:
			print(p1.pop(), end=' ')
		else:
			print(p2.pop(), end=' ')
	print()
else:
	print((n >> 1) - 1)
	ext = li.pop()
	n = len(li)
	p1 = li[:n >> 1]
	p2 = li[n >> 1:]
	for i in range(n):
		if i & 1:
			print(p1.pop(), end=' ')
		else:
			print(p2.pop(), end=' ')
	print(ext)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	a.sort(reverse=True)
	k = n // 2 + 1
	l = []
	for i in range(k):
		l.append(a[i])
	nl = []
	for j in range(k, n):
		nl.append(a[j])
	if n % 2 == 1:
		ans = n // 2
	else:
		ans = n // 2 - 1
	print(ans)
	for i in range(len(nl)):
		print(l[i], end=' ')
		print(nl[i], end=' ')
	for j in range(len(nl), len(l)):
		print(l[j], end=' ')
	print()


n = int(input())
a = list(map(int, input().split()))
a.sort()
res = (n - 1) // 2
result = []
for i in range(res):
	result.append(a[res + i])
	result.append(a[i])
result.extend(a[res * 2:])
print(res)
print(*result)


n = int(input().strip())
a = list(map(int, input().strip().split()))
a.sort()
i = n - 1
ls = [0] * n
j = 0
for i in range(1, n, 2):
	ls[i] = a[j]
	j += 1
for i in range(0, n, 2):
	ls[i] = a[j]
	j += 1
cnt = 0
i = 1
while i < n - 1:
	if ls[i] < ls[i - 1] and ls[i] < ls[i + 1]:
		cnt += 1
		i += 2
	else:
		i += 1
print(cnt)
print(*ls)


n = int(input())
a = sorted(map(int, input().split()))
print((n - 1) // 2)
i = 0
j = n - 1
while i != (n - 1) // 2:
	print(a[j], a[i], end=' ')
	i += 1
	j -= 1
if n & 1:
	print(a[i])
else:
	print(a[j], a[i])


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
new_arr = []
left = 0
right = n - 1
for i in range(0, n):
	if i % 2 == 0:
		new_arr.append(arr[right])
		right -= 1
	else:
		new_arr.append(arr[left])
		left += 1
count = 0
for i in range(1, n - 1):
	(left, mid, right) = new_arr[i - 1:i + 2]
	if left > mid and right > mid:
		count += 1
	else:
		continue
print(count)
for i in new_arr:
	print(i, end=' ')
print('')


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input = sys.stdin.readline
import random
mod = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(1):
	n = inin()
	l = ain()
	l.sort()
	ans = []
	k = (n + 1) // 2 - 1
	print(k)
	c = k
	for i in range(k):
		ans += [l[c], l[i]]
		c += 1
	if n % 2:
		ans += [l[c]]
	else:
		ans += [l[c], l[c + 1]]
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	print(0)
	print(' '.join(map(str, a)))
else:
	a.sort()
	b = [0] * n
	j = 0
	for i in range(1, n, 2):
		b[i] = a[j]
		j += 1
	for i in range(0, n, 2):
		b[i] = a[j]
		j += 1
	c = 0
	for i in range(1, n - 1, 2):
		if b[i - 1] > b[i] < b[i + 1]:
			c += 1
	print(c)
	print(' '.join(map(str, b)))


n = int(input())
l = sorted(list(map(int, input().split())), reverse=0)
if n % 2:
	ans = [l[-i // 2 - 1] if i % 2 == 0 else l[i // 2] for i in range(n)]
	print(n // 2)
else:
	print(n // 2 - 1)
	p = l.pop()
	ans = [l[-i // 2 - 1] if i % 2 == 0 else l[i // 2] for i in range(n - 1)] + [p]
print(*ans)


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = [int(c) for c in input().split()]
arr.sort()
ans = [None for i in range(n)]
pos = 0
for i in range(1, n, 2):
	ans[i] = arr[pos]
	pos += 1
for i in range(0, n, 2):
	ans[i] = arr[pos]
	pos += 1
count = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		count += 1
print(count)
print(*ans)


import math
from collections import deque
from collections import defaultdict
n = int(input())
arr = list(map(int, input().strip().split(' ')))
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = (n - 1) // 2
print(ans)
arr.sort()
ap = [0] * n
i = 0
lst = n - 1
st = 0
while st <= lst:
	if i % 2 == 0:
		ap[i] = arr[lst]
		lst -= 1
	else:
		ap[i] = arr[st]
		st += 1
	i += 1
for i in ap:
	print(i, end=' ')
print()


def read_line(type=int):
	return list(map(type, input().split()))
n = int(input())
d = read_line()
d = sorted(d)[::-1]
print((n - 1) // 2)
ans = [0] * n
ans[::2] = d[:(n + 1) // 2]
ans[1::2] = d[(n + 1) // 2:]
print(*ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
arr1 = arr[0:n // 2]
arr2 = arr[n // 2:]
arr3 = []
for i in range(n // 2):
	arr3.append(arr2[i])
	arr3.append(arr1[i])
if n % 2 != 0:
	arr3.append(arr2[-1])
ans = 0
for i in range(1, n - 1):
	if arr3[i - 1] > arr3[i] and arr3[i + 1] > arr3[i]:
		ans += 1
print(ans)
print(*arr3)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
i = 0
j = n - 1
cnt = 0
l = []
while i <= j:
	l.append(a[j])
	j -= 1
	if i < j:
		l.append(a[i])
		i += 1
for i in range(1, len(l) - 1):
	if l[i] < l[i - 1] and l[i] < l[i + 1]:
		cnt += 1
print(cnt)
print(*l)


from sys import stdin, stdout
from math import ceil

def find(arr, N):
	arr.sort()
	print(ceil(N / 2) - 1)
	for i in range(ceil(N // 2)):
		print(arr[-i - 1], end=' ')
		print(arr[i], end=' ')
	if N % 2:
		print(arr[N // 2], end='')
	print()

def main():
	N = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	find(arr, N)
main()


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
n = int(input())
a = list(map(int, input().split()))[:n]
a.sort()
b = []
count = 0
j = 0
if n % 2 == 1:
	for i in range(n // 2, n):
		b.append(a[i])
		if j < n // 2:
			b.append(a[j])
			j += 1
	for i in range(1, n - 1):
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			count += 1
else:
	for i in range(n // 2, n):
		b.append(a[i])
		if j < n // 2:
			b.append(a[j])
			j += 1
	for i in range(1, n - 1):
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			count += 1
print(count)
for i in b:
	print(i, end=' ')


n = int(input())
a = sorted(map(int, input().split()))
final = []
if n % 2 == 0:
	peqs = a[:n // 2 - 1]
	grandes = a[n // 2 - 1:]
else:
	peqs = a[:n // 2]
	grandes = a[n // 2:]
print(len(peqs))
if n % 2 == 0:
	n -= 1
for i in range(n):
	if i % 2 == 0:
		final.append(grandes[0])
		del grandes[0]
	else:
		final.append(peqs[0])
		del peqs[0]
if max(a) not in final:
	final.append(max(a))
print(*final)


def resolve(a, n):
	a.sort()
	if len(a) % 2 == 0:
		maxOder = len(a) // 2 - 1
	else:
		maxOder = len(a) // 2
	print(maxOder)
	res = [0] * n
	j = 0
	for i in range(1, n, 2):
		res[i] = a[j]
		j += 1
	for i in range(0, n, 2):
		res[i] = a[j]
		j += 1
	for res_item in res:
		print(res_item, end=' ')
n = int(input())
a = list(map(int, input().split(' ')))
resolve(a, n)


from math import ceil
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
print(ceil(n / 2) - 1)
for i in range(n):
	if i % 2 == 0:
		print(lst[n - 1 - int(i / 2)], end=' ')
	else:
		print(lst[i // 2], end=' ')


import math
import sys
input = sys.stdin.readline
n = int(input())
l = sorted(list(map(int, input().split())))
i = 0
j = n // 2
p = []
while i < n // 2 and j < n:
	p.append(l[j])
	j += 1
	p.append(l[i])
	i += 1
while i < n // 2:
	p.append(l[i])
	i += 1
while j < n:
	p.append(l[j])
	j += 1
c = 0
for i in range(1, n - 1):
	if p[i] < p[i - 1] and p[i] < p[i + 1]:
		c += 1
print(c)
print(*p)


n = int(input())
a = [int(x) for x in input().split()]
print((n - 1) // 2)
a.sort()
spredu = 0
zozadu = n - 1
out = []
for i in range(n):
	if i % 2 == 0:
		out.append(a[zozadu])
		zozadu = zozadu - 1
	else:
		out.append(a[spredu])
		spredu = spredu + 1
print(*out)


import math
from collections import deque
from collections import defaultdict
n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr.sort()
ap = [0] * n
ind = 0
for i in range(1, n, 2):
	ap[i] = arr[ind]
	ind += 1
for i in range(n):
	if ap[i] == 0:
		ap[i] = arr[ind]
		ind += 1
ans = 0
for i in range(1, len(ap) - 1):
	if ap[i] < ap[i - 1] and ap[i] < ap[i + 1]:
		ans += 1
print(ans)
for i in ap:
	print(i, end=' ')
print()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr1 = arr[:n // 2]
arr2 = arr[n // 2:]
lst = [0] * n
for i in range(n // 2):
	arr2.insert(i + (i + 1), arr[i])
d = 0
for i in range(1, n - 1, 2):
	if arr2[i] < arr2[i - 1] and arr2[i] < arr2[i + 1]:
		d += 1
print(d)
print(*arr2)


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
ans = n // 2
left = 0
right = n - 1
if n % 2 == 0:
	ans -= 1
print(ans)
flag = 1
out = []
for i in range(n):
	if flag:
		out.append(nums[right])
		right -= 1
		flag = 0
	else:
		out.append(nums[left])
		left += 1
		flag = 1
print(' '.join(map(str, out)))


def ans(arr):
	arr.sort(reverse=True)
	for i in range(1, t - 1, 2):
		(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	if t % 2:
		ans = t // 2
	else:
		ans = (t - 2) // 2
	return [ans, arr]
t = int(input())
n = list(map(int, input().strip().split()))
result = ans(n)
print(result[0])
print(*result[1])


n = int(input())
data = list(map(int, input().split()))

def cal(data, n):
	data.sort()
	res = [0] * n
	m = n // 2
	res[0::2] = data[m:]
	res[1::2] = data[:m]
	ans = 0
	for i in range(1, n, 2):
		if i == n - 1:
			break
		if res[i - 1] > res[i] and res[i] < res[i + 1]:
			ans += 1
	print(ans)
	s = ' '.join(list(map(str, res)))
	print(s)
cal(data, n)


from collections import defaultdict
from queue import deque

def arrinp():
	return [*map(int, input().split(' '))]

def mulinp():
	return map(int, input().split(' '))

def intinp():
	return int(input())

def solution():
	n = intinp()
	a = arrinp()
	a.sort()
	i = 0
	j = n - 1
	arr = [a[j]]
	j -= 1
	while j > i:
		arr.append(a[i])
		i += 1
		arr.append(a[j])
		j -= 1
	if i == j:
		arr.append(a[i])
	print(i)
	print(*arr)
	return
testcases = 1
for _ in range(testcases):
	solution()


def solve(lst):
	lst = sorted(lst)
	if len(lst) < 3:
		return lst
	p = []
	for i in range(0, len(lst) - 1, 2):
		p.append(lst[i + 1])
		p.append(lst[i])
	if len(lst) % 2:
		p.append(lst[len(lst) - 1])
	return p
k = int(input())
lst = list(map(int, input().split()))
ans = solve(lst)
c = 0
for i in range(1, len(ans) - 1):
	if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
		c += 1
print(c)
f = [str(i) for i in ans]
print(' '.join(f))

class FPTree:

	def __init__(self, item=None):
		self.node = FPNode(1, item or None)

	def getNode(self):
		return self.node

	def add(self, transaction):
		temprory_mem = self.node
		for item in transaction:
			new_searched = temprory_mem.search(item)
			if new_searched:
				new_searched.increment()
			else:
				new_searched = FPNode(1, item)
				temprory_mem.add(new_searched)
			temprory_mem = new_searched

class FPNode:

	def __init__(self, count, item):
		self.children = {}
		self.item = item
		self.count = count
		self.parent = None

	def getItem(self):
		return self.item

	def getChildren(self):
		return self.children

	def add(self, child):
		if child not in self.children:
			child.parent = self
			self.children[child.item] = child
			return True
		return False

	def search(self, item):
		try:
			return self.children[item]
		except KeyError:
			return None

	def increment(self):
		self.count += 1


n = int(input())
a = [int(x) for x in input().split()]
l = 0
if n % 2 != 0:
	l = (n - 2) // 2 + 1
else:
	l = (n - 2) // 2
print(l)
b = a.copy()
c = a.copy()
b.sort()
c.sort(reverse=True)
out = list()
bi = 0
ci = 0
for i in range(n):
	if i % 2 == 0:
		print(c[ci], end=' ')
		ci += 1
	else:
		print(b[bi], end=' ')
		bi += 1


n = int(input())
x = list(map(int, input().split()))
print(int(n / 2) - int(n % 2 == 0))
o = []
half = int(n / 2)
x.sort()
for i in range(half):
	o.append(x[half + i])
	o.append(x[i])
if n % 2:
	o.append(x[-1])
print(*o)


t = int(input())
e = list(map(int, input().split()))
if len(e) % 2 == 0:
	print(len(e) // 2 - 1)
else:
	print(len(e) // 2)
e.sort()
i = 0
while i < t - 1:
	temp = e[i]
	e[i] = e[i + 1]
	e[i + 1] = temp
	i += 2
for i in range(t):
	print(e[i], end=' ')


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

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

def minp():
	return map(int, input().split())
n = inp()
res = [0 for i in range(n)]
a = linp()
a.sort()
if n & 1:
	res[-1] = a[-1]
i = 0
e = n // 2
t = 0
while i < e:
	res[t] = a[e + i]
	t += 1
	res[t] = a[i]
	t += 1
	i += 1
i = 1
c = 0
while i <= n - 2:
	if res[i - 1] > res[i]:
		if res[i + 1] > res[i]:
			c += 1
	i += 1
print(c)
print(*res)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		l.sort()
		i = 1
		while i < n:
			if l[i] > l[i - 1]:
				(l[i - 1], l[i]) = (l[i], l[i - 1])
				i += 2
			else:
				i += 1
		if n & 1 == 1:
			print(n // 2)
		else:
			print(n // 2 - 1)
		print(*l)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
a = list(map(int, input().split()))
for i in range(1, n - 1, 2):
	q = [a[i - 1], a[i], a[i + 1]]
	q.sort()
	(a[i - 1], a[i], a[i + 1]) = (q[2], q[0], q[1])
print((n - 1) // 2)
print(' '.join((str(x) for x in a)))


n = int(input())
a = sorted([int(i) for i in input().split()])
b = []
m = n // 2
for i in range(m):
	b.append(a[m + i])
	b.append(a[i])
if n % 2 == 1:
	b.append(a[-1])
ans = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		ans += 1
print(ans)
print(' '.join([str(i) for i in b]))


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	lst.sort()
	ans = []
	index = int(n / 2)
	ans.append(lst[index])
	try:
		for i in range(1, index + 1):
			ans.append(lst[index - i])
			ans.append(lst[index + i])
	except:
		pass
	if n % 2 != 0:
		print(int(n / 2))
	else:
		print(int(n / 2) - 1)
	for item in ans:
		print(item, end=' ')
	return
t = 1
while t != 0:
	solve()
	t -= 1


n = int(input())
A = list(map(int, input().split()))
if n < 3:
	print(0)
	for num in A:
		print(num, end=' ')
else:
	Max_arr = [0 for i in range(n)]
	A = sorted(A)
	Max_arr[-1] = A[-1]
	Max_arr[-2] = A[-2] if n % 2 == 0 else 0
	k = n - 1 if n % 2 != 0 else n - 2
	for i in range(k):
		if i % 2 == 0:
			Max_arr[i] = A[i + 1]
		else:
			Max_arr[i] = A[i - 1]
	print(n // 2 - 1) if n % 2 == 0 else print(n // 2)
	for num in Max_arr:
		print(num, end=' ')


n = int(input())
x = [int(w) for w in input().split()]
x = sorted(x)
i = 1
while i < n - 1:
	(x[i - 1], x[i]) = (x[i], x[i - 1])
	i += 2
print((n + 1) // 2 - 1)
print(*x)


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
t = int(input())
l = sorted(list(map(int, input().split())))
for i in range(t // 2):
	(l[i * 2], l[i * 2 + 1]) = (l[i * 2 + 1], l[i * 2])
print((t - 1) // 2)
print(*l)


n = int(input())
p = list(map(int, input().split()))
p1 = sorted(p)
ans = []
if n % 2 == 0:
	print((n - 1) // 2)
	for i in range(n // 2):
		ans.append(p1[n - i - 1])
		ans.append(p1[i])
else:
	print(n // 2)
	for i in range(n // 2 + 1):
		ans.append(p1[n - i - 1])
		ans.append(p1[i])
	ans.pop()
print(*ans)


n = int(input())
a = sorted(map(int, input().split()))
print(n // 2 - (n % 2 == 0))
l = list()
t1 = a[:n // 2]
t2 = a[n // 2:n - (n % 2 == 1)]
for i in range(n // 2):
	l.append(t2[i])
	l.append(t1[i])
if n % 2 == 1:
	l.append(a[-1])
print(*l)


n = int(input())
l = list(map(int, input().split()))
l.sort()
(p1, p2) = (0, n - 1)
ans = []
while p1 < p2:
	ans.append(l[p2])
	ans.append(l[p1])
	p2 += -1
	p1 += 1
if p1 == p2:
	ans.append(l[p1])
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt -= -1
print(cnt)
print(*ans)


t = 1
for _ in range(t):
	n = int(input())
	z = input().split()
	w = []
	for i in range(n):
		z[i] = int(z[i])
	if n == 2:
		print(0)
		print(z[0], z[1])
	else:
		z.sort()
		for i in range(n):
			w.append(z[i])
		for i in range(1, n - 1, 2):
			(z[i], z[i + 1]) = (z[i + 1], z[i])
		for i in range(0, n - 1, 2):
			(w[i], w[i + 1]) = (w[i + 1], w[i])
		a1 = 0
		a2 = 0
		for i in range(1, n - 1):
			if w[i] < w[i + 1] and w[i] < w[i - 1]:
				a1 += 1
			if z[i] < z[i + 1] and z[i] < z[i - 1]:
				a2 += 1
		if a1 >= a2:
			print(a1)
			for i in range(n):
				print(w[i], end=' ')
			print()
		else:
			print(a2)
			for i in range(n):
				print(z[i], end=' ')
			print()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = [0] * n
i = 0
j = n - 1
s = 0
lis = [0] * n
for k in range(n // 2):
	if s == 0:
		ans[k] = arr[j]
		lis[j] = 1
		j -= 1
		ans[-k - 1] = arr[j]
		lis[j] = 1
		j -= 1
		s = 1
	else:
		ans[k] = arr[i]
		lis[i] = 1
		i += 1
		ans[-k - 1] = arr[i]
		lis[i] = 1
		i += 1
		s = 0
if n % 2 == 0:
	print(n // 2 - 1)
	print(' '.join((str(x) for x in ans)))
else:
	for i in range(n):
		if lis[i] == 0:
			ans[n // 2] = arr[i]
	print(n // 2)
	print(' '.join((str(x) for x in ans)))


n = int(input())
b = list(map(int, input().split()))
b.sort(reverse=True)
a = [0] * (n + 1)
j = 0
if n % 2 == 0:
	for i in b[:n // 2]:
		a[j] = i
		j += 2
	j = 1
	for i in b[n // 2:]:
		a[j] = i
		j += 2
	print(n // 2 - 1)
	print(*a[:n], sep=' ')
else:
	for i in b[:n // 2 + 1]:
		a[j] = i
		j += 2
	j = 1
	for i in b[n // 2 + 1:]:
		a[j] = i
		j += 2
	print(n // 2)
	print(*a[:n], sep=' ')


for z in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	num = (n - 1) // 2
	l_new = [0] * n
	if num > 0:
		index = 1
		for i in range(num):
			l_new[index] = l[i]
			index += 2
		last_ind = index - 2
		num_index = num
		for i in range(0, last_ind, 2):
			l_new[i] = l[num_index]
			num_index += 1
		last_ind += 1
		if num_index <= n - 1:
			for i in range(num_index, n):
				l_new[last_ind] = l[i]
				last_ind += 1
	else:
		l_new = l[:]
	print(num)
	print(*l_new)


from sys import stdin, stdout
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
a.sort()
cnt = (n - 1) // 2
(l, r) = (0, n // 2)
ans = []
while l < n // 2:
	ans.append(a[r])
	ans.append(a[l])
	l += 1
	r += 1
if n & 1:
	ans.append(a[-1])
print(cnt)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
a = len(l) // 2
m = []
o = []
if n == 1 or n == 2:
	print(0)
	print(*l)
	exit()
for i in range(len(l)):
	if i < a:
		m.append(l[i])
	else:
		o.append(l[i])
i = 0
j = 0
k = 0
ans = []
while k < n:
	if k % 2 == 0:
		ans.append(o[j])
		j += 1
	else:
		ans.append(m[i])
		i += 1
	k += 1
if len(l) % 2 == 0:
	print((n - 1) // 2)
else:
	print(n // 2)
print(*ans)


from collections import defaultdict
n = int(input())
nums = list(map(int, input().split()))
nums = sorted(nums)
max_ans = (n - 1) // 2
if max_ans == 0:
	print(0)
	print(*nums)
else:
	bigs = nums[max_ans:]
	smalls = nums[:max_ans]
	j = 0
	s_loc = defaultdict(lambda : -1)
	for i in range(len(bigs) - 1):
		if bigs[i] > smalls[j] and bigs[i + 1] > smalls[j]:
			s_loc[i] = smalls[j]
			j += 1
		if j == max_ans:
			break
	print(j)
	for i in range(len(bigs)):
		print(bigs[i], end=' ')
		if s_loc[i] != -1:
			print(s_loc[i], end=' ')
	print(*smalls[j:])


n = int(input())
a = sorted([int(x) for x in input().split()])
m = n // 2
b = [0] * n
for i in range(n):
	if i % 2:
		b[i] = a[i // 2]
	else:
		b[i] = a[m + i // 2]
z = 0
i = 1
while i < n - 1:
	if b[i - 1] > b[i] < b[i + 1]:
		z += 1
		i += 2
	else:
		i += 1
print(z)
print(*b)


from sys import stdin
n = int(stdin.readline())
a = sorted(map(int, stdin.readline().split()))
b = []
if n % 2 == 1:
	m = (n - 1) // 2
	for i in range(m):
		b.append(a[m + i])
		b.append(a[i])
	b.append(a[n - 1])
	print(m)
	print(*b)
else:
	m = n // 2
	for i in range(m - 1):
		b.append(a[m - 1 + i])
		b.append(a[i])
	b.append(a[n - 2])
	b.append(a[n - 1])
	print(m - 1)
	print(*b)


n = int(input())
a = input().split(' ')
if n <= 2:
	print(0)
	print(' '.join(a))
	exit(0)
a = [int(s) for s in a]
a = sorted(a)
b = [0] * n
stepb = 1
for i in range(0, n):
	b[stepb] = a[i]
	stepb += 2
	if stepb >= n:
		stepb = 0
cnt = 0
for i in range(1, n - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		cnt += 1
print(cnt)
print(' '.join([str(s) for s in b]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
lo = 0
hi = (n + 1) // 2
while hi - lo > 1:
	test = (hi + lo) // 2
	smol = a[:test]
	large = a[-test - 1:]
	rest = a[test:-test - 1]
	works = True
	for i in range(test):
		if smol[i] == large[i] or smol[i] == large[i + 1]:
			works = False
	if works:
		lo = test
	else:
		hi = test
smol = a[:lo]
large = a[-lo - 1:]
rest = a[lo:-lo - 1]
o = []
while smol:
	o += [large.pop()]
	o += [smol.pop()]
o += large
o += rest
print(lo)
print(' '.join(map(str, o)))


n = int(input())
x = 0
a = list(map(int, input().split()))
a.sort()
arr = [0] * n
see = 0
while False:
	break
for j in range(1, n, 2):
	arr[j] = a[see]
	see += 1
for j in range(0, n, 2):
	arr[j] = a[see]
	while False:
		break
	see += 1
mark = 0
x = 0
for j in range(1, n - 1):
	if arr[j - 1] > arr[j] and arr[j + 1] > arr[j]:
		mark += 1
print(mark)
for j in arr:
	print(j, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
newarr = [0] * n
k = 0
for i in range(1, n, 2):
	newarr[i] = arr[k]
	k += 1
for i in range(0, n, 2):
	newarr[i] = arr[k]
	k += 1
if n <= 2:
	print(0)
else:
	ct = 0
	for i in range(1, n - 1, 2):
		if newarr[i] < newarr[i - 1] and newarr[i] < newarr[i + 1]:
			ct += 1
	print(ct)
print(*newarr)


n = int(input())
l = sorted(list(map(int, input().split())))
if n < 3:
	print(0)
	print(*l)
elif n % 2 == 0:
	print(n // 2 - 1)
	num = (n - 1) // 2
	j = 0
	for i in range(num, n):
		print(l[i], end=' ')
		if j < num:
			print(l[j], end=' ')
			j += 1
else:
	print(n // 2)
	num = (n - 1) // 2
	j = 0
	for i in range(num, n):
		print(l[i], end=' ')
		if j < num:
			print(l[j], end=' ')
			j += 1


n = int(input())
lis = [int(x) for x in input().split()]
lis = sorted(lis)
newlis = [1] * n
count = 0
j = 0
for k in range(1, n - 1, 2):
	newlis[k] = lis[j]
	j += 1
	count += 1
for k in range(0, n, 2):
	newlis[k] = lis[j]
	j += 1
if n % 2 == 0:
	newlis[n - 1] = lis[n - 1]
print(count)
print(*newlis)


from collections import Counter

def read_line():
	return list(map(int, input().split()))
n = int(input())
l = sorted(read_line())

def ok(ans):
	nums = l[:ans]
	rest = l[ans:]
	if len(rest) < ans + 1:
		return None
	rest = rest[-(ans + 1):]
	l2 = []
	for i in range(len(nums)):
		if nums[i] < rest[i] and nums[i] < rest[i + 1]:
			l2.append(rest[i])
			l2.append(nums[i])
		else:
			return None
	l2.append(rest[-1])
	r = Counter(l)
	s = Counter(l2)
	for v in r:
		k = r[v] - s[v]
		l2 += [v] * k
	return l2

def _ok(ans):
	nums = l[:ans]
	rest = l[ans:]
	if len(rest) < ans + 1:
		return None
	rest = rest[-(ans + 1):]
	for i in range(len(nums)):
		if nums[i] < rest[i] and nums[i] < rest[i + 1]:
			pass
		else:
			return None
	return 1
lo = 0
hi = n
while lo <= hi:
	mid = (lo + hi) // 2
	if _ok(mid) is not None:
		lo = mid + 1
	else:
		hi = mid - 1
a = ok(hi)
print(hi)
print(' '.join(map(str, a)))


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
from bisect import bisect_right
n = int(input())
a = lnii()
if n <= 2:
	print(0)
	print(*a)
	exit()
a_i = sorted(a)
a_d = sorted(a, reverse=True)
ans = []
for i in range(n):
	if i % 2 == 0:
		ans.append(a_d[i // 2])
	else:
		ans.append(a_i[i // 2])
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
print(*ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
a = sorted(R())
print(n - 1 >> 1)
f = 0
l = -1
for i in range(n):
	if i & 1:
		print(a[f], end=' ')
		f += 1
	else:
		print(a[l], end=' ')
		l -= 1


n = int(input())
sol = [0] * n
a = []
a[0:n] = map(int, input().split())
a.sort()
index = n - 1
index1 = 0
cc = 0
for i in range(n):
	if i % 2 > 0:
		cc += 1
		sol[i] = a[index1]
		index1 += 1
	else:
		sol[i] = a[index]
		index -= 1
if n % 2 > 0:
	cc = cc
else:
	cc = cc - 1
print(cc)
print(*sol)


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq
import re

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	n = iin()
	l = ain()
	l.sort()
	d = [0] * n
	c = 0
	for i in range(1, n, 2):
		d[i] = l[c]
		c += 1
	for i in range(0, n, 2):
		d[i] = l[c]
		c += 1
	ans = 0
	for i in range(1, n - 1, 2):
		if d[i - 1] > d[i] < d[i + 1]:
			ans += 1
	print(ans)
	print(*d)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
cheap = int(n / 2)
if n % 2 == 0:
	cheap = cheap - 1
print(cheap)
for i in range(0, int(n / 2)):
	print('{} {}'.format(lst[n - i - 1], lst[i]), end=' ')
if n & 1:
	print(lst[int(n / 2)])


n = int(input())
A = list(map(int, input().split()))
if n == 1:
	print(0)
	print(A[0])
else:
	A.sort()
	res = [0] * len(A)
	j = 0
	i = 1
	if n % 2 == 0:
		while j < n:
			res[i] = A[j]
			j += 1
			i = (i + 2) % n - (i + 2) // n
	else:
		while j < n:
			res[i] = A[j]
			j += 1
			i = (i + 2) % n
	ans = 0
	for i in range(1, n - 1, 2):
		if res[i] < res[i - 1] and res[i] < res[i + 1]:
			ans += 1
	print(ans)
	for i in range(n):
		print(res[i], end=' ')
	print()


n = int(input())
a = list(map(int, input().split()))
l = a.copy()
l.sort()
a.sort(reverse=True)
ans = []
i = 0
while len(ans) <= n:
	ans.append(a[i])
	ans.append(l[i])
	i += 1
if n % 2 == 0:
	ans.pop(n - 1)
	ans.pop(n - 2)
	print(n // 2 - 1)
	print(*ans, end=' ')
else:
	ans.pop(n - 1)
	print(n // 2)
	print(*ans, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
if n <= 2:
	print(0)
	print(*arr)
elif n == 3:
	(arr[1], arr[2]) = (arr[2], arr[1])
	print(1)
	print(*arr)
else:
	y = (n - 2) // 2
	x = n - 2 - y
	list1 = []
	list1[:] = [arr[0]] + arr[2:2 + y] + [arr[1]]
	k = 1
	for i in range(2 + y, n):
		list1.insert(k, arr[i])
		k += 2
	print(x)
	print(*list1)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
n = inn()
a = arr()
a.sort()
res = n // 2
ans = []
i = 0
j = res
while i < res and j < n:
	ans += [a[j], a[i]]
	i += 1
	j += 1
while i < res:
	ans += [a[i]]
	i += 1
while j < n:
	ans += [a[j]]
	j += 1
if n % 2 == 0:
	print(res - 1)
	print(*ans)
else:
	print(res)
	print(*ans)


n = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range(n)]
(b[1::2], b[::2]) = (a[:n // 2], a[n // 2:])
count = 0
for i in range(1, n - 1, 2):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		count += 1
print(count)
print(*b)


n = int(input())
s = sorted(map(int, input().split()))
ans = []
i = 0
j = n - 1
for _ in range(n):
	if _ % 2 == 0:
		ans.append(s[j])
		j -= 1
	else:
		ans.append(s[i])
		i += 1
res = 0
for i in range(1, n - 1):
	res += ans[i - 1] > ans[i] < ans[i + 1]
print(res)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mid = n // 2
a1 = a[:mid]
a2 = a[mid:]
if n % 2 == 0:
	print(mid - 1)
else:
	print(mid)
for i in range(mid):
	print(a2[i], a1[i], end=' ')
if n % 2 == 1:
	print(a2[-1])


n = int(input())
li = sorted(map(int, input().split()))
div = int(n / 2)
i = 0
j = div
if n % 2 == 0:
	print(div - 1)
else:
	print(div)
while j < len(li):
	if j != len(li) - 1:
		print(li[j], li[i], end=' ')
	elif n % 2 == 0:
		print(li[j], li[i])
	else:
		print(li[j])
	i += 1
	j += 1


def read_line():
	return list(map(int, input().split()))
n = int(input())
l = sorted(read_line())
ans = [0] * n
idx = 0
for i in range(1, n, 2):
	ans[i] = l[idx]
	idx += 1
for i in range(0, n, 2):
	ans[i] = l[idx]
	idx += 1
v = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]:
		v += 1
print(v)
print(' '.join(map(str, ans)))


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = 1
	for _ in range(t):
		n = int(input())
		arr = inar()
		arr.sort(reverse=True)
		count = 0
		for i in range(n):
			if i % 2 != 0:
				if i + 1 < n:
					(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		for i in range(1, n - 1):
			if arr[i - 1] > arr[i] and arr[i + 1] > arr[i]:
				count += 1
		print(count)
		print(*arr)
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()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
p = [0] * n
j = 0
if n < 3:
	print(0)
	print(*a)
	sys.exit(0)
for i in range(0, n, 2):
	p[i] = a[j]
	j += 1
bad = []
for i in range(1, n, 2):
	if i + 1 == n:
		bad.append(a[j])
		j += 1
		break
	while j < n and (p[i - 1] <= a[j] or p[i + 1] <= a[j]):
		bad.append(a[j])
		j += 1
	if j == n:
		break
	p[i] = a[j]
	j += 1
j = 0
for i in range(n):
	if p[i] == 0:
		p[i] = bad[j]
		j += 1
ans = 0
for i in range(1, n - 1):
	if p[i] < p[i - 1] and p[i] < p[i + 1]:
		ans += 1
print(ans)
print(*p)


n = int(input())
a = sorted(map(int, input().split()), reverse=True)
i = n - n // 2
order = [a[0]]
skipped = []
j = 1
while i < n:
	if len(order) % 2:
		while a[i] == a[j]:
			skipped.append(a[i])
			i += 1
			if i == n:
				break
		else:
			order.append(a[i])
			i += 1
	else:
		order.append(a[j])
		j += 1
skipped.extend(a[j:j + n - len(order) - len(skipped)])
purchases = len(order) // 2
if not skipped:
	purchases = max(purchases - 1, 0)
print(purchases)
print(*order + skipped)


def solve(n, arr):
	if n <= 2:
		print(0)
		print(*arr)
		return
	arr.sort()
	arr1 = [0]
	dic = {0: arr[0]}
	cur = 0
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			arr1.append(cur)
		else:
			cur += 1
			dic[cur] = arr[i]
			arr1.append(cur)
	if arr[-2] == 0:
		print(0)
		print(*arr)
		return
	count = [0]
	cur = 0
	for a in arr1:
		if a == cur:
			count[-1] += 1
		else:
			cur += 1
			count.append(1)
	count = count[::-1]
	suff = [0]
	for x in count:
		suff.append(suff[-1] + x)
	suff.pop()
	suff = suff[::-1]
	i = 0
	while suff[arr1[i]] >= i + 2:
		i += 1
	k = i
	res = [-1 for i in range(n)]
	for i in range(k):
		res[i * 2 + 1] = dic[arr1[i]]
	j = k
	for i in range(n):
		if res[i] == -1:
			res[i] = dic[arr1[j]]
			j += 1
	print(k)
	print(*res)
n = int(input())
arr = list(map(int, input().split()))
solve(n, arr)


from sys import stdin

def create(x):
	if 2 * x + 1 > n:
		return (False, None)
	ret = [0] * (2 * x + 1)
	cntA = n - 1
	for i in range(0, len(ret), 2):
		ret[i] = a[cntA]
		cntA -= 1
	cntB = x - 1
	for j in range(1, len(ret), 2):
		ret[j] = a[cntB]
		cntB -= 1
		if ret[j - 1] <= ret[j] or ret[j] >= ret[j + 1]:
			return (False, None)
	ret += a[x:cntA + 1]
	return (True, ret)
tt = 1
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	l = 0
	r = n
	while r - l != 1:
		mid = (l + r) // 2
		(flag, ans) = create(mid)
		if flag:
			l = mid
		else:
			r = mid
	(flag, ans) = create(l)
	print(l)
	print(*ans)


n = int(input())
tab = list(map(int, input().split()))
tab.sort()
print((len(tab) - 1) // 2)
for i in range(len(tab) // 2):
	print(tab[len(tab) // 2 + i], tab[i], sep=' ', end=' ')
if len(tab) % 2 == 1:
	print(tab[-1])


n = int(input())
l = list(map(int, input().split()))
l.sort()
b = len(l) // 2
j = 0
li = []
for i in range(b, n):
	li.append(l[i])
	if j < b:
		li.append(l[j])
	j = j + 1
if len(li) % 2 == 0:
	print(b - 1)
else:
	print(b)
for i in li:
	print(i, end=' ')


t = 1
for _ in range(t):
	n = int(input())
	l = [int(j) for j in input().split()]
	l.sort()
	(c, cnt) = (0, 0)
	k = [0] * n
	for i in range(n // 2):
		k[c] = l[n // 2 + i]
		c += 1
		k[c] = l[i]
		c += 1
	if n % 2 != 0:
		k[n - 1] = l[n - 1]
	for i in range(1, n - 1):
		if k[i - 1] > k[i] and k[i + 1] > k[i]:
			cnt += 1
	print(cnt)
	print(*k)


import math
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
a.sort()
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
(i, j) = (0, n - 1)
for k in range(n):
	if k % 2:
		b[k] = a[i]
		i += 1
	else:
		b[k] = a[j]
		j -= 1
for x in b:
	print(x, end=' ')
print()


import math
n = int(input())
li = [int(i) for i in input().split()]
li.sort()
if n <= 2:
	print(0)
	print(*li)
	exit(0)
if n & 1:
	p1 = li[:n >> 1]
	p2 = li[n >> 1:]
	aq = []
	for i in range(n):
		if i & 1:
			aq.append(p1.pop())
		else:
			aq.append(p2.pop())
	ac = 0
	for (p, i) in enumerate(aq):
		if p != 0 and p != n - 1 and (i < aq[p - 1]) and (i < aq[p + 1]):
			ac += 1
	print(ac)
	print(*aq)
else:
	p1 = li[:n >> 1]
	p2 = li[n >> 1:]
	ext = p1.pop()
	aq = []
	for i in range(n - 1):
		if i & 1:
			aq.append(p1.pop())
		else:
			aq.append(p2.pop())
	aq.append(ext)
	ac = 0
	for (p, i) in enumerate(aq):
		if p != 0 and p != n - 1 and (i < aq[p - 1]) and (i < aq[p + 1]):
			ac += 1
	print(ac)
	print(*aq)


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		n = int(R())
		a = [int(x) for x in R().split()]
		if n < 3:
			print(0)
			print(*a)
			return 0
		a.sort(reverse=True)
		cnt = 0
		s = str(a[0]) + ' '
		ind = n - (n - 1) // 2 - 1
		flg = 1
		(prev, pres) = (None, a[0])
		for i in range(1, n):
			if a[i] == 10 ** 9 + 1:
				continue
			else:
				prev = pres
				pres = a[i]
			if flg:
				if ind <= i:
					ind = i
				(l, r) = (ind + 1, n - 1)
				while l <= r:
					mid = (l + r) // 2
					if prev > a[mid] < pres:
						ind = mid
						r = mid - 1
					else:
						l = mid + 1
			if prev > a[ind] < pres and flg:
				s += str(a[ind]) + ' ' + str(pres) + ' '
				a[ind] = 10 ** 9 + 1
				cnt += 1
			else:
				flg = 0
				s += str(pres) + ' '
		ans.append(str(cnt))
		ans.append(s)
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = []
if n % 2 == 1:
	x = n // 2
	for i in range(n // 2 + 1):
		ans.append(a[n - i - 1])
		if i == n // 2:
			break
		ans.append(a[i])
else:
	x = n // 2 - 1
	for i in range(n // 2):
		ans.append(a[n - i - 1])
		ans.append(a[i])
print(x)
print(*ans)


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * n
aidx = 0
bidx = 1
while bidx < n:
	b[bidx] = a[aidx]
	aidx += 1
	bidx += 2
bidx = 0
while bidx < n:
	b[bidx] = a[aidx]
	aidx += 1
	bidx += 2
res = 0
for i in range(1, n - 1):
	if b[i - 1] > b[i] and b[i] < b[i + 1]:
		res += 1
print(res)
print(*b)


import math
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
k = math.ceil(n / 2) - 1
print(math.ceil(n / 2) - 1)
for i in range(k):
	print(a[k + i], end=' ')
	print(a[i], end=' ')
if n % 2 == 0:
	print(f'{a[-2]} {a[-1]}')
else:
	print(a[-1])


import sys
input = sys.stdin.readline
n = int(input())
lis = sorted(map(int, input().split()))
ans = 0
for i in range(0, n, 2):
	if i + 1 < n:
		(lis[i], lis[i + 1]) = (lis[i + 1], lis[i])
for i in range(1, n - 1):
	if lis[i - 1] > lis[i] and lis[i] < lis[i + 1]:
		ans += 1
print(ans)
print(*lis)


n = int(input())
ar = sorted(list(map(int, input().split())))
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
m = ans
ar1 = []
ar2 = []
j = 0
k = 0
for i in range(n):
	if n % 2 != 0:
		if m > 0:
			ar1.append(ar[i])
		else:
			ar2.append(ar[i])
		m -= 1
	else:
		if m + 1 > 0:
			ar1.append(ar[i])
		else:
			ar2.append(ar[i])
		m -= 1
print(ans)
for i in range(n):
	if i % 2 == 0:
		print(ar2[j], end=' ')
		j += 1
	else:
		print(ar1[k], end=' ')
		k += 1


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	a = []
	if (n - 2) % 2 == 0:
		print((n - 2) // 2)
	else:
		print((n - 2) // 2 + 1)
	i = 0
	j = n - 1
	flag = 0
	while i <= j:
		if flag == 0:
			flag = 1
			a.append(l[j])
			j -= 1
		else:
			flag = 0
			a.append(l[i])
			i += 1
	print(*a)
t = 1
for _ in range(t):
	solution()


def fn1(lis):
	print(0)
	print(*lis)

def fn3(arr, m):
	co = 0
	for i in range(1, m - 1, 1):
		if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			co += 1
	print(co)
	print(*arr)

def fn6(arr, m):
	co = 0
	for i in range(1, m - 1, 1):
		if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			co += 1
	print(co)
	print(*arr)

def fn4(bambai, arr, i, j1, i1):
	for k in range(i):
		arr[j1] = bambai[i1]
		i1 -= 1
		j1 -= 2
	n1 = 1
	n2 = 0
	for i in range(m // 2):
		arr[n1] = bambai[n2]
		n2 += 1
		n1 += 2
	fn6(arr, m)

def fn2(bambai, arr, i, i1, j1):
	for k in range(i):
		arr[j1] = bambai[i1]
		i1 -= 1
		j1 -= 2
	m1 = 2
	m2 = 0
	for i in range(m // 2 - 1):
		arr[m1] = bambai[m2]
		m2 += 1
		m1 += 2
	arr[0] = bambai[m2]
	fn3(arr, m)
m = int(input())
arr = [0 for i in range(m)]
bambai = list(map(int, input().split()))
if m < 3:
	fn1(bambai)
else:
	bambai.sort()
	j1 = m - 1
	if m % 2 == 0:
		i = m // 2
	else:
		i = m // 2 + 1
	v1 = 0
	i1 = m - 1
	if m % 2 == 0:
		fn2(bambai, arr, i, i1, j1)
	else:
		fn4(bambai, arr, i, j1, i1)


N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [0] * N
for i in range(1, N, 2):
	B[i] = A[i // 2]
Astart = N // 2
Bstart = N - 2 if N % 2 == 0 else N - 1
rem = []
while Astart < N and A[Astart] == B[Bstart - 1]:
	rem.append(A[Astart])
	Astart += 1
for i in range(Bstart, -1, -2):
	if Astart >= N:
		B[i] = rem.pop()
	else:
		B[i] = A[Astart]
		Astart += 1
ans = 0
for i in range(1, N - 1, 2):
	if B[i - 1] > B[i] < B[i + 1]:
		ans += 1
print(ans)
print(*B)


(size, array) = (int(input()), sorted(list(map(int, input().split()))))
a = len(array)
res = a - 1 if a % 2 == 0 else a
print(res // 2)
if not res // 2:
	print(*array)
else:
	(r, l, temp) = (a - 1, 0, [])
	for x in range(a):
		if x % 2 == 0:
			temp.append(array[r])
			r -= 1
		else:
			temp.append(array[l])
			l += 1
	print(*temp)


n = int(input())
arr = [int(el) for el in input().split()]
ans = [0] * n
arr.sort()
take = 0
count = 0
for i in range(1, n, 2):
	ans[i] = arr[count]
	count += 1
for i in range(0, n, 2):
	ans[i] = arr[count]
	count += 1
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] and ans[i + 1] > ans[i]:
		take += 1
print(take)
print(*ans)


from math import ceil, floor
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(floor(n / 2)):
	b.append(a[n - i - 1])
	b.append(a[i])
if n % 2 != 0:
	b.append(a[floor(n / 2)])
print(floor((n - 1) / 2))
for present in b:
	print(present, end=' ')


n = int(input())
ls = sorted(list(map(int, input().split())))
ar = [0] * n
i = 0
j = n - 1
k = 0
cnt = 0
while cnt < n:
	if cnt % 4 == 0:
		ar[k] = ls[j]
		j -= 1
	elif cnt % 4 == 1:
		ar[n - 1 - k] = ls[j]
		j -= 1
		k += 1
	elif cnt % 4 == 2:
		ar[k] = ls[i]
		i += 1
	else:
		ar[n - 1 - k] = ls[i]
		i += 1
		k += 1
	cnt += 1
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
print(ans)
print(*ar)


t = 1
import random
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr)
	temp = [0 for x in range(n)]
	c = n - 1
	for i in range(0, n, 2):
		temp[i] = arr[c]
		c -= 1
	c = 0
	for i in range(1, n, 2):
		temp[i] = arr[c]
		c += 1
	ans = 0
	val = n
	if n % 2 == 0:
		val -= 1
	for i in range(1, val, 2):
		if temp[i] < temp[i - 1] and temp[i] < temp[i + 1]:
			ans += 1
	temp2 = [0 for x in range(n)]
	c = 0
	for i in range(1, n, 2):
		temp2[i] = arr[c]
		c += 1
	for i in range(0, n, 2):
		temp2[i] = arr[c]
		c += 1
	ans2 = 0
	for i in range(1, val, 2):
		if temp2[i] < temp2[i - 1] and temp2[i] < temp2[i + 1]:
			ans2 += 1
	if ans2 > ans:
		print(ans2)
		print(*temp2)
	else:
		print(ans)
		print(*temp)


n = int(input())
arr = list(map(int, input().strip().split()))
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
arr.sort()
low = arr[:n // 2]
hi = arr[n // 2:]
arr[::2] = hi
arr[1::2] = low
for i in range(1, n - 1, 2):
	if arr[i] == arr[i - 1] or arr[i] == arr[i + 1]:
		ans -= 1
print(ans)
print(*arr, sep=' ')


import bisect
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = n // 2
ll = []
while j < n:
	ll.append(l[j])
	if i < n // 2:
		ll.append(l[i])
	j += 1
	i += 1
cou = 0
for i in range(1, n - 1):
	if ll[i] < ll[i - 1] and ll[i] < ll[i + 1]:
		cou += 1
print(cou)
print(*ll)


n = int(input())
a = sorted(list(map(int, input().split())))
ans = []
i = 0
j = len(a) - 1
while i <= j:
	if i != j:
		ans.append(a[j])
	ans.append(a[i])
	i += 1
	j -= 1
if n == 1:
	print(0)
	print(*ans)
	exit()
elif n == 2:
	print(0)
	print(*ans)
	exit()
elif n % 2 == 0:
	print(n // 2 - 1)
	print(*ans)
	exit()
else:
	print(n // 2)
	print(*ans)
	exit()


import sys

def multiple_input():
	return map(int, sys.stdin.readline().strip().split())

def list_input():
	return list(map(int, sys.stdin.readline().strip().split()))
n = int(input())
a = list_input()
a.sort()
ans = [0] * n
(i, j) = (1, 0)
count = 0
while i < n:
	ans[i] = a[j]
	if i == n - 1:
		count -= 1
	i += 2
	j += 1
	count += 1
i = 0
while i < n:
	ans[i] = a[j]
	i += 2
	j += 1
print(count)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = [0] * n
for i in range(n):
	nj = 2 * i + 1
	if nj >= n:
		break
	ans[nj] = a[i]
idx = 0
for j in range(i, n):
	ans[idx] = a[j]
	idx += 2
cnt = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		cnt += 1
print(cnt)
print(*ans)


def permut(b, c):
	temp = b
	b = c
	c = temp
n = int(input())
prices = []
temp = []
temp = input().split()
for i in range(n):
	prices.append(int(temp[i]))
prices.sort()
prices = prices[::-1]
ans = 0
for i in range(1, n - 1, 2):
	ans += 1
	loc = prices[i]
	prices[i] = prices[i + 1]
	prices[i + 1] = loc
print(ans)
print(*prices)


n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	print(0)
	print(*a)
	exit()
a = sorted(a, reverse=True)
order = [0, 2, 1]
current = 2
while len(order) < n - 1:
	order.append(current + 2)
	order.append(current + 1)
	current += 2
if len(order) < n:
	order.append(n - 1)
new = [a[i] for i in order[:n]]
print((n - 1) // 2)
print(*new)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	if n <= 2:
		print(0)
		print(*arr)
		return
	arr.sort(reverse=True)
	i = 2
	while i < n:
		temp = arr[i]
		arr[i] = arr[i - 1]
		arr[i - 1] = temp
		i += 2
	print((n - 1) // 2)
	print(*arr)
solve()


def factorial(n):
	lst = [1]
	p = 1
	for i in range(1, n + 1):
		lst.append(i * lst[i - 1])
	return lst
n = int(input())
l = [int(j) for j in input().split()]
(c, cnt) = (0, 0)
k = [0] * n
l.sort()
if n % 2 != 0:
	k[n - 1] = l[n - 1]
for i in range(n // 2):
	k[c] = l[n // 2 + i]
	c += 1
	k[c] = l[i]
	c += 1
for i in range(1, n - 1):
	if k[i - 1] > k[i] and k[i + 1] > k[i]:
		cnt += 1
print(cnt)
print(*k)


n = int(input())
l = list(map(int, input().split()))
l.sort()
temp = []
p = n // 2
j = 0
for i in range(p, n):
	temp.append(l[i])
	if j < p:
		temp.append(l[j])
		j = j + 1
ans = 0
for i in range(1, n - 1):
	if temp[i] < temp[i + 1] and temp[i] < temp[i - 1]:
		ans = ans + 1
print(ans)
for i in range(len(temp)):
	print(temp[i], end=' ')


n = int(input())
arr = sorted(map(int, input().split()))
if n < 3:
	print(0)
	print(*arr)
else:
	ans = []
	half = n // 2
	for (i, j) in zip(arr[:half], arr[half:]):
		ans.append(j)
		ans.append(i)
	if n % 2 != 0:
		ans.append(arr[-1])
	print((n - 1) // 2)
	print(*ans)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = [0] * n
ans1 = [0] * n
j = 0
for i in range(n):
	if i % 2 != 0:
		ans[i] = l[j]
		ans1[i] = l[j]
		j += 1
j = n - 1
for i in range(0, n, 2):
	ans[i] = l[j]
	j -= 1
c = 0
for i in range(1, n - 1):
	if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]:
		c += 1
c2 = 0
j = n - 1
for i in range(n - 1, -1, -1):
	if i % 2 == 0:
		ans1[i] = l[j]
		j -= 1
for i in range(1, n - 1):
	if ans1[i] < ans1[i - 1] and ans1[i] < ans1[i + 1]:
		c2 += 1
if c > c2:
	print(c)
	print(*ans)
else:
	print(c2)
	print(*ans1)


from math import ceil
x = int(input())
s = sorted(list(map(int, input().split())))
res = []
a = 0
b = x - 1
while a < b:
	res.append(s[b])
	res.append(s[a])
	a += 1
	b -= 1
if a == b:
	res.append(s[a])
print(ceil(x / 2) - 1)
print(*res)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n < 3:
	print(0)
	for x in arr:
		print(x, end=' ')
	print()
else:
	temp = list((1 for i in range(n)))
	j = 0
	for i in range(1, n, 2):
		temp[i] = arr[j]
		j += 1
	for i in range(0, n, 2):
		temp[i] = arr[j]
		j += 1
		count = 0
	for i in range(1, n, 2):
		if i == n - 1:
			break
		if temp[i] < temp[i + 1] and temp[i] < temp[i - 1]:
			count += 1
	print(count)
	for i in temp:
		print(i, end=' ')
	print()


from collections import Counter
import string
import math
import sys

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))
mod = 100000007
n = vary(1)
num = array_int()
num.sort()
ans = 0
if n % 2 == 0:
	ans = n // 2 - 1
else:
	ans = n // 2
print(ans)
for i in range(0, n - 1, 2):
	(num[i], num[i + 1]) = (num[i + 1], num[i])
print(*num)


import sys
import math
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
arr = [0] * n
a.sort()
ind = 0
for h in range(1, n, 2):
	arr[h] = str(a[ind])
	ind += 1
for p in range(0, n, 2):
	arr[p] = str(a[ind])
	ind += 1
print(math.ceil(n / 2) - 1)
print(' '.join(arr))


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
l = [0] * n
n1 = n
p = 0
for j in range(1, n, 2):
	l[j] = a[p]
	p += 1
if n & 1 == 0:
	n -= 1
p = 1
for j in range(n - 1, -1, -2):
	l[j] = a[-p]
	p += 1
for j in range(1, n1, 2):
	if j != n1 - 1 and l[j] < l[j + 1] and (l[j] < l[j - 1]):
		ans += 1
print(ans)
print(*l)


n = int(input())
arr = sorted(list(map(int, input().split())), reverse=True)
t = n - (n - 1) // 2
ans = [0 for _ in range(n)]
for i in range(t):
	x = i * 2
	if x == n:
		x -= 1
	ans[x] = arr[i]
cur = 1
cur2 = n - 2
if n % 2 == 0:
	cur2 -= 1
for i in range(t, n):
	if ans[cur - 1] > arr[i] < ans[cur + 1]:
		ans[cur] = arr[i]
		cur += 2
	else:
		ans[cur2] = arr[i]
		cur2 -= 2
answer = sum((ans[i - 1] > ans[i] < ans[i + 1] for i in range(1, n - 1)))
print(answer)
print(*ans)


def solve(n, ar):
	ar = sorted(ar)
	l = 0
	r = n + 1
	while r - l > 1:
		m = (r + l) // 2
		f = True
		if 2 * m + 1 > n:
			f = False
		else:
			b = []
			pos_a = 0
			pos_b = n - (m + 1)
			for i in range(2 * m + 1):
				if i % 2 == 0:
					b.append(ar[pos_b])
					pos_b += 1
				else:
					b.append(ar[pos_a])
					pos_a += 1
			for i in range(1, 2 * m + 1, 2):
				if b[i - 1] <= b[i] or b[i + 1] <= b[i]:
					f = False
		if f:
			l = m
		else:
			r = m
	print(l)
	pos_a = 0
	pos_b = n - (l + 1)
	b = []
	for i in range(2 * l + 1):
		if i % 2 == 0:
			b.append(ar[pos_b])
			pos_b += 1
		else:
			b.append(ar[pos_a])
			pos_a += 1
	for i in range(pos_a, n - (l + 1)):
		b.append(ar[i])
	print(' '.join(map(str, b)))
n = int(input())
ar = list(map(int, input().split()))
solve(n, ar)


from sys import stdin
input = stdin.readline
n = int(input())
a = [(i, int(x)) for (i, x) in enumerate(input().split(), start=1)]
a.sort(key=lambda x: x[1])
r = [0] * n
for i in range(n):
	if i % 2 == 0:
		r[i] = a[n - 1 - i // 2][1]
	else:
		r[i] = a[i // 2][1]
print((n - 1) // 2)
print(*r)


from math import ceil
n = int(input())
a = list(map(int, input().split()))
print(ceil(n / 2) - 1)
a.sort()
i = 1
cur = 0
res = [0 for i in range(n)]
while i < len(a):
	res[i] = a[cur]
	i += 2
	cur += 1
i = 0
while i < len(a):
	res[i] = a[cur]
	cur += 1
	i += 2
print(' '.join([str(x) for x in res]))


n = int(input())
temp_arr = list(map(int, input().split()))
arr = list(set(temp_arr))
n = len(arr)
if n >= 3:
	ele = (n - 1) // 2
	arr.sort()
	poped = arr[0:ele]
	arr = arr[ele:]
	print(ele)
	for j in range(n - ele):
		print(arr[j], end=' ')
		if j < ele:
			print(poped[j], end=' ')
else:
	print(0)
	for i in temp_arr:
		print(i, end=' ')


ks = int(input())
cs = [int(i) for i in input().split()]
cs.sort(reverse=True)
otv = 0
for i in range(1, ks - 1, 2):
	s = cs[i]
	cs[i] = cs[i + 1]
	cs[i + 1] = s
	otv = otv + 1
print(otv)
print(' '.join(map(str, cs)))


n = int(input())
lis = sorted(map(int, input().split()))
ans = [0] * n
i = j = n - 1
while j >= 0 and i >= 0:
	ans[j] = lis[i]
	i -= 1
	j -= 2
j = n - 2
tmp = []
while j > 0 and i >= 0:
	while j > 0 and i >= 0 and (ans[j + 1] == lis[i] or ans[j - 1] == lis[i]):
		tmp.append(lis[i])
		i -= 1
	if i >= 0:
		ans[j] = lis[i]
		i -= 1
		j -= 2
j = 0
while i >= 0:
	tmp.append(lis[i])
	i -= 1
for i in range(n):
	if ans[i] == 0:
		ans[i] = tmp[j]
		j += 1
tmp = 0
for i in range(1, n - 1):
	if ans[i - 1] > ans[i] < ans[i + 1]:
		tmp += 1
print(tmp)
print(*ans)


from sys import stdin
from math import ceil, gcd
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.sort()
(i, j) = (0, n - 1)
ans = []
while i < j:
	ans.append(arr[j])
	ans.append(arr[i])
	j -= 1
	i += 1
if i == j:
	ans.append(arr[i])
print((n - 1) // 2)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[:n // 2]
c = a[n // 2:]
A = []
for i in c:
	A.append(i)
index = 1
indB = 0
while index < n:
	A.insert(index, b[indB])
	indB += 1
	index += 2
index = 1
ans = 0
while index < len(A) - 1:
	if A[index - 1] > A[index] < A[index + 1]:
		ans += 1
	index += 2
print(ans)
answer = ''
for i in A:
	answer += str(i) + ' '
print(answer)


def solve(n, A):
	A.sort()
	print((n - 1) // 2)
	v = [0] * n
	j = 0
	for i in range(1, n, 2):
		v[i] = A[j]
		j += 1
	for i in range(0, n, 2):
		v[i] = A[j]
		j += 1
	return v
res = []
n = int(input())
in_ = map(int, input().split(' '))
for c in in_:
	res.append(int(c))
print(*solve(n, res))


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
k = (n - 1) // 2
if n < 3:
	print(0)
	print(' '.join((str(i) for i in a)))
else:
	print(k)
	for i in range(k):
		print(a[k + i], a[i], end=' ')
	if n % 2 == 1:
		print(a[n - 1])
	else:
		print(a[n - 2], a[n - 1])


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n & 1:
	print(n // 2)
else:
	print(n // 2 - 1)
p = 0
q = n - 1
for j in range(n):
	if j & 1:
		print(a[p], end=' ')
		p += 1
	else:
		print(a[q], end=' ')
		q -= 1


n = int(input())
li = list(map(int, input().split()))
li.sort()
n1 = int(n / 2)
res = []
i = 0
q = n1
p = 0
while i < n:
	if q < n:
		res.append(li[q])
		i += 1
		q = q + 1
	if p < n1:
		res.append(li[p])
		p = p + 1
		i = i + 1
		pass
	pass
i = 1
ans = 0
while i < n - 1:
	if res[i - 1] > res[i] and res[i] < res[i + 1]:
		ans += 1
	i += 1
print(ans)
i = 0
while i < n:
	print(res[i], end=' ')
	i += 1
print()


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
if n % 2 != 0:
	k = n // 2
	for i in range(1, n - 2, 2):
		(a[i], a[i + 2]) = (a[i + 2], a[i])
	(a[n - 2], a[n - 1]) = (a[n - 1], a[n - 2])
	print(k)
	for i in a:
		print(i, end=' ')
else:
	k = n // 2 - 1
	for i in range(1, n - 2, 2):
		(a[i], a[i + 2]) = (a[i + 2], a[i])
	print(k)
	for i in a:
		print(i, end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
resultArr = [-1] * n
arr.sort()
result = 0
c = 0
for i in range(1, n, 2):
	resultArr[i] = arr[c]
	c += 1
for i in range(0, n, 2):
	resultArr[i] = arr[c]
	c += 1
for i in range(1, n - 1):
	if resultArr[i - 1] > resultArr[i] and resultArr[i + 1] > resultArr[i]:
		result += 1
print(result)
print(*resultArr)


n = int(input())
seq = sorted(list(map(int, input().split())))
if n % 2 == 1:
	print(n // 2)
elif n % 2 == 0:
	print(n // 2 - 1)
lst = list()
for i in range(n // 2):
	lst.append(seq[i])
seq.sort(reverse=True)
j = 0
k = 0
for i in range(n):
	if i % 2 == 0:
		print(seq[k], end=' ')
		k += 1
	if i % 2 == 1:
		print(lst[j], end=' ')
		j += 1


import sys

def input():
	return sys.stdin.readline()[:-1]

def getInt():
	return int(input())

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

def getIntList():
	return list(getIntIter())

def flush():
	sys.stdout.flush()
n = getInt()
nums = getIntList()
nums.sort()
print((len(nums) - 1) // 2)
mid = len(nums) // 2
for x in range(len(nums)):
	if x % 2 == 0:
		print(nums[mid + x // 2], end=' ')
	else:
		print(nums[x // 2], end=' ')
print()


import bisect
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
i = 0
j = n // 2
while j < n:
	print(l[j], end=' ')
	if i < n // 2:
		print(l[i], end=' ')
	j += 1
	i += 1


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
f = a[n // 2:][::-1]
s = a[:n // 2][::-1]
t = []
while f and s:
	t.append(f.pop())
	t.append(s.pop())
if f:
	t.append(f.pop())
if s:
	t.append(s.pop())
if n % 2:
	print(n // 2)
else:
	print(n // 2 - 1)
print(*t)


n = int(input())
l = list(map(int, input().strip().split(' ')))
l = sorted(l)
ans = [-1] * len(l)
if n < 3:
	print(0)
	for i in range(len(l)):
		print(l[i], end=' ')
elif n % 2 == 0:
	count = int(n / 2) - 1
	i = int(n / 2)
	for j in range(len(l)):
		if j % 2 == 0:
			ans[j] = l[i]
			i += 1
	i = int(n / 2) - 1
	for j in range(len(l)):
		if j % 2 != 0:
			ans[j] = l[i]
			i -= 1
	print(count)
	for j in range(len(ans)):
		print(ans[j], end=' ')
else:
	count = int(n / 2)
	i = int(n / 2)
	for j in range(len(l)):
		if j % 2 == 0:
			ans[j] = l[i]
			i += 1
	i = int(n / 2) - 1
	for j in range(len(l)):
		if j % 2 != 0:
			ans[j] = l[i]
			i -= 1
	print(count)
	for j in range(len(ans)):
		print(ans[j], end=' ')


def main():
	number = int(input())
	if number < 3:
		if number == 1:
			a = int(input())
			print(0)
			print(a)
		elif number == 2:
			(a, b) = input().split()
			a = int(a)
			b = int(b)
			print(0)
			print(a, b)
	else:
		initial = list(map(int, input().split()))
		initial.sort()
		maxp = (number - 1) // 2
		final = []
		print(maxp)
		low = initial[:maxp]
		high = initial[maxp:]
		for i in range(maxp):
			final.append(high.pop(0))
			final.append(low.pop(0))
		for item in high:
			final.append(item)
		print(*final)
main()


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
ans = []
left = 0
right = n - 1
side = True
while prices[left] <= prices[right] and right >= 0 and (left < n):
	if side:
		ans.append(prices[right])
		right -= 1
		side = not side
	else:
		ans.append(prices[left])
		left += 1
		side = not side
if n % 2 == 0:
	print(n // 2 - 1)
else:
	print(n // 2)
for x in ans:
	print(x, end=' ')


import sys

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))
tc = 1
while tc:
	tc -= 1
	n = int(input())
	ls = ints()
	print((n - 1) // 2)
	ls.sort()
	for i in range(1, n // 2 + 1):
		print(ls[-i], ls[i - 1], end=' ')
	if n % 2 != 0:
		print(ls[n // 2], end='')
	print()


def chp(k):
	if k % 2 == 0:
		c = k // 2 - 1
	else:
		c = k // 2
	return c
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = chp(n)
print(c)
c = c - 1
d = c
i = len(a) - 1
e = ''
while i > d:
	print(a[i], end=' ')
	if c >= 0:
		print(a[c], end=' ')
	i = i - 1
	c = c - 1
print(e)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = []
(s, e) = (0, n - 1)
t = 0
while t < n:
	ans.append(a[e])
	e -= 1
	t += 1
	if t < n and s != e:
		ans.append(a[s])
		s += 1
		t += 1
print((n - 1) // 2)
print(*ans)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = li()
	a.sort()
	b = []
	(i, j) = (0, n // 2)
	ans = 0
	for k in range(n):
		if k % 2 == 0:
			b.append(a[j])
			j += 1
		else:
			b.append(a[i])
			i += 1
	for i in range(1, n - 1):
		if b[i] < b[i - 1] and b[i] < b[i + 1]:
			ans += 1
	print(ans)
	print(*b)
for _ in range(1):
	solve()


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)

def gs(fr=None):
	return map_type_to_fr(str, fr)[0]
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '4\n1 2 3 4\n'.split('\n')

def my_r(x):
	c = ceil(x)
	if c - x > 0.5:
		return floor(x)
	return c
n = i2i()
a = sorted(mis())
if n <= 2:
	print(0)
	print(*a)
	exit()
ans = [a[-1]] + [None for _ in range(n - 1)]
first_half_last_idx = ceil(n / 2 - 1)
for i in range(first_half_last_idx):
	ans[2 * i + 1] = a[i]
	ans[2 * (i + 1)] = a[-i - 2]
print(first_half_last_idx)
if ans[-1] is None:
	ans[-1] = a[first_half_last_idx]
print(*ans)


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
A.sort(reverse=True)
Ans = [None] * N
for i in range(-(-N // 2)):
	Ans[2 * i] = A[i]
for i in range(N + -N // 2):
	Ans[2 * i + 1] = A[i - -N // 2]
print((N - 1) // 2)
print(*Ans)