cnt=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 cnt
        cnt+=1
        if(l[i] <= r[j]):
            a[k] = l[i]
            i+=1
        else:
            a[k]=r[j]
            j+=1
 
def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
 
n=int(input())
s=input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(cnt)
     cnt=0 cnt 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 cnt
        cnt+=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 cnt
        cnt+=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 cnt cnt+=1 cnt 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 merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
  merge_sort if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
  left+1<right left+1 left 1 right mid=(left+right)//2 mid (left+right)//2 left+right left right 2 merge_sort(a,left,mid) merge_sort a left mid merge_sort(a,mid,right) merge_sort a mid right merge(a,left,mid,right) merge a left mid right a a left left right right n=int(input()) n int(input()) int input() input s=input() s input() input a=list(map(int,s.split())) a list(map(int,s.split())) list map(int,s.split()) map int s.split() s.split s split merge_sort(a,0,n) merge_sort a 0 n a=map(str,a) a map(str,a) map str a print(" ".join(list(a))) print " ".join(list(a)) " ".join " " join list(a) list a print(cnt) print cnt cnt=0 0 cnt 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 cnt
        cnt+=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 cnt
        cnt+=1
        if(l[i] <= r[j]):
            a[k] = l[i]
            i+=1
        else:
            a[k]=r[j]
            j+=1
  merge a=map(str,a) map(str,a) a n=int(input()) int(input()) n def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
  def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
  merge_sort s=input() input() s a=list(map(int,s.split())) list(map(int,s.split())) a
cnt=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 cnt
        cnt+=1
        if(l[i] <= r[j]):
            a[k] = l[i]
            i+=1
        else:
            a[k]=r[j]
            j+=1
 
def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
 
n=int(input())
s=input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(cnt)
    
