cnt=0
def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S


n=int(input())
S=list(map(int,input().split()))
merge_sort(S)
print(*S)
print(cnt) cnt=0 cnt 0 def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S merge_sort l=len(S) l len(S) len S mid=int(l/2) mid int(l/2) int l/2 l 2 Left=S[0:mid] Left S[0:mid] S 0:mid 0 mid Right=S[(mid):l] Right S[(mid):l] S (mid):l mid l global cnt if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

     l>=2 l 2 merge_sort(Left) and merge_sort(Right) merge_sort(Left) merge_sort Left merge_sort(Right) merge_sort Right Left.append(float('inf')) Left.append Left append float('inf') float 'inf' Right.append(float('inf')) Right.append Right append float('inf') float 'inf' p=0 p 0 q=0 q 0 for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
     i range(l) range l if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
     Left[p]<Right[q] Left[p] Left p Right[q] Right q S[i]=Left[p] S[i] S i Left[p] Left p p+=1 p 1 S[i]=Right[q] S[i] S i Right[q] Right q q+=1 q 1 if l!=1 :
        cnt+=l
    
     l!=1 l 1 cnt+=l cnt l return S S S S n=int(input()) n int(input()) int input() input S=list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split merge_sort(S) merge_sort S print(*S) print *S S print(cnt) print cnt S=list(map(int,input().split())) list(map(int,input().split())) S cnt=0 0 cnt def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S merge_sort n=int(input()) int(input()) n
cnt=0
def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    

    Left.append(float('inf'))
    Right.append(float('inf'))

    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
    if l!=1 :
        cnt+=l
    
    return S


n=int(input())
S=list(map(int,input().split()))
merge_sort(S)
print(*S)
print(cnt)
