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. # print(lst)
  32. lo=0
  33. hi=n
  34.  
  35. ans=lo
  36. while lo<=hi:
  37. mid=(lo+hi)//2
  38. if f(mid)[0]:
  39. ans=mid
  40. lo=mid+1
  41. else:
  42. hi=mid-1
  43. print(ans)
  44. if ans==0:
  45. print(*lst)
  46. continue
  47. print(*f(ans)[1])
  48.  
  49.  
  50.  
Success #stdin #stdout 0.09s 14180KB
stdin
3
3 1 4 2 4 2 5 
stdout
3
3 1 4 2 4 2 5