N=int(input())
num_list=list(map(int,input().split(" ")))
MAX=500000
L=[None]*((MAX)//2+2)
R=[None]*((MAX)//2+2)
def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt
def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0
cnt=mergesort(num_list,0,N)
print(*num_list)
print(cnt) N=int(input()) N int(input()) int input() input num_list=list(map(int,input().split(" "))) num_list list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " MAX=500000 MAX 500000 L=[None]*((MAX)//2+2) L [None]*((MAX)//2+2) [None] None (MAX)//2+2 (MAX)//2 MAX 2 2 R=[None]*((MAX)//2+2) R [None]*((MAX)//2+2) [None] None (MAX)//2+2 (MAX)//2 MAX 2 2 def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt merge cnt=0 cnt 0 n1=mid-left n1 mid-left mid left n2=right-mid n2 right-mid right mid for i in range(n1):
        L[i]=A[i+left]
     i range(n1) range n1 L[i]=A[i+left] L[i] L i A[i+left] A i+left i left for i in range(n2):
        R[i]=A[i+mid]
     i range(n2) range n2 R[i]=A[i+mid] R[i] R i A[i+mid] A i+mid i mid L[n1]=(10**9+1) L[n1] L n1 10**9+1 10**9 10 9 1 R[n2]=(10**9+1) R[n2] R n2 10**9+1 10**9 10 9 1 j,k=0,0 j 0 k 0 for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
     i range(left,right) range left right cnt+=1 cnt 1 if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
     L[j]<=R[k] L[j] L j R[k] R k A[i]=L[j] A[i] A i L[j] L j j+=1 j 1 A[i]=R[k] A[i] A i R[k] R k k+=1 k 1 return cnt cnt A A left left mid mid right right def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0 mergesort if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
     left+1<right left+1 left 1 right mid=(left+right)//2 mid (left+right)//2 left+right left right 2 cntL=mergesort(A,left,mid) cntL mergesort(A,left,mid) mergesort A left mid cntR=mergesort(A,mid,right) cntR mergesort(A,mid,right) mergesort A mid right return merge(A,left,mid,right)+cntL+cntR merge(A,left,mid,right)+cntL+cntR merge(A,left,mid,right)+cntL merge(A,left,mid,right) merge A left mid right cntL cntR return 0 0 A A left left right right cnt=mergesort(num_list,0,N) cnt mergesort(num_list,0,N) mergesort num_list 0 N print(*num_list) print *num_list num_list print(cnt) print cnt def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0 def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0 mergesort cnt=mergesort(num_list,0,N) mergesort(num_list,0,N) cnt N=int(input()) int(input()) N num_list=list(map(int,input().split(" "))) list(map(int,input().split(" "))) num_list MAX=500000 500000 MAX def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt merge L=[None]*((MAX)//2+2) [None]*((MAX)//2+2) L R=[None]*((MAX)//2+2) [None]*((MAX)//2+2) R
N=int(input())
num_list=list(map(int,input().split(" ")))
MAX=500000
L=[None]*((MAX)//2+2)
R=[None]*((MAX)//2+2)
def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt
def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0
cnt=mergesort(num_list,0,N)
print(*num_list)
print(cnt)
