#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin

num_swap = 0


def merge(a, left, mid, right):
    global num_swap
    L = a[left:mid]
    R = a[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1


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


stdin.readline()
s = [int(s) for s in stdin.readline().split()]
merge_sort(s, 0, len(s))
print(*s)
print(num_swap) from __future__ import division, print_function from sys import stdin num_swap = 0 num_swap 0 def merge(a, left, mid, right):
    global num_swap
    L = a[left:mid]
    R = a[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1 merge global num_swap L = a[left:mid] L a[left:mid] a left:mid left mid R = a[mid:right] R a[mid:right] a mid:right mid right L.append(10**9+1) L.append L append 10**9+1 10**9 10 9 1 R.append(10**9+1) R.append R append 10**9+1 10**9 10 9 1 i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1 k range(left, right) range left right if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
         L[i] <= R[j] L[i] L i R[j] R j a[k] = L[i] a[k] a k L[i] L i i += 1 i 1 a[k] = R[j] a[k] a k R[j] R j j += 1 j 1 num_swap += 1 num_swap 1 a a left left mid mid right right def merge_sort(a, left, right):
    if left+1 < right:
        mid = (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 = (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 = (left + right) // 2 mid (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 stdin.readline() stdin.readline stdin readline int(s) for s in stdin.readline().split() for s in stdin.readline().split() s stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split for s in stdin.readline().split() int(s) int s s = [int(s) for s in stdin.readline().split()] s [int(s) for s in stdin.readline().split()] merge_sort(s, 0, len(s)) merge_sort s 0 len(s) len s print(*s) print *s s print(num_swap) print num_swap def merge(a, left, mid, right):
    global num_swap
    L = a[left:mid]
    R = a[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1 def merge(a, left, mid, right):
    global num_swap
    L = a[left:mid]
    R = a[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1 merge def merge_sort(a, left, right):
    if left+1 < right:
        mid = (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 = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort s = [int(s) for s in stdin.readline().split()] [int(s) for s in stdin.readline().split()] s num_swap = 0 0 num_swap
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin

num_swap = 0


def merge(a, left, mid, right):
    global num_swap
    L = a[left:mid]
    R = a[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        num_swap += 1


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


stdin.readline()
s = [int(s) for s in stdin.readline().split()]
merge_sort(s, 0, len(s))
print(*s)
print(num_swap)