fork download
  1. import math
  2. def ip():
  3. return map(int,input().split())
  4.  
  5.  
  6. def f(x):
  7. t1=lst[:x]
  8. t2=lst[x:]
  9. if not t2:
  10. return False,[]
  11. i=0
  12. j=0
  13.  
  14. res=[]
  15. res.append(t2[0])
  16. j+=1
  17. for i in range(len(t1)):
  18. res.append(t1[i])
  19. if j<len(t2):
  20. res.append(t2[j])
  21. j+=1
  22. else:
  23. return False,[]
  24. return True,res
  25. # T=int(input())
  26. T=1
  27. for __ in range(T):
  28. n=int(input())
  29. lst=list(ip())
  30. lst.sort()
  31. lo=0
  32. hi=n
  33.  
  34. ans=lo
  35. while lo<=hi:
  36. mid=(lo+hi)//2
  37. if f(mid)[0]:
  38. ans=mid
  39. lo=mid+1
  40. else:
  41. hi=mid-1
  42. print(ans)
  43. print(*f(ans)[1])
  44.  
  45.  
  46.  
Success #stdin #stdout 0.11s 14160KB
stdin
7
1 3 2 2 4 5 4
stdout
3
3 1 4 2 4 2 5