m=0
def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left]



n=int(input())
s=raw_input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(m) m=0 m 0 def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1 merge n1=mid-left n1 mid-left mid left n2=right-mid n2 right-mid right mid el=range(0,n1+1) el range(0,n1+1) range 0 n1+1 n1 1 ar=range(0,n2+1) ar range(0,n2+1) range 0 n2+1 n2 1 for i in range(n1):
        el[i]=a[left+i]
     i range(n1) range n1 el[i]=a[left+i] el[i] el i a[left+i] a left+i left i for i in range(n2):
        ar[i]=a[mid+i]
     i range(n2) range n2 ar[i]=a[mid+i] ar[i] ar i a[mid+i] a mid+i mid i el[n1]=float("inf") el[n1] el n1 float("inf") float "inf" ar[n2]=float("inf") ar[n2] ar n2 float("inf") float "inf" i=0 i 0 j=0 j 0 for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1 k range(left,right) range left right global m m+=1 m 1 if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1 el[i] <= ar[j] el[i] el i ar[j] ar j a[k] = el[i] a[k] a k el[i] el i i=i+1 i i+1 i 1 a[k]=ar[j] a[k] a k ar[j] ar j j=j+1 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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left] 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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left] 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 if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left] a[left]>a[right-1] a[left] a left a[right-1] a right-1 right 1 a[left],a[right-1]=a[right],a[left] a[left] a left a[right] a right a[right-1] a right-1 right 1 a[left] a left a a left left right right n=int(input()) n int(input()) int input() input s=raw_input() s raw_input() raw_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(m) print m 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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left] 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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left] merge_sort s=raw_input() raw_input() s a=list(map(int,s.split())) list(map(int,s.split())) a m=0 0 m def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1 def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1 merge n=int(input()) int(input()) n a=map(str,a) map(str,a) a
m=0
def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            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)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left]



n=int(input())
s=raw_input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(m)