import sys
from typing import List


COMP_NUM = 0


def merge(elements: List[int], left: int, mid: int, right: int) -> None:
    global COMP_NUM
    n1 = mid - left
    n2 = right - mid
    left_array = [0] * (n1 + 1)
    right_array = [0] * (n2 + 1)
    left_array[0:n1] = elements[left:left + n1]
    left_array[n1] = sys.maxsize
    right_array[0:n2] = elements[mid:mid + n2]
    right_array[n2] = sys.maxsize

    i = 0
    j = 0
    for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1


def merge_sort(elements: List[int], left: int, right: int) -> None:
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right)


if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))
    merge_sort(elements, 0, len(elements))
    print(" ".join([str(elem) for elem in elements]))
    print(f"{COMP_NUM}")
 import sys sys from typing import List COMP_NUM = 0 COMP_NUM 0 def merge(elements: List[int], left: int, mid: int, right: int) -> None:
    global COMP_NUM
    n1 = mid - left
    n2 = right - mid
    left_array = [0] * (n1 + 1)
    right_array = [0] * (n2 + 1)
    left_array[0:n1] = elements[left:left + n1]
    left_array[n1] = sys.maxsize
    right_array[0:n2] = elements[mid:mid + n2]
    right_array[n2] = sys.maxsize

    i = 0
    j = 0
    for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1 merge global COMP_NUM n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid left_array = [0] * (n1 + 1) left_array [0] * (n1 + 1) [0] 0 n1 + 1 n1 1 right_array = [0] * (n2 + 1) right_array [0] * (n2 + 1) [0] 0 n2 + 1 n2 1 left_array[0:n1] = elements[left:left + n1] left_array[0:n1] left_array 0:n1 0 n1 elements[left:left + n1] elements left:left + n1 left left + n1 left n1 left_array[n1] = sys.maxsize left_array[n1] left_array n1 sys.maxsize sys maxsize right_array[0:n2] = elements[mid:mid + n2] right_array[0:n2] right_array 0:n2 0 n2 elements[mid:mid + n2] elements mid:mid + n2 mid mid + n2 mid n2 right_array[n2] = sys.maxsize right_array[n2] right_array n2 sys.maxsize sys maxsize i = 0 i 0 j = 0 j 0 for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1 k range(left, right) range left right COMP_NUM += 1 COMP_NUM 1 if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1 left_array[i] <= right_array[j] left_array[i] left_array i right_array[j] right_array j elements[k] = left_array[i] elements[k] elements k left_array[i] left_array i i += 1 i 1 elements[k] = right_array[j] elements[k] elements k right_array[j] right_array j j += 1 j 1 elements: List[int] elements left: int left mid: int mid right: int right def merge_sort(elements: List[int], left: int, right: int) -> None:
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right) merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(elements, left, mid) merge_sort elements left mid merge_sort(elements, mid, right) merge_sort elements mid right merge(elements, left, mid, right) merge elements left mid right elements: List[int] elements left: int left right: int right if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))
    merge_sort(elements, 0, len(elements))
    print(" ".join([str(elem) for elem in elements]))
    print(f"{COMP_NUM}") __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input elements = list(map(lambda x: int(x), input().split())) elements list(map(lambda x: int(x), input().split())) list map(lambda x: int(x), input().split()) map lambda x: int(x) int(x) int x x input().split() ().split () input split merge_sort(elements, 0, len(elements)) merge_sort elements 0 len(elements) len elements str(elem) for elem in elements for elem in elements elem elements for elem in elements str(elem) str elem print(" ".join([str(elem) for elem in elements])) print " ".join([str(elem) for elem in elements]) " ".join " " join [str(elem) for elem in elements] print(f"{COMP_NUM}") print f"{COMP_NUM}" COMP_NUM = 0 0 COMP_NUM def merge(elements: List[int], left: int, mid: int, right: int) -> None:
    global COMP_NUM
    n1 = mid - left
    n2 = right - mid
    left_array = [0] * (n1 + 1)
    right_array = [0] * (n2 + 1)
    left_array[0:n1] = elements[left:left + n1]
    left_array[n1] = sys.maxsize
    right_array[0:n2] = elements[mid:mid + n2]
    right_array[n2] = sys.maxsize

    i = 0
    j = 0
    for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1 def merge(elements: List[int], left: int, mid: int, right: int) -> None:
    global COMP_NUM
    n1 = mid - left
    n2 = right - mid
    left_array = [0] * (n1 + 1)
    right_array = [0] * (n2 + 1)
    left_array[0:n1] = elements[left:left + n1]
    left_array[n1] = sys.maxsize
    right_array[0:n2] = elements[mid:mid + n2]
    right_array[n2] = sys.maxsize

    i = 0
    j = 0
    for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1 merge elements = list(map(lambda x: int(x), input().split())) list(map(lambda x: int(x), input().split())) elements def merge_sort(elements: List[int], left: int, right: int) -> None:
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right) def merge_sort(elements: List[int], left: int, right: int) -> None:
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right) merge_sort n = int(input()) int(input()) n
import sys
from typing import List


COMP_NUM = 0


def merge(elements: List[int], left: int, mid: int, right: int) -> None:
    global COMP_NUM
    n1 = mid - left
    n2 = right - mid
    left_array = [0] * (n1 + 1)
    right_array = [0] * (n2 + 1)
    left_array[0:n1] = elements[left:left + n1]
    left_array[n1] = sys.maxsize
    right_array[0:n2] = elements[mid:mid + n2]
    right_array[n2] = sys.maxsize

    i = 0
    j = 0
    for k in range(left, right):
        COMP_NUM += 1
        if left_array[i] <= right_array[j]:
            elements[k] = left_array[i]
            i += 1
        else:
            elements[k] = right_array[j]
            j += 1


def merge_sort(elements: List[int], left: int, right: int) -> None:
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(elements, left, mid)
        merge_sort(elements, mid, right)
        merge(elements, left, mid, right)


if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))
    merge_sort(elements, 0, len(elements))
    print(" ".join([str(elem) for elem in elements]))
    print(f"{COMP_NUM}")

