def merge(a, l, m, r):
  global count
  Left = a[l:m]
  Left.append(1e10)
  Right = a[m:r]
  Right.append(1e10)
  i, j = 0, 0
  for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1

def sort(a, l, r):
  if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
       
count=0
n=int(input())
a=[int(i) for i in input().split()]
sort(a, 0, n)
print(*a)
print(count) def merge(a, l, m, r):
  global count
  Left = a[l:m]
  Left.append(1e10)
  Right = a[m:r]
  Right.append(1e10)
  i, j = 0, 0
  for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1 merge global count Left = a[l:m] Left a[l:m] a l:m l m Left.append(1e10) Left.append Left append 1e10 Right = a[m:r] Right a[m:r] a m:r m r Right.append(1e10) Right.append Right append 1e10 i, j = 0, 0 i 0 j 0 for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1 k range(l, r) range l r count += 1 count 1 if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1 Left[i] <= Right[j] Left[i] Left i Right[j] Right j a[k] = Left[i] a[k] a k Left[i] Left i i += 1 i 1 a[k] = Right[j] a[k] a k Right[j] Right j j += 1 j 1 a a l l m m r r def sort(a, l, r):
  if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
        sort if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
        r-l > 1 r-l r l 1 m = (l+r)//2 m (l+r)//2 l+r l r 2 sort(a, l, m) sort a l m sort(a, m, r) sort a m r merge(a, l, m, r) merge a l m r a a l l r r count=0 count 0 n=int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a=[int(i) for i in input().split()] a [int(i) for i in input().split()] sort(a, 0, n) sort a 0 n print(*a) print *a a print(count) print count n=int(input()) int(input()) n a=[int(i) for i in input().split()] [int(i) for i in input().split()] a def merge(a, l, m, r):
  global count
  Left = a[l:m]
  Left.append(1e10)
  Right = a[m:r]
  Right.append(1e10)
  i, j = 0, 0
  for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1 def merge(a, l, m, r):
  global count
  Left = a[l:m]
  Left.append(1e10)
  Right = a[m:r]
  Right.append(1e10)
  i, j = 0, 0
  for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1 merge count=0 0 count def sort(a, l, r):
  if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
        def sort(a, l, r):
  if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
        sort
def merge(a, l, m, r):
  global count
  Left = a[l:m]
  Left.append(1e10)
  Right = a[m:r]
  Right.append(1e10)
  i, j = 0, 0
  for k in range(l, r):
    count += 1
    if Left[i] <= Right[j]:
      a[k] = Left[i]
      i += 1
    else:
      a[k] = Right[j]
      j += 1

def sort(a, l, r):
  if r-l > 1:
    m = (l+r)//2
    sort(a, l, m)
    sort(a, m, r)
    merge(a, l, m, r)
       
       
count=0
n=int(input())
a=[int(i) for i in input().split()]
sort(a, 0, n)
print(*a)
print(count)
