#初期定義
global result
global s_list
result = 0

#アルゴリズム：ソート
def merge(left, mid, right):
    global result
    
    n1 = mid - left
    n2 = right - mid
    inf = 10**9
    L_list = s_list[left: mid] + [inf]
    R_list = s_list[mid: right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート
def mergeSort(left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値
n = int(input())
s_list = list(map(int, input().split()))

#処理の実行
mergeSort(0, n)

#結果の表示
print(" ".join(map(str, s_list)))
print(result) global result global s_list result = 0 result 0 def merge(left, mid, right):
    global result
    
    n1 = mid - left
    n2 = right - mid
    inf = 10**9
    L_list = s_list[left: mid] + [inf]
    R_list = s_list[mid: right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート merge global result n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid inf = 10**9 inf 10**9 10 9 L_list = s_list[left: mid] + [inf] L_list s_list[left: mid] + [inf] s_list[left: mid] s_list left: mid left mid [inf] inf R_list = s_list[mid: right] + [inf] R_list s_list[mid: right] + [inf] s_list[mid: right] s_list mid: right mid right [inf] inf i = 0 i 0 j = 0 j 0 for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート k range(left, right) range left right result += 1 result 1 if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート L_list[i] <= R_list[j] L_list[i] L_list i R_list[j] R_list j s_list[k] = L_list[i] s_list[k] s_list k L_list[i] L_list i i += 1 i 1 s_list[k] = R_list[j] s_list[k] s_list k R_list[j] R_list j j += 1 j 1 left left mid mid right right def mergeSort(left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値 mergeSort if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値 (left + 1) < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 mergeSort(left, mid) mergeSort left mid mergeSort(mid, right) mergeSort mid right merge(left, mid, right) merge left mid right left left right right n = int(input()) n int(input()) int input() input s_list = list(map(int, input().split())) s_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mergeSort(0, n) mergeSort 0 n print(" ".join(map(str, s_list))) print " ".join(map(str, s_list)) " ".join " " join map(str, s_list) map str s_list print(result) print result s_list = list(map(int, input().split())) list(map(int, input().split())) s_list def merge(left, mid, right):
    global result
    
    n1 = mid - left
    n2 = right - mid
    inf = 10**9
    L_list = s_list[left: mid] + [inf]
    R_list = s_list[mid: right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート def merge(left, mid, right):
    global result
    
    n1 = mid - left
    n2 = right - mid
    inf = 10**9
    L_list = s_list[left: mid] + [inf]
    R_list = s_list[mid: right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート merge n = int(input()) int(input()) n global s_list def mergeSort(left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値 def mergeSort(left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値 mergeSort result = 0 0 result global result
#初期定義
global result
global s_list
result = 0

#アルゴリズム：ソート
def merge(left, mid, right):
    global result
    
    n1 = mid - left
    n2 = right - mid
    inf = 10**9
    L_list = s_list[left: mid] + [inf]
    R_list = s_list[mid: right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        result += 1
        if L_list[i] <= R_list[j]:
            s_list[k] = L_list[i]
            i += 1
        else:
            s_list[k] = R_list[j]
            j += 1

#アルゴリズム：マージソート
def mergeSort(left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        mergeSort(left, mid)
        mergeSort(mid, right)
        merge(left, mid, right)

#初期値
n = int(input())
s_list = list(map(int, input().split()))

#処理の実行
mergeSort(0, n)

#結果の表示
print(" ".join(map(str, s_list)))
print(result)
