def merge(A, l, m, r):
    n1 = m - l
    n2 = r - m
    
    L = [A[l+i] for i in range(n1)]
    R = [A[m+i] for i in range(n2)]
    L.append(10**10)
    R.append(10**10)
    
    i = 0
    j = 0
    for k in range(l, r):
        if L[i]<=R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global cnt
    cnt += i+j
    #print(cnt)
    return i+j
    
def mergeSort(A, l, r):
    if l+1<r:
        mid = (l + r)//2;
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r)


n = int(input())
A = list(map(int, input().split()))
#n = 10
#A = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
cnt = 0

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


n = int(input())
A = list(map(int, input().split()))
#n = 10
#A = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
cnt = 0

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