count = [0]

def merge(A, left, right, mid, count):
    lstl = A[left: mid] + [5000000000]
    lstr = A[mid: right] + [5000000000]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
    

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

import sys
input = sys.stdin.readline

n = int(input())
S = list(map(int, input().split()))

merge_sort(S, 0, n)
print(" ".join(map(str, S)))
print(count[0]) count = [0] count [0] 0 def merge(A, left, right, mid, count):
    lstl = A[left: mid] + [5000000000]
    lstr = A[mid: right] + [5000000000]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
     merge lstl = A[left: mid] + [5000000000] lstl A[left: mid] + [5000000000] A[left: mid] A left: mid left mid [5000000000] 5000000000 lstr = A[mid: right] + [5000000000] lstr A[mid: right] + [5000000000] A[mid: right] A mid: right mid right [5000000000] 5000000000 pl = 0 pl 0 pr = 0 pr 0 for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
     _ range(left, right) range left right if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
     lstl[pl] < lstr[pr] lstl[pl] lstl pl lstr[pr] lstr pr A[left + pl + pr] = lstl[pl] A[left + pl + pr] A left + pl + pr left + pl left pl pr lstl[pl] lstl pl pl += 1 pl 1 count[0] += 1 count[0] count 0 1 A[left + pr + pl] = lstr[pr] A[left + pr + pl] A left + pr + pl left + pr left pr pl lstr[pr] lstr pr pr += 1 pr 1 count[0] += 1 count[0] count 0 1 A A left left right right mid mid count count def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, right, mid, count) merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, right, mid, count) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(A, left, mid) merge_sort A left mid merge_sort(A, mid, right) merge_sort A mid right merge(A, left, right, mid, count) merge A left right mid count A A left left right right import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split merge_sort(S, 0, n) merge_sort S 0 n print(" ".join(map(str, S))) print " ".join(map(str, S)) " ".join " " join map(str, S) map str S print(count[0]) print count[0] count 0 count = [0] [0] count input = sys.stdin.readline sys.stdin.readline input n = int(input()) int(input()) n S = list(map(int, input().split())) list(map(int, input().split())) S def merge(A, left, right, mid, count):
    lstl = A[left: mid] + [5000000000]
    lstr = A[mid: right] + [5000000000]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
     def merge(A, left, right, mid, count):
    lstl = A[left: mid] + [5000000000]
    lstr = A[mid: right] + [5000000000]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
     merge def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, right, mid, count) def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, right, mid, count) merge_sort
count = [0]

def merge(A, left, right, mid, count):
    lstl = A[left: mid] + [5000000000]
    lstr = A[mid: right] + [5000000000]
    pl = 0
    pr = 0
    for _ in range(left, right):
        if lstl[pl] < lstr[pr]:
            A[left + pl + pr] = lstl[pl]
            pl += 1
            count[0] += 1
        else:
            A[left + pr + pl] = lstr[pr]
            pr += 1
            count[0] += 1
    
    

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

import sys
input = sys.stdin.readline

n = int(input())
S = list(map(int, input().split()))

merge_sort(S, 0, n)
print(" ".join(map(str, S)))
print(count[0])
