import sys
input = sys.stdin.readline

n = int(input())
L = [int(x) for x in input().split()]
cnt = 0

def Merge(S, l, m, r):
    global cnt
    cnt += r - l
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    return

def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return

MergeSort(L, 0, n)
print(*L)
print(cnt) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x L = [int(x) for x in input().split()] L [int(x) for x in input().split()] cnt = 0 cnt 0 def Merge(S, l, m, r):
    global cnt
    cnt += r - l
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    return Merge global cnt cnt += r - l cnt r - l r l L = S[l:m] + [float('inf')] L S[l:m] + [float('inf')] S[l:m] S l:m l m [float('inf')] float('inf') float 'inf' R = S[m:r] + [float('inf')] R S[m:r] + [float('inf')] S[m:r] S m:r m r [float('inf')] float('inf') float 'inf' i, j = 0, 0 i 0 j 0 for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
     k range(l, r) range l r if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
     L[i] < R[j] L[i] L i R[j] R j S[k] = L[i] S[k] S k L[i] L i i += 1 i 1 S[k] = R[j] S[k] S k R[j] R j j += 1 j 1 return S S l l m m r r def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return MergeSort if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
     r - l > 1 r - l r l 1 m = (l + r) // 2 m (l + r) // 2 l + r l r 2 MergeSort(S, l, m) MergeSort S l m MergeSort(S, m, r) MergeSort S m r Merge(S, l, m, r) Merge S l m r return S S l l r r MergeSort(L, 0, n) MergeSort L 0 n print(*L) print *L L print(cnt) print cnt n = int(input()) int(input()) n input = sys.stdin.readline sys.stdin.readline input L = [int(x) for x in input().split()] [int(x) for x in input().split()] L cnt = 0 0 cnt def Merge(S, l, m, r):
    global cnt
    cnt += r - l
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    return def Merge(S, l, m, r):
    global cnt
    cnt += r - l
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    return Merge def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return MergeSort
import sys
input = sys.stdin.readline

n = int(input())
L = [int(x) for x in input().split()]
cnt = 0

def Merge(S, l, m, r):
    global cnt
    cnt += r - l
    L = S[l:m] + [float('inf')]
    R = S[m:r] + [float('inf')]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] < R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    return

def MergeSort(S, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(S, l, m)
        MergeSort(S, m, r)
        Merge(S, l, m, r)
    return

MergeSort(L, 0, n)
print(*L)
print(cnt)
