from collections import deque

INFTY = 1e9 + 1


def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


n, a, cnt = int(input()), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print(*a)
print(cnt) from collections import deque INFTY = 1e9 + 1 INFTY 1e9 + 1 1e9 1 def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l merge global cnt ll = deque(a[l:m]) ll deque(a[l:m]) deque a[l:m] a l:m l m rl = deque(a[m:r]) rl deque(a[m:r]) deque a[m:r] a m:r m r ll.append(INFTY) ll.append ll append INFTY rl.append(INFTY) rl.append rl append INFTY for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
     k range(l, r) range l r a[k] = (ll if ll[0] < rl[0] else rl).popleft() a[k] a k (ll if ll[0] < rl[0] else rl).popleft() ll if ll[0] < rl[0] else rl).popleft ll if ll[0] < rl[0] else rl ll[0] < rl[0] ll[0] ll 0 rl[0] rl 0 ll rl popleft cnt += r - l cnt r - l r l a a l l m m r r def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) merge_sort if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(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 merge_sort(a, l, m) merge_sort a l m merge_sort(a, m, r) merge_sort a m r merge(a, l, m, r) merge a l m r a a l l r r n, a, cnt = int(input()), list(map(int, input().split())), 0 n int(input()) int input() input a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt 0 merge_sort(a, 0, n) merge_sort a 0 n print(*a) print *a a print(cnt) print cnt def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) merge_sort a, cnt = int(input()), list(map(int, input().split())), 0 list(map(int, input().split())) a def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l merge cnt = int(input()), list(map(int, input().split())), 0 0 cnt n, a, cnt = int(input()), list(map(int, input().split())), 0 int(input()) n INFTY = 1e9 + 1 1e9 + 1 INFTY
from collections import deque

INFTY = 1e9 + 1


def merge(a, l, m, r):
    global cnt
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(INFTY)
    rl.append(INFTY)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    cnt += r - l


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


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