#マージソート
from collections import deque
n = int(input())
S = list(map(int, input().split()))
INFTY = 1e9 + 1

def merge(S, left, mid, right):
    global cnt
    L = deque(S[left:mid])
    R = deque(S[mid:right])
    L.append(INFTY)
    R.append(INFTY)
    for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
    cnt += right - left
    
def merge_sort(S, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
        
cnt = 0
merge_sort(S, 0, n)
print(*S)
print(cnt) from collections import deque n = int(input()) n int(input()) int input() input S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split INFTY = 1e9 + 1 INFTY 1e9 + 1 1e9 1 def merge(S, left, mid, right):
    global cnt
    L = deque(S[left:mid])
    R = deque(S[mid:right])
    L.append(INFTY)
    R.append(INFTY)
    for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
    cnt += right - left
     merge global cnt L = deque(S[left:mid]) L deque(S[left:mid]) deque S[left:mid] S left:mid left mid R = deque(S[mid:right]) R deque(S[mid:right]) deque S[mid:right] S mid:right mid right L.append(INFTY) L.append L append INFTY R.append(INFTY) R.append R append INFTY for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
     k range(left, right) range left right S[k] = (L if L[0] < R[0] else R).popleft() S[k] S k (L if L[0] < R[0] else R).popleft() L if L[0] < R[0] else R).popleft L if L[0] < R[0] else R L[0] < R[0] L[0] L 0 R[0] R 0 L R popleft cnt += right - left cnt right - left right left S S left left mid mid right right def merge_sort(S, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
         merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
         left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(S, left, mid) merge_sort S left mid merge_sort(S, mid, right) merge_sort S mid right merge(S, left, mid, right) merge S left mid right S S left left right right cnt = 0 cnt 0 merge_sort(S, 0, n) merge_sort S 0 n print(*S) print *S S print(cnt) print cnt S = list(map(int, input().split())) list(map(int, input().split())) S n = int(input()) int(input()) n def merge_sort(S, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
         def merge_sort(S, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
         merge_sort cnt = 0 0 cnt def merge(S, left, mid, right):
    global cnt
    L = deque(S[left:mid])
    R = deque(S[mid:right])
    L.append(INFTY)
    R.append(INFTY)
    for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
    cnt += right - left
     def merge(S, left, mid, right):
    global cnt
    L = deque(S[left:mid])
    R = deque(S[mid:right])
    L.append(INFTY)
    R.append(INFTY)
    for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
    cnt += right - left
     merge INFTY = 1e9 + 1 1e9 + 1 INFTY
#マージソート
from collections import deque
n = int(input())
S = list(map(int, input().split()))
INFTY = 1e9 + 1

def merge(S, left, mid, right):
    global cnt
    L = deque(S[left:mid])
    R = deque(S[mid:right])
    L.append(INFTY)
    R.append(INFTY)
    for k in range(left, right):
        S[k] = (L if L[0] < R[0] else R).popleft()
    cnt += right - left
    
def merge_sort(S, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(S, left, mid)
        merge_sort(S, mid, right)
        merge(S, left, mid, right)
        
cnt = 0
merge_sort(S, 0, n)
print(*S)
print(cnt)
