import sys
from sys import stdin
input = stdin.readline

inf = float("inf")
cnt = 0
def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r)

def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
    
n = int(input())
NL = list(map(int, input().split()))
MS(NL, 0, n)

print(" ".join(list(map(str, NL))))
print(cnt) import sys sys from sys import stdin input = stdin.readline input stdin.readline stdin readline inf = float("inf") inf float("inf") float "inf" cnt = 0 cnt 0 def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r) MS if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r) l+1 <r l+1 l 1 r m = (l+r)//2 m (l+r)//2 l+r l r 2 MS(NL, l, m) MS NL l m MS(NL, m, r) MS NL m r M(NL, l, m, r) M NL l m r NL NL l l r r def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
     M global cnt L = NL[l:m]+[inf] L NL[l:m]+[inf] NL[l:m] NL l:m l m [inf] inf R = NL[m:r]+[inf] R NL[m:r]+[inf] NL[m:r] NL m:r m r [inf] inf i, j = 0, 0 i 0 j 0 for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
     k range(l, r) range l r if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
     L[i] >= R[j] L[i] L i R[j] R j NL[k] = R[j] NL[k] NL k R[j] R j j += 1 j 1 NL[k] = L[i] NL[k] NL k L[i] L i i += 1 i 1 cnt += (r-l) cnt r-l r l NL NL l l m m r r n = int(input()) n int(input()) int input() input NL = list(map(int, input().split())) NL list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split MS(NL, 0, n) MS NL 0 n print(" ".join(list(map(str, NL)))) print " ".join(list(map(str, NL))) " ".join " " join list(map(str, NL)) list map(str, NL) map str NL print(cnt) print cnt input = stdin.readline stdin.readline input n = int(input()) int(input()) n cnt = 0 0 cnt NL = list(map(int, input().split())) list(map(int, input().split())) NL inf = float("inf") float("inf") inf def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
     def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
     M def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r) def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r) MS
import sys
from sys import stdin
input = stdin.readline

inf = float("inf")
cnt = 0
def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r)

def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
    
n = int(input())
NL = list(map(int, input().split()))
MS(NL, 0, n)

print(" ".join(list(map(str, NL))))
print(cnt)
