def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1]

def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A

def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c)

c = -int(input())


solver()

 def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1] merge T=[] T [] for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
   l L[::-1] L ::-1 -1 while R and R[-1] > l:
      T += [R.pop()]
     R and R[-1] > l R R[-1] > l R[-1] R -1 l T += [R.pop()] T [R.pop()] R.pop() R.pop R pop T += [l] T [l] l return R+T[::-1] R+T[::-1] R T[::-1] T ::-1 -1 L L R R def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A mergesort l = len(A) l len(A) len A global c c += l c l s = l // 2 s l // 2 l 2 return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A l > 1 l 1 merge(mergesort(A[:s]),mergesort(A[s:])) merge mergesort(A[:s]) mergesort A[:s] A :s s mergesort(A[s:]) mergesort A[s:] A s: s A A A def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c) solver print(*mergesort(list(map(int,input().split())))) print *mergesort(list(map(int,input().split()))) mergesort(list(map(int,input().split()))) mergesort list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split print(c) print c c = -int(input()) c -int(input()) int(input()) int input() input solver() solver c = -int(input()) -int(input()) c def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1] def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1] merge def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c) def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c) solver def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A mergesort
def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1]

def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A

def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c)

c = -int(input())


solver()


