INF = float('inf')

cnt = 0

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

def merge(num_list,left,middle,right):
    global cnt
    left_list  =  num_list[left:middle] + [INF]
    right_list = num_list[middle:right] + [INF]

    i,j = 0,0
    for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1

n = int(input())
n_list = list(map(int,input().split()))
merge_sort(n_list,0,len(n_list))
print(' '.join([str(i) for i in n_list]))
print(cnt) INF = float('inf') INF float('inf') float 'inf' cnt = 0 cnt 0 def merge_sort(num_list,left,right):
    if left+1 < right:
        middle = (left+right)//2
        merge_sort(num_list,left,middle)
        merge_sort(num_list,middle,right)
        merge(num_list,left,middle,right) merge_sort if left+1 < right:
        middle = (left+right)//2
        merge_sort(num_list,left,middle)
        merge_sort(num_list,middle,right)
        merge(num_list,left,middle,right) left+1 < right left+1 left 1 right middle = (left+right)//2 middle (left+right)//2 left+right left right 2 merge_sort(num_list,left,middle) merge_sort num_list left middle merge_sort(num_list,middle,right) merge_sort num_list middle right merge(num_list,left,middle,right) merge num_list left middle right num_list num_list left left right right def merge(num_list,left,middle,right):
    global cnt
    left_list  =  num_list[left:middle] + [INF]
    right_list = num_list[middle:right] + [INF]

    i,j = 0,0
    for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1 merge global cnt left_list  =  num_list[left:middle] + [INF] left_list num_list[left:middle] + [INF] num_list[left:middle] num_list left:middle left middle [INF] INF right_list = num_list[middle:right] + [INF] right_list num_list[middle:right] + [INF] num_list[middle:right] num_list middle:right middle right [INF] INF i,j = 0,0 i 0 j 0 for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1 k range(left,right) range left right if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
         left_list[i] <= right_list[j] left_list[i] left_list i right_list[j] right_list j num_list[k]  = left_list[i] num_list[k] num_list k left_list[i] left_list i i += 1 i 1 num_list[k]  = right_list[j] num_list[k] num_list k right_list[j] right_list j j += 1 j 1 cnt += 1 cnt 1 num_list num_list left left middle middle right right n = int(input()) n int(input()) int input() input n_list = list(map(int,input().split())) n_list list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split merge_sort(n_list,0,len(n_list)) merge_sort n_list 0 len(n_list) len n_list str(i) for i in n_list for i in n_list i n_list for i in n_list str(i) str i print(' '.join([str(i) for i in n_list])) print ' '.join([str(i) for i in n_list]) ' '.join ' ' join [str(i) for i in n_list] print(cnt) print cnt cnt = 0 0 cnt def merge_sort(num_list,left,right):
    if left+1 < right:
        middle = (left+right)//2
        merge_sort(num_list,left,middle)
        merge_sort(num_list,middle,right)
        merge(num_list,left,middle,right) def merge_sort(num_list,left,right):
    if left+1 < right:
        middle = (left+right)//2
        merge_sort(num_list,left,middle)
        merge_sort(num_list,middle,right)
        merge(num_list,left,middle,right) merge_sort INF = float('inf') float('inf') INF n = int(input()) int(input()) n def merge(num_list,left,middle,right):
    global cnt
    left_list  =  num_list[left:middle] + [INF]
    right_list = num_list[middle:right] + [INF]

    i,j = 0,0
    for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1 def merge(num_list,left,middle,right):
    global cnt
    left_list  =  num_list[left:middle] + [INF]
    right_list = num_list[middle:right] + [INF]

    i,j = 0,0
    for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1 merge n_list = list(map(int,input().split())) list(map(int,input().split())) n_list
INF = float('inf')

cnt = 0

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

def merge(num_list,left,middle,right):
    global cnt
    left_list  =  num_list[left:middle] + [INF]
    right_list = num_list[middle:right] + [INF]

    i,j = 0,0
    for k in range(left,right):
        if left_list[i] <= right_list[j]:
            num_list[k]  = left_list[i] 
            i += 1
        else:
            num_list[k]  = right_list[j] 
            j += 1 
        cnt += 1

n = int(input())
n_list = list(map(int,input().split()))
merge_sort(n_list,0,len(n_list))
print(' '.join([str(i) for i in n_list]))
print(cnt)
