import sys
sys.setrecursionlimit(10**6)


N = int(input())
A = list(map(int, input().split()))
INF = float('inf')
cnt = 0


def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1


def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)


merge_sort(0, N)
print(*A)
print(cnt)
 import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 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 INF = float('inf') INF float('inf') float 'inf' cnt = 0 cnt 0 def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1 merge global cnt L = A[left:mid]+[INF] L A[left:mid]+[INF] A[left:mid] A left:mid left mid [INF] INF R = A[mid:right]+[INF] R A[mid:right]+[INF] A[mid:right] A mid:right mid right [INF] INF l = 0 l 0 r = 0 r 0 for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1 i range(right-left) range right-left right left cnt += 1 cnt 1 if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1 L[l] < R[r] L[l] L l R[r] R r A[left+i] = L[l] A[left+i] A left+i left i L[l] L l l += 1 l 1 A[left+i] = R[r] A[left+i] A left+i left i R[r] R r r += 1 r 1 left left mid mid right right def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) merge_sort if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(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(left, mid) merge_sort left mid merge_sort(mid, right) merge_sort mid right merge(left, mid, right) merge left mid right left left right right merge_sort(0, N) merge_sort 0 N print(*A) print *A A print(cnt) print cnt INF = float('inf') float('inf') INF def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) merge_sort cnt = 0 0 cnt A = list(map(int, input().split())) list(map(int, input().split())) A N = int(input()) int(input()) N def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1 def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1 merge
import sys
sys.setrecursionlimit(10**6)


N = int(input())
A = list(map(int, input().split()))
INF = float('inf')
cnt = 0


def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1


def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)


merge_sort(0, N)
print(*A)
print(cnt)

