n=int(input())
S=[int(i) for i in input().split()]
INF=10**10

def merge(A,l,m,r):
    cnt=0
    n1=m-l
    n2=r-m
    L,R=[0 for i in range(n1)],[0 for i in range(n2)]
    cnt=0
    L=A[l:l+n1]
    R=A[m:m+n2]
    L.append(INF)
    R.append(INF)
    i,j=0,0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
    return cnt     

def mergesort(A,l,r):
    cnt=0
    if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
    return cnt


cnt=mergesort(S,0,n)
print(*S)
print(cnt) n=int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S=[int(i) for i in input().split()] S [int(i) for i in input().split()] INF=10**10 INF 10**10 10 10 def merge(A,l,m,r):
    cnt=0
    n1=m-l
    n2=r-m
    L,R=[0 for i in range(n1)],[0 for i in range(n2)]
    cnt=0
    L=A[l:l+n1]
    R=A[m:m+n2]
    L.append(INF)
    R.append(INF)
    i,j=0,0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
    return cnt      merge cnt=0 cnt 0 n1=m-l n1 m-l m l n2=r-m n2 r-m r m 0 for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) 0 L,R=[0 for i in range(n1)],[0 for i in range(n2)] L [0 for i in range(n1)] R [0 for i in range(n2)] cnt=0 cnt 0 L=A[l:l+n1] L A[l:l+n1] A l:l+n1 l l+n1 l n1 R=A[m:m+n2] R A[m:m+n2] A m:m+n2 m m+n2 m n2 L.append(INF) L.append L append INF R.append(INF) R.append R append INF i,j=0,0 i 0 j 0 for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
     k range(l,r) range l r 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 return cnt cnt A A l l m m r r def mergesort(A,l,r):
    cnt=0
    if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
    return cnt mergesort cnt=0 cnt 0 if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
     l+1<r l+1 l 1 r m=(l+r)//2 m (l+r)//2 l+r l r 2 cnt+=mergesort(A,l,m) cnt mergesort(A,l,m) mergesort A l m cnt+=mergesort(A,m,r) cnt mergesort(A,m,r) mergesort A m r cnt+=merge(A,l,m,r) cnt merge(A,l,m,r) merge A l m r return cnt cnt A A l l r r cnt=mergesort(S,0,n) cnt mergesort(S,0,n) mergesort S 0 n print(*S) print *S S print(cnt) print cnt cnt=mergesort(S,0,n) mergesort(S,0,n) cnt S=[int(i) for i in input().split()] [int(i) for i in input().split()] S n=int(input()) int(input()) n INF=10**10 10**10 INF def merge(A,l,m,r):
    cnt=0
    n1=m-l
    n2=r-m
    L,R=[0 for i in range(n1)],[0 for i in range(n2)]
    cnt=0
    L=A[l:l+n1]
    R=A[m:m+n2]
    L.append(INF)
    R.append(INF)
    i,j=0,0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
    return cnt      def merge(A,l,m,r):
    cnt=0
    n1=m-l
    n2=r-m
    L,R=[0 for i in range(n1)],[0 for i in range(n2)]
    cnt=0
    L=A[l:l+n1]
    R=A[m:m+n2]
    L.append(INF)
    R.append(INF)
    i,j=0,0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
    return cnt      merge def mergesort(A,l,r):
    cnt=0
    if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
    return cnt def mergesort(A,l,r):
    cnt=0
    if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
    return cnt mergesort
n=int(input())
S=[int(i) for i in input().split()]
INF=10**10

def merge(A,l,m,r):
    cnt=0
    n1=m-l
    n2=r-m
    L,R=[0 for i in range(n1)],[0 for i in range(n2)]
    cnt=0
    L=A[l:l+n1]
    R=A[m:m+n2]
    L.append(INF)
    R.append(INF)
    i,j=0,0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1   
        else:
            A[k]=R[j]
            j+=1
    return cnt     

def mergesort(A,l,r):
    cnt=0
    if l+1<r:
        m=(l+r)//2
        cnt+=mergesort(A,l,m)
        cnt+=mergesort(A,m,r)
        cnt+=merge(A,l,m,r)
    return cnt


cnt=mergesort(S,0,n)
print(*S)
print(cnt)
