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

def merge(A,left,mid,right,B):
    L = A[left:mid]
    R = A[mid:right]
    L.append(1000000000)
    R.append(1000000000)

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

n = int(input())
nums = list(map(int,input().split(" ")))
B = []

mergeSort(nums,0,n,B)
print(' '.join(map(str,nums)))
print(str(len(B)))
 def mergeSort(A,left,right,B):
    if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A,left,mid,B)
        mergeSort(A,mid,right,B)
        merge(A,left,mid,right,B) mergeSort if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A,left,mid,B)
        mergeSort(A,mid,right,B)
        merge(A,left,mid,right,B) left + 1 < right left + 1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 mergeSort(A,left,mid,B) mergeSort A left mid B mergeSort(A,mid,right,B) mergeSort A mid right B merge(A,left,mid,right,B) merge A left mid right B A A left left right right B B def merge(A,left,mid,right,B):
    L = A[left:mid]
    R = A[mid:right]
    L.append(1000000000)
    R.append(1000000000)

    i = 0
    j = 0
    for k in range(left,right):
        B.append(1)
        if L[i] < R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 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 L.append(1000000000) L.append L append 1000000000 R.append(1000000000) R.append R append 1000000000 i = 0 i 0 j = 0 j 0 for k in range(left,right):
        B.append(1)
        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 B.append(1) B.append B append 1 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 A A left left mid mid right right B B n = int(input()) n int(input()) int input() input nums = list(map(int,input().split(" "))) nums list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " B = [] B [] mergeSort(nums,0,n,B) mergeSort nums 0 n B print(' '.join(map(str,nums))) print ' '.join(map(str,nums)) ' '.join ' ' join map(str,nums) map str nums print(str(len(B))) print str(len(B)) str len(B) len B nums = list(map(int,input().split(" "))) list(map(int,input().split(" "))) nums B = [] [] B def mergeSort(A,left,right,B):
    if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A,left,mid,B)
        mergeSort(A,mid,right,B)
        merge(A,left,mid,right,B) def mergeSort(A,left,right,B):
    if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A,left,mid,B)
        mergeSort(A,mid,right,B)
        merge(A,left,mid,right,B) mergeSort def merge(A,left,mid,right,B):
    L = A[left:mid]
    R = A[mid:right]
    L.append(1000000000)
    R.append(1000000000)

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

    i = 0
    j = 0
    for k in range(left,right):
        B.append(1)
        if L[i] < R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge n = int(input()) int(input()) n
def mergeSort(A,left,right,B):
    if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A,left,mid,B)
        mergeSort(A,mid,right,B)
        merge(A,left,mid,right,B)

def merge(A,left,mid,right,B):
    L = A[left:mid]
    R = A[mid:right]
    L.append(1000000000)
    R.append(1000000000)

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

n = int(input())
nums = list(map(int,input().split(" ")))
B = []

mergeSort(nums,0,n,B)
print(' '.join(map(str,nums)))
print(str(len(B)))

