N = int(input())
*A, = list(map(int, input().split()))
count = 0


def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1


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

merge_sort(A, 0, N)
print(*A)
print(count)
 N = int(input()) N int(input()) int input() input *A, = list(map(int, input().split())) *A A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split count = 0 count 0 def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1 merge global count la = a[left:mid] + [float("inf")] la a[left:mid] + [float("inf")] a[left:mid] a left:mid left mid [float("inf")] float("inf") float "inf" ra = a[mid:right] + [float("inf")] ra a[mid:right] + [float("inf")] a[mid:right] a mid:right mid right [float("inf")] float("inf") float "inf" i, j = 0, 0 i 0 j 0 for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1 k range(left, right) range left right count += 1 count 1 if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1 la[i] <= ra[j] la[i] la i ra[j] ra j a[k] = la[i] a[k] a k la[i] la i i += 1 i 1 a[k] = ra[j] a[k] a k ra[j] ra j j += 1 j 1 a a left left mid mid right right def merge_sort(a, left, right):
    if left + 1 < right:
        mid = int((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 = int((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 = int((left + right) / 2) mid int((left + right) / 2) int (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 a left left right right merge_sort(A, 0, N) merge_sort A 0 N print(*A) print *A A print(count) print count count = 0 0 count def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1 def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1 merge def merge_sort(a, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) def merge_sort(a, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort N = int(input()) int(input()) N
N = int(input())
*A, = list(map(int, input().split()))
count = 0


def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1


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

merge_sort(A, 0, N)
print(*A)
print(count)

