n = int(input())
nums = [int(i) for i in input().split(" ")]

count = 0

def merge(nums, left, mid, right):
    i = 0
    j = 0
    nums_l = nums[left:mid]
    nums_r = nums[mid:right]
    nums_l.append(10 ** 9 + 1)
    nums_r.append(10 ** 9 + 1)
    for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1

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

merge_sort(nums, 0, n)
result = ""
for i in nums:
    result += str(i) + " "
print(result.rstrip())
print(count) 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 nums = [int(i) for i in input().split(" ")] nums [int(i) for i in input().split(" ")] count = 0 count 0 def merge(nums, left, mid, right):
    i = 0
    j = 0
    nums_l = nums[left:mid]
    nums_r = nums[mid:right]
    nums_l.append(10 ** 9 + 1)
    nums_r.append(10 ** 9 + 1)
    for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1 merge i = 0 i 0 j = 0 j 0 nums_l = nums[left:mid] nums_l nums[left:mid] nums left:mid left mid nums_r = nums[mid:right] nums_r nums[mid:right] nums mid:right mid right nums_l.append(10 ** 9 + 1) nums_l.append nums_l append 10 ** 9 + 1 10 ** 9 10 9 1 nums_r.append(10 ** 9 + 1) nums_r.append nums_r append 10 ** 9 + 1 10 ** 9 10 9 1 for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1 x range(0, right - left) range 0 right - left right left global count count = count + 1 count count + 1 count 1 if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1 nums_l[i] <= nums_r[j] nums_l[i] nums_l i nums_r[j] nums_r j nums[left + x] = nums_l[i] nums[left + x] nums left + x left x nums_l[i] nums_l i i = i + 1 i i + 1 i 1 nums[left + x] = nums_r[j] nums[left + x] nums left + x left x nums_r[j] nums_r j j = j + 1 j j + 1 j 1 nums nums left left mid mid right right def merge_sort(nums, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(nums, left, mid)
        merge_sort(nums, mid, right)
        merge(nums, left, mid, right) merge_sort if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(nums, left, mid)
        merge_sort(nums, mid, right)
        merge(nums, 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(nums, left, mid) merge_sort nums left mid merge_sort(nums, mid, right) merge_sort nums mid right merge(nums, left, mid, right) merge nums left mid right nums nums left left right right merge_sort(nums, 0, n) merge_sort nums 0 n result = "" result "" for i in nums:
    result += str(i) + " " i nums result += str(i) + " " result str(i) + " " str(i) str i " " print(result.rstrip()) print result.rstrip() result.rstrip result rstrip print(count) print count def merge(nums, left, mid, right):
    i = 0
    j = 0
    nums_l = nums[left:mid]
    nums_r = nums[mid:right]
    nums_l.append(10 ** 9 + 1)
    nums_r.append(10 ** 9 + 1)
    for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1 def merge(nums, left, mid, right):
    i = 0
    j = 0
    nums_l = nums[left:mid]
    nums_r = nums[mid:right]
    nums_l.append(10 ** 9 + 1)
    nums_r.append(10 ** 9 + 1)
    for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1 merge result += str(i) + " " str(i) + " " result count = 0 0 count n = int(input()) int(input()) n nums = [int(i) for i in input().split(" ")] [int(i) for i in input().split(" ")] nums result = "" "" result def merge_sort(nums, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(nums, left, mid)
        merge_sort(nums, mid, right)
        merge(nums, left, mid, right) def merge_sort(nums, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(nums, left, mid)
        merge_sort(nums, mid, right)
        merge(nums, left, mid, right) merge_sort
n = int(input())
nums = [int(i) for i in input().split(" ")]

count = 0

def merge(nums, left, mid, right):
    i = 0
    j = 0
    nums_l = nums[left:mid]
    nums_r = nums[mid:right]
    nums_l.append(10 ** 9 + 1)
    nums_r.append(10 ** 9 + 1)
    for x in range(0, right - left):
        global count
        count = count + 1
        if nums_l[i] <= nums_r[j]:
            nums[left + x] = nums_l[i]
            i = i + 1
        else:
            nums[left + x] = nums_r[j]
            j = j + 1

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

merge_sort(nums, 0, n)
result = ""
for i in nums:
    result += str(i) + " "
print(result.rstrip())
print(count)
