ct=0
def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            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)
        
n=input()
s=map(int,raw_input().split())
mergesort(s,0,n)
i=0
s=map(str,s)
print(" ".join(s))
print(ct) ct=0 ct 0 def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1 merge global ct n1=mid-left n1 mid-left mid left n2=right-mid n2 right-mid right mid A[left+i] for i in xrange(n1) for i in xrange(n1) i xrange(n1) xrange n1 for i in xrange(n1) A[left+i] A left+i left i l=[A[left+i] for i in xrange(n1)] l [A[left+i] for i in xrange(n1)] A[mid+i] for i in xrange(n2) for i in xrange(n2) i xrange(n2) xrange n2 for i in xrange(n2) A[mid+i] A mid+i mid i r=[A[mid+i] for i in xrange(n2)] r [A[mid+i] for i in xrange(n2)] 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 xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1 k xrange(left,right) xrange left right ct+=1 ct 1 if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            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=i+1 i i+1 i 1 A[k]=r[j] A[k] A k r[j] r j j=j+1 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 n=input() n input() input s=map(int,raw_input().split()) s map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split mergesort(s,0,n) mergesort s 0 n i=0 i 0 s=map(str,s) s map(str,s) map str s print(" ".join(s)) print " ".join(s) " ".join " " join s print(ct) print ct i=0 0 i n=input() input() n ct=0 0 ct def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1 def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1 merge s=map(int,raw_input().split()) map(int,raw_input().split()) s 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 s=map(str,s) map(str,s) s
ct=0
def merge(A,left,mid,right):
    global ct
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append(float('inf'))
    r.append(float('inf'))
    i=0
    j=0
    for k in xrange(left,right):
        ct+=1
        if l[i]<=r[j]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            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)
        
n=input()
s=map(int,raw_input().split())
mergesort(s,0,n)
i=0
s=map(str,s)
print(" ".join(s))
print(ct)