import sys
from typing import List
import math

n = int(input())
S = [int(i) for i in input().split()]
hikaku = 0


def merge(A: List[int], left: int, mid: int, right: int) -> None:
    global hikaku
    # n1 = mid - left  # left_listのデータ数
    # n2 = right - mid  # right_listのデータ数

    # left_list = [A[left + i] for i in range(n1)]
    # right_list = [A[mid + i] for i in range(n2)]
    left_list = A[left:mid]
    right_list = A[mid:right]
    left_list.append(sys.maxsize)
    right_list.append(sys.maxsize)

    i = 0  # left_listのインデックス
    j = 0  # right_listのインデックス
    for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1


def merge_sort(A: List[int], left: int, right: int) -> int:
    if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


merge_sort(S, 0, len(S))
print(' '.join(map(str, S)))
print(hikaku)
 import sys sys from typing import List import math math n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S = [int(i) for i in input().split()] S [int(i) for i in input().split()] hikaku = 0 hikaku 0 def merge(A: List[int], left: int, mid: int, right: int) -> None:
    global hikaku
    # n1 = mid - left  # left_listのデータ数
    # n2 = right - mid  # right_listのデータ数

    # left_list = [A[left + i] for i in range(n1)]
    # right_list = [A[mid + i] for i in range(n2)]
    left_list = A[left:mid]
    right_list = A[mid:right]
    left_list.append(sys.maxsize)
    right_list.append(sys.maxsize)

    i = 0  # left_listのインデックス
    j = 0  # right_listのインデックス
    for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1 merge global hikaku left_list = A[left:mid] left_list A[left:mid] A left:mid left mid right_list = A[mid:right] right_list A[mid:right] A mid:right mid right left_list.append(sys.maxsize) left_list.append left_list append sys.maxsize sys maxsize right_list.append(sys.maxsize) right_list.append right_list append sys.maxsize sys maxsize i = 0 i 0 j = 0 j 0 for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1 k range(left, right) range left right hikaku += 1 hikaku 1 if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1 left_list[i] <= right_list[j] left_list[i] left_list i right_list[j] right_list j A[k] = left_list[i] A[k] A k left_list[i] left_list i i += 1 i 1 A[k] = right_list[j] A[k] A k right_list[j] right_list j j += 1 j 1 A: List[int] A left: int left mid: int mid right: int right def merge_sort(A: List[int], left: int, right: int) -> int:
    if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) merge_sort if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) left + 1 < right left + 1 left 1 right mid = math.floor((left + right) / 2) mid math.floor((left + right) / 2) math.floor math floor (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, mid, right) merge A left mid right A: List[int] A left: int left right: int right merge_sort(S, 0, len(S)) merge_sort S 0 len(S) len S print(' '.join(map(str, S))) print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print(hikaku) print hikaku def merge_sort(A: List[int], left: int, right: int) -> int:
    if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) def merge_sort(A: List[int], left: int, right: int) -> int:
    if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) merge_sort S = [int(i) for i in input().split()] [int(i) for i in input().split()] S def merge(A: List[int], left: int, mid: int, right: int) -> None:
    global hikaku
    # n1 = mid - left  # left_listのデータ数
    # n2 = right - mid  # right_listのデータ数

    # left_list = [A[left + i] for i in range(n1)]
    # right_list = [A[mid + i] for i in range(n2)]
    left_list = A[left:mid]
    right_list = A[mid:right]
    left_list.append(sys.maxsize)
    right_list.append(sys.maxsize)

    i = 0  # left_listのインデックス
    j = 0  # right_listのインデックス
    for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1 def merge(A: List[int], left: int, mid: int, right: int) -> None:
    global hikaku
    # n1 = mid - left  # left_listのデータ数
    # n2 = right - mid  # right_listのデータ数

    # left_list = [A[left + i] for i in range(n1)]
    # right_list = [A[mid + i] for i in range(n2)]
    left_list = A[left:mid]
    right_list = A[mid:right]
    left_list.append(sys.maxsize)
    right_list.append(sys.maxsize)

    i = 0  # left_listのインデックス
    j = 0  # right_listのインデックス
    for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1 merge n = int(input()) int(input()) n hikaku = 0 0 hikaku
import sys
from typing import List
import math

n = int(input())
S = [int(i) for i in input().split()]
hikaku = 0


def merge(A: List[int], left: int, mid: int, right: int) -> None:
    global hikaku
    # n1 = mid - left  # left_listのデータ数
    # n2 = right - mid  # right_listのデータ数

    # left_list = [A[left + i] for i in range(n1)]
    # right_list = [A[mid + i] for i in range(n2)]
    left_list = A[left:mid]
    right_list = A[mid:right]
    left_list.append(sys.maxsize)
    right_list.append(sys.maxsize)

    i = 0  # left_listのインデックス
    j = 0  # right_listのインデックス
    for k in range(left, right):
        hikaku += 1
        if left_list[i] <= right_list[j]:
            A[k] = left_list[i]
            i += 1
        else:
            A[k] = right_list[j]
            j += 1


def merge_sort(A: List[int], left: int, right: int) -> int:
    if left + 1 < right:
        mid = math.floor((left + right) / 2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


merge_sort(S, 0, len(S))
print(' '.join(map(str, S)))
print(hikaku)

