n=int(input())
a=[int(input()) for _ in range(n)]
b=max(a)
c=a.count(b)
if c>1:
  for i in range(n):
    print(b)
else:
  d=sorted(a, reverse=True)
  e=d[1]
  f=0
  h=0
  while f!=b:
    g=a[h]
    if f<g:
      f=g
    h=h+1
  print(h)
  for i in range(h-1):
    print(b)
  print(e)
  for i in range(n-h):
    print(b)
    