cnt = 0
def merge(L,R):
    global cnt
    A = []
    i = j = 0
    n = len(L)+len(R)
    L.append(float("inf"))
    R.append(float("inf"))
    for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 
    

if __name__=='__main__':
    n=int(input()) 
    A=list(map(int,input().split()))
    print(*mergeSort(A))
    print(cnt) cnt = 0 cnt 0 def merge(L,R):
    global cnt
    A = []
    i = j = 0
    n = len(L)+len(R)
    L.append(float("inf"))
    R.append(float("inf"))
    for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A merge global cnt A = [] A [] i = j = 0 i 0 = j = 0 j 0 n = len(L)+len(R) n len(L)+len(R) len(L) len L len(R) len R L.append(float("inf")) L.append L append float("inf") float "inf" R.append(float("inf")) R.append R append float("inf") float "inf" for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
     _ range(n) range n cnt += 1 cnt 1 if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
     L[i] <= R[j] L[i] L i R[j] R j A.append(L[i]) A.append A append L[i] L i i += 1 i 1 A.append(R[j]) A.append A append R[j] R j j += 1 j 1 return A A L L R R def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 
     mergeSort if len(A)==1: return A
     len(A)==1 len(A) len A 1 m = len(A)//2 m len(A)//2 len(A) len A 2 return merge(mergeSort(A[:m]),mergeSort(A[m:])) merge(mergeSort(A[:m]),mergeSort(A[m:])) merge mergeSort(A[:m]) mergeSort A[:m] A :m m mergeSort(A[m:]) mergeSort A[m:] A m: m A A if __name__=='__main__':
    n=int(input()) 
    A=list(map(int,input().split()))
    print(*mergeSort(A))
    print(cnt) __name__=='__main__' __name__ '__main__' n=int(input()) n int(input()) int input() input A=list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split print(*mergeSort(A)) print *mergeSort(A) mergeSort(A) mergeSort A print(cnt) print cnt def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 
     def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 
     mergeSort n=int(input()) int(input()) n def merge(L,R):
    global cnt
    A = []
    i = j = 0
    n = len(L)+len(R)
    L.append(float("inf"))
    R.append(float("inf"))
    for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A def merge(L,R):
    global cnt
    A = []
    i = j = 0
    n = len(L)+len(R)
    L.append(float("inf"))
    R.append(float("inf"))
    for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A merge A=list(map(int,input().split())) list(map(int,input().split())) A cnt = 0 0 cnt
cnt = 0
def merge(L,R):
    global cnt
    A = []
    i = j = 0
    n = len(L)+len(R)
    L.append(float("inf"))
    R.append(float("inf"))
    for _ in range(n):
        cnt += 1
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 
    

if __name__=='__main__':
    n=int(input()) 
    A=list(map(int,input().split()))
    print(*mergeSort(A))
    print(cnt)