import math
N=10**9 + 1
n=int(input())
a=list(map(int,input().split()))

def merge(a,left,mid,right):
    global cnt
    n=mid-left
    m=right-mid
    l=a[left:left + n]
    o=a[mid:mid + m]
    l.append(N)
    o.append(N)
    i=0
    j=0
    for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1

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





cnt=0
mergesort(a,0,len(a))
print(*a)
print(cnt)
 import math math N=10**9 + 1 N 10**9 + 1 10**9 10 9 1 n=int(input()) n int(input()) int input() input a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def merge(a,left,mid,right):
    global cnt
    n=mid-left
    m=right-mid
    l=a[left:left + n]
    o=a[mid:mid + m]
    l.append(N)
    o.append(N)
    i=0
    j=0
    for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1 merge global cnt n=mid-left n mid-left mid left m=right-mid m right-mid right mid l=a[left:left + n] l a[left:left + n] a left:left + n left left + n left n o=a[mid:mid + m] o a[mid:mid + m] a mid:mid + m mid mid + m mid m l.append(N) l.append l append N o.append(N) o.append o append N i=0 i 0 j=0 j 0 for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1 k range(left,right) range left right cnt+=1 cnt 1 if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1 l[i]<=o[j] l[i] l i o[j] o j a[k]=l[i] a[k] a k l[i] l i i+=1 i 1 a[k]=o[j] a[k] a k o[j] o j j+=1 j 1 a a left left mid mid right right def mergesort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        mergesort(a,left,mid)
        mergesort(a,mid,right)
        merge(a,left,mid,right) mergesort if left+1<right:
        mid=(left+right)//2
        mergesort(a,left,mid)
        mergesort(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 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 cnt=0 cnt 0 mergesort(a,0,len(a)) mergesort a 0 len(a) len a print(*a) print *a a print(cnt) print cnt a=list(map(int,input().split())) list(map(int,input().split())) a def merge(a,left,mid,right):
    global cnt
    n=mid-left
    m=right-mid
    l=a[left:left + n]
    o=a[mid:mid + m]
    l.append(N)
    o.append(N)
    i=0
    j=0
    for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1 def merge(a,left,mid,right):
    global cnt
    n=mid-left
    m=right-mid
    l=a[left:left + n]
    o=a[mid:mid + m]
    l.append(N)
    o.append(N)
    i=0
    j=0
    for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1 merge N=10**9 + 1 10**9 + 1 N cnt=0 0 cnt n=int(input()) int(input()) n def mergesort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        mergesort(a,left,mid)
        mergesort(a,mid,right)
        merge(a,left,mid,right) def mergesort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        mergesort(a,left,mid)
        mergesort(a,mid,right)
        merge(a,left,mid,right) mergesort
import math
N=10**9 + 1
n=int(input())
a=list(map(int,input().split()))

def merge(a,left,mid,right):
    global cnt
    n=mid-left
    m=right-mid
    l=a[left:left + n]
    o=a[mid:mid + m]
    l.append(N)
    o.append(N)
    i=0
    j=0
    for k in range(left,right):
        cnt+=1
        if l[i]<=o[j]:
            a[k]=l[i]
            i+=1
        else:
            a[k]=o[j]
            j+=1

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





cnt=0
mergesort(a,0,len(a))
print(*a)
print(cnt)

