import math
import sys


def merge(a, left, mid, right):
    count = 0

    a1 = a[left:mid] + [math.inf]
    a2 = a[mid:right] + [math.inf]

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

    return count


def merge_sort(a, left, right):
    if left + 1 >= right:
        return 0

    count = 0
    mid = (left + right) // 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
    return count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().split()]
count = merge_sort(a, 0, len(a))

print(' '.join(map(str, a)))
print(count)
 import math math import sys sys def merge(a, left, mid, right):
    count = 0

    a1 = a[left:mid] + [math.inf]
    a2 = a[mid:right] + [math.inf]

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

    return count merge count = 0 count 0 a1 = a[left:mid] + [math.inf] a1 a[left:mid] + [math.inf] a[left:mid] a left:mid left mid [math.inf] math.inf math inf a2 = a[mid:right] + [math.inf] a2 a[mid:right] + [math.inf] a[mid:right] a mid:right mid right [math.inf] math.inf math inf i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        if a1[i] <= a2[j]:
            a[k] = a1[i]
            i += 1
        else:
            a[k] = a2[j]
            j += 1
        count += 1

     k range(left, right) range left right if a1[i] <= a2[j]:
            a[k] = a1[i]
            i += 1
        else:
            a[k] = a2[j]
            j += 1
         a1[i] <= a2[j] a1[i] a1 i a2[j] a2 j a[k] = a1[i] a[k] a k a1[i] a1 i i += 1 i 1 a[k] = a2[j] a[k] a k a2[j] a2 j j += 1 j 1 count += 1 count 1 return count count a a left left mid mid right right def merge_sort(a, left, right):
    if left + 1 >= right:
        return 0

    count = 0
    mid = (left + right) // 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
    return count merge_sort if left + 1 >= right:
        return 0

     left + 1 >= right left + 1 left 1 right return 0 0 count = 0 count 0 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 count += merge_sort(a, left, mid) count merge_sort(a, left, mid) merge_sort a left mid count += merge_sort(a, mid, right) count merge_sort(a, mid, right) merge_sort a mid right count += merge(a, left, mid, right) count merge(a, left, mid, right) merge a left mid right return count count a a left left right right n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline int(v) for v in sys.stdin.readline().split() for v in sys.stdin.readline().split() v sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for v in sys.stdin.readline().split() int(v) int v a = [int(v) for v in sys.stdin.readline().split()] a [int(v) for v in sys.stdin.readline().split()] count = merge_sort(a, 0, len(a)) count merge_sort(a, 0, len(a)) merge_sort a 0 len(a) len a print(' '.join(map(str, a))) print ' '.join(map(str, a)) ' '.join ' ' join map(str, a) map str a print(count) print count n = int(sys.stdin.readline()) int(sys.stdin.readline()) n def merge_sort(a, left, right):
    if left + 1 >= right:
        return 0

    count = 0
    mid = (left + right) // 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
    return count def merge_sort(a, left, right):
    if left + 1 >= right:
        return 0

    count = 0
    mid = (left + right) // 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
    return count merge_sort a = [int(v) for v in sys.stdin.readline().split()] [int(v) for v in sys.stdin.readline().split()] a def merge(a, left, mid, right):
    count = 0

    a1 = a[left:mid] + [math.inf]
    a2 = a[mid:right] + [math.inf]

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

    return count def merge(a, left, mid, right):
    count = 0

    a1 = a[left:mid] + [math.inf]
    a2 = a[mid:right] + [math.inf]

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

    return count merge count = merge_sort(a, 0, len(a)) merge_sort(a, 0, len(a)) count
import math
import sys


def merge(a, left, mid, right):
    count = 0

    a1 = a[left:mid] + [math.inf]
    a2 = a[mid:right] + [math.inf]

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

    return count


def merge_sort(a, left, right):
    if left + 1 >= right:
        return 0

    count = 0
    mid = (left + right) // 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
    return count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().split()]
count = merge_sort(a, 0, len(a))

print(' '.join(map(str, a)))
print(count)

