import math
inf = math.inf

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

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

_ =input()
A = list(map(int, input().rstrip().split(" ")))
cnt = 0
mergeSort(A, 0, len(A))

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

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

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

_ =input()
A = list(map(int, input().rstrip().split(" ")))
cnt = 0
mergeSort(A, 0, len(A))

print(" ".join(list(map(str, A))))
print(cnt)
    
