def m(S, left, mid, right):
  global count
  L = S[left:mid]
  R = S[mid:right]
  L.append(1000000000)
  R.append(1000000000)
  i = 0
  j = 0
  for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1

def ms(S,left,right):
  if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right)

n = int(input())
S = [int(x) for x in input().split()]
left = 0
right = n
count = 0

ms(S,left,right)

for i in range(n):
  if i != (n-1):
    print(S[i], end = " ")
  else:
    print(S[i])
print(count)
 def m(S, left, mid, right):
  global count
  L = S[left:mid]
  R = S[mid:right]
  L.append(1000000000)
  R.append(1000000000)
  i = 0
  j = 0
  for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1 m global count L = S[left:mid] L S[left:mid] S left:mid left mid R = S[mid:right] R S[mid:right] S mid:right mid right L.append(1000000000) L.append L append 1000000000 R.append(1000000000) R.append R append 1000000000 i = 0 i 0 j = 0 j 0 for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1 k range(left,right) range left right count = count + 1 count count + 1 count 1 if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1 L[i] <= R[j] L[i] L i R[j] R j S[k] = L[i] S[k] S k L[i] L i i = i + 1 i i + 1 i 1 S[k] = R[j] S[k] S k R[j] R j j = j + 1 j j + 1 j 1 S S left left mid mid right right def ms(S,left,right):
  if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right) ms if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right) (left+1) < right left+1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 ms(S, left, mid) ms S left mid ms(S, mid, right) ms S mid right m(S, left, mid, right) m S left mid right S S left left right right n = int(input()) n int(input()) int input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x S = [int(x) for x in input().split()] S [int(x) for x in input().split()] left = 0 left 0 right = n right n count = 0 count 0 ms(S,left,right) ms S left right for i in range(n):
  if i != (n-1):
    print(S[i], end = " ")
  else:
    print(S[i]) i range(n) range n if i != (n-1):
    print(S[i], end = " ")
  else:
    print(S[i]) i != (n-1) i n-1 n 1 print(S[i], end = " ") print S[i] S i end = " " end " " print(S[i]) print S[i] S i print(count) print count S = [int(x) for x in input().split()] [int(x) for x in input().split()] S right = n n right def m(S, left, mid, right):
  global count
  L = S[left:mid]
  R = S[mid:right]
  L.append(1000000000)
  R.append(1000000000)
  i = 0
  j = 0
  for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1 def m(S, left, mid, right):
  global count
  L = S[left:mid]
  R = S[mid:right]
  L.append(1000000000)
  R.append(1000000000)
  i = 0
  j = 0
  for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1 m count = 0 0 count def ms(S,left,right):
  if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right) def ms(S,left,right):
  if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right) ms n = int(input()) int(input()) n left = 0 0 left
def m(S, left, mid, right):
  global count
  L = S[left:mid]
  R = S[mid:right]
  L.append(1000000000)
  R.append(1000000000)
  i = 0
  j = 0
  for k in range(left,right):
    count = count + 1
    if L[i] <= R[j]:
      S[k] = L[i]
      i = i + 1
    else:
      S[k] = R[j]
      j = j + 1

def ms(S,left,right):
  if (left+1) < right:
    mid = (left+right)//2
    ms(S, left, mid)
    ms(S, mid, right)
    m(S, left, mid, right)

n = int(input())
S = [int(x) for x in input().split()]
left = 0
right = n
count = 0

ms(S,left,right)

for i in range(n):
  if i != (n-1):
    print(S[i], end = " ")
  else:
    print(S[i])
print(count)

