import sys,collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = 0
def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1

def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right)

mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(c) import sys,collections sys collections n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline a = list(map(int,sys.stdin.readline().split())) a list(map(int,sys.stdin.readline().split())) list map(int,sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split c = 0 c 0 def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1 merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = a[left:mid] L a[left:mid] a left:mid left mid R = a[mid:right] R a[mid:right] a mid:right mid right L.append(float("inf")) L.append L append float("inf") float "inf" R.append(float("inf")) R.append R append float("inf") float "inf" i = 0 i 0 j = 0 j 0 for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1 k range(left,right) range left right global c c += 1 c 1 if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1 L[i] <= R[j] L[i] L i R[j] R j a[k] = L[i] a[k] a k L[i] L i i += 1 i 1 a[k] = R[j] a[k] a k R[j] R j j += 1 j 1 a a left left mid mid right right def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right) mergeSort if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right) 1 < right - left 1 right - left right left mid = (left+right)//2 mid (left+right)//2 left+right left right 2 mergeSort(a,left,mid) mergeSort a left mid mergeSort(a,mid,right) mergeSort a mid right merge(a,left,mid,right) merge a left mid right a a left left right right mergeSort(a,0,n) mergeSort a 0 n print(" ".join(map(str,a))) print " ".join(map(str,a)) " ".join " " join map(str,a) map str a print(c) print c n = int(sys.stdin.readline()) int(sys.stdin.readline()) n def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right) def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right) mergeSort c = 0 0 c def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1 def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1 merge a = list(map(int,sys.stdin.readline().split())) list(map(int,sys.stdin.readline().split())) a
import sys,collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = 0
def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1

def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right)

mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(c)
