# Merge sort マージソート
# 与えられたリストAをマージソートして返す。
def mergesort(A, left, right):
    mid = int((left + right) / 2)
    if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt


def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    l1, l2 = len(L), len(R)
    i1, i2 = 0, 0
    L += [2000000000]
    R += [2000000000]
    cnt = 0
    for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
    return cnt


n = int(input())
S = [int(i) for i in input().split()]
mergecnt = mergesort(S, 0, n)
for i in range(0, n - 1):
    print(S[i], end=" ")
print(S[n - 1])
print(mergecnt)
 def mergesort(A, left, right):
    mid = int((left + right) / 2)
    if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt mergesort mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt left + 1 >= right left + 1 left 1 right return 0 0 cnt = 0 cnt 0 cnt += mergesort(A, left, mid) cnt mergesort(A, left, mid) mergesort A left mid cnt += mergesort(A, mid, right) cnt mergesort(A, mid, right) mergesort A mid right cnt += merge(A, left, mid, right) cnt merge(A, left, mid, right) merge A left mid right return cnt cnt A A left left right right def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    l1, l2 = len(L), len(R)
    i1, i2 = 0, 0
    L += [2000000000]
    R += [2000000000]
    cnt = 0
    for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
    return cnt merge L = A[left:mid] L A[left:mid] A left:mid left mid R = A[mid:right] R A[mid:right] A mid:right mid right l1, l2 = len(L), len(R) l1 len(L) len L l2 len(R) len R i1, i2 = 0, 0 i1 0 i2 0 L += [2000000000] L [2000000000] 2000000000 R += [2000000000] R [2000000000] 2000000000 cnt = 0 cnt 0 for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
     k range(l1 + l2) range l1 + l2 l1 l2 cnt += 1 cnt 1 if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
     L[i1] <= R[i2] L[i1] L i1 R[i2] R i2 A[left + k] = L[i1] A[left + k] A left + k left k L[i1] L i1 i1 += 1 i1 1 A[left + k] = R[i2] A[left + k] A left + k left k R[i2] R i2 i2 += 1 i2 1 return cnt cnt A A left left mid mid right right n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S = [int(i) for i in input().split()] S [int(i) for i in input().split()] mergecnt = mergesort(S, 0, n) mergecnt mergesort(S, 0, n) mergesort S 0 n for i in range(0, n - 1):
    print(S[i], end=" ") i range(0, n - 1) range 0 n - 1 n 1 print(S[i], end=" ") print S[i] S i end=" " end " " print(S[n - 1]) print S[n - 1] S n - 1 n 1 print(mergecnt) print mergecnt n = int(input()) int(input()) n mergecnt = mergesort(S, 0, n) mergesort(S, 0, n) mergecnt def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    l1, l2 = len(L), len(R)
    i1, i2 = 0, 0
    L += [2000000000]
    R += [2000000000]
    cnt = 0
    for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
    return cnt def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    l1, l2 = len(L), len(R)
    i1, i2 = 0, 0
    L += [2000000000]
    R += [2000000000]
    cnt = 0
    for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
    return cnt merge def mergesort(A, left, right):
    mid = int((left + right) / 2)
    if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt def mergesort(A, left, right):
    mid = int((left + right) / 2)
    if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt mergesort S = [int(i) for i in input().split()] [int(i) for i in input().split()] S
# Merge sort マージソート
# 与えられたリストAをマージソートして返す。
def mergesort(A, left, right):
    mid = int((left + right) / 2)
    if left + 1 >= right:
        return 0
    else:
        cnt = 0
        cnt += mergesort(A, left, mid)
        cnt += mergesort(A, mid, right)
        cnt += merge(A, left, mid, right)
        return cnt


def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    l1, l2 = len(L), len(R)
    i1, i2 = 0, 0
    L += [2000000000]
    R += [2000000000]
    cnt = 0
    for k in range(l1 + l2):
        cnt += 1
        if L[i1] <= R[i2]:
            A[left + k] = L[i1]
            i1 += 1
        else:
            A[left + k] = R[i2]
            i2 += 1
    return cnt


n = int(input())
S = [int(i) for i in input().split()]
mergecnt = mergesort(S, 0, n)
for i in range(0, n - 1):
    print(S[i], end=" ")
print(S[n - 1])
print(mergecnt)

