n = int(input())
S = [int(i) for i in input().split()]

def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    i = 0
    j = 0
    L.append(1000000000)
    R.append(1000000000)
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return A

def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
    return A, cnt

S, comp_cnt = mergeSort(S, 0, n, 0)
print(*S)
print(comp_cnt)
 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()] def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    i = 0
    j = 0
    L.append(1000000000)
    R.append(1000000000)
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return A 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 i = 0 i 0 j = 0 j 0 L.append(1000000000) L.append L append 1000000000 R.append(1000000000) R.append R append 1000000000 for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     k range(left,right) range left right if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     L[i] <= R[j] L[i] L i R[j] R j A[k] = L[i] A[k] A k L[i] L i i += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 return A A A A left left mid mid right right def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
    return A, cnt mergeSort if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
     left+1 < right left+1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 A, cnt = mergeSort(A, left, mid, cnt) A mergeSort(A, left, mid, cnt) mergeSort A left mid cnt cnt A, cnt = mergeSort(A, mid, right, cnt) A mergeSort(A, mid, right, cnt) mergeSort A mid right cnt cnt A = merge(A, left, mid, right) A merge(A, left, mid, right) merge A left mid right cnt += right - left cnt right - left right left return A, cnt return A, cnt A cnt A A left left right right cnt cnt S, comp_cnt = mergeSort(S, 0, n, 0) S mergeSort(S, 0, n, 0) mergeSort S 0 n 0 comp_cnt print(*S) print *S S print(comp_cnt) print comp_cnt comp_cnt = mergeSort(S, 0, n, 0) mergeSort(S, 0, n, 0) comp_cnt def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    i = 0
    j = 0
    L.append(1000000000)
    R.append(1000000000)
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return A def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    i = 0
    j = 0
    L.append(1000000000)
    R.append(1000000000)
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return A merge n = int(input()) int(input()) n def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
    return A, cnt def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
    return A, cnt mergeSort S, comp_cnt = mergeSort(S, 0, n, 0) mergeSort(S, 0, n, 0) S S = [int(i) for i in input().split()] [int(i) for i in input().split()] S
n = int(input())
S = [int(i) for i in input().split()]

def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    i = 0
    j = 0
    L.append(1000000000)
    R.append(1000000000)
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return A

def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left + right)//2
        A, cnt = mergeSort(A, left, mid, cnt)
        A, cnt = mergeSort(A, mid, right, cnt)
        A = merge(A, left, mid, right)
        cnt += right - left
    return A, cnt

S, comp_cnt = mergeSort(S, 0, n, 0)
print(*S)
print(comp_cnt)

