SENTINEL = 9999999999999

count = 0

def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right)

n = int(input())
S = list(map(int, input().split(" ")))

mergeSort(S, n, 0, n)
print(*S)
print(count) SENTINEL = 9999999999999 SENTINEL 9999999999999 count = 0 count 0 def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 merge global SENTINEL global count n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = S[left:mid] + [SENTINEL] L S[left:mid] + [SENTINEL] S[left:mid] S left:mid left mid [SENTINEL] SENTINEL R = S[mid:right] + [SENTINEL] R S[mid:right] + [SENTINEL] S[mid:right] S mid:right mid right [SENTINEL] SENTINEL i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 k range(left, right) range left right count += 1 count 1 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 S S n n left left mid mid right right def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right) mergeSort if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right) left + 1 < right left + 1 left 1 right mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 mergeSort(S, n, left, mid) mergeSort S n left mid mergeSort(S, n, mid, right) mergeSort S n mid right merge(S, n, left, mid, right) merge S n left mid right S S n n 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 " " mergeSort(S, n, 0, n) mergeSort S n 0 n print(*S) print *S S print(count) print count def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right) def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right) mergeSort count = 0 0 count SENTINEL = 9999999999999 9999999999999 SENTINEL def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 merge n = int(input()) int(input()) n S = list(map(int, input().split(" "))) list(map(int, input().split(" "))) S
SENTINEL = 9999999999999

count = 0

def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right)

n = int(input())
S = list(map(int, input().split(" ")))

mergeSort(S, n, 0, n)
print(*S)
print(count)
