#coding:utf-8
#1_5_B
def merge(array, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left

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


n = int(input())
S = list(map(int, input().split()))
cnt = 0
sentinel = 10 ** 9 + 1
merge_sort(S, 0, len(S))
print(*S)
print(cnt) def merge(array, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left merge global cnt n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = array[left:mid]  + [sentinel] L array[left:mid]  + [sentinel] array[left:mid] array left:mid left mid [sentinel] sentinel R = array[mid:right] + [sentinel] R array[mid:right] + [sentinel] array[mid:right] array mid:right mid right [sentinel] sentinel i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
     k range(left, right) range left right if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
     L[i] <= R[j] L[i] L i R[j] R j array[k] = L[i] array[k] array k L[i] L i i += 1 i 1 array[k] = R[j] array[k] array k R[j] R j j += 1 j 1 cnt += right - left cnt right - left right left array array left left mid mid right right def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right) merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, 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(array, left, mid) merge_sort array left mid merge_sort(array, mid, right) merge_sort array mid right merge(array, left, mid, right) merge array left mid right array array left left right right 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 cnt = 0 cnt 0 sentinel = 10 ** 9 + 1 sentinel 10 ** 9 + 1 10 ** 9 10 9 1 merge_sort(S, 0, len(S)) merge_sort S 0 len(S) len S print(*S) print *S S print(cnt) print cnt sentinel = 10 ** 9 + 1 10 ** 9 + 1 sentinel cnt = 0 0 cnt n = int(input()) int(input()) n def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right) def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right) merge_sort def merge(array, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left def merge(array, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left merge S = list(map(int, input().split())) list(map(int, input().split())) S
#coding:utf-8
#1_5_B
def merge(array, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left

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


n = int(input())
S = list(map(int, input().split()))
cnt = 0
sentinel = 10 ** 9 + 1
merge_sort(S, 0, len(S))
print(*S)
print(cnt)