import math

def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    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
def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0

mergeSort(a,0,n)
print(*a)
print(cnt) import math math def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    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 merge global cnt L = a[l:m]+[math.inf] L a[l:m]+[math.inf] a[l:m] a l:m l m [math.inf] math.inf math inf R = a[m:r]+[math.inf] R a[m:r]+[math.inf] a[m:r] a m:r m r [math.inf] math.inf math inf i = 0 i 0 j = 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 a a l l m m r r def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) mergeSort if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        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 mergeSort(a,l,m) mergeSort a l m mergeSort(a,m,r) mergeSort a m r merge(a,l,m,r) merge a l m r a a l l r r n = int(input()) n int(input()) int input() input a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt = 0 cnt 0 mergeSort(a,0,n) mergeSort a 0 n print(*a) print *a a print(cnt) print cnt def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) mergeSort cnt = 0 0 cnt a = list(map(int, input().split())) list(map(int, input().split())) a def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    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 def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    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 merge n = int(input()) int(input()) n
import math

def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    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
def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0

mergeSort(a,0,n)
print(*a)
print(cnt)
