cnt = 0

def merge(array, left, middle, right):
    n1 = middle - left
    n2 = right - middle
    L = array[left:left + n1] + [float("inf")]
    R = array[middle:middle + n2] + [float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1


def mergeSort(array, left, right):
    if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right)


n = int(input())
array = [int(x) for x in input().split()]
mergeSort(array, 0, len(array))
print(*array)
print(cnt) cnt = 0 cnt 0 def merge(array, left, middle, right):
    n1 = middle - left
    n2 = right - middle
    L = array[left:left + n1] + [float("inf")]
    R = array[middle:middle + n2] + [float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1 merge n1 = middle - left n1 middle - left middle left n2 = right - middle n2 right - middle right middle L = array[left:left + n1] + [float("inf")] L array[left:left + n1] + [float("inf")] array[left:left + n1] array left:left + n1 left left + n1 left n1 [float("inf")] float("inf") float "inf" R = array[middle:middle + n2] + [float("inf")] R array[middle:middle + n2] + [float("inf")] array[middle:middle + n2] array middle:middle + n2 middle middle + n2 middle n2 [float("inf")] float("inf") float "inf" i = 0 i 0 j = 0 j 0 for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1 k range(left, right) range left right global cnt cnt += 1 cnt 1 if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j array[k] = L[i] array[k] array k L[i] L i i += 1 i 1 array[k] = R[j] array[k] array k R[j] R j j += 1 j 1 array array left left middle middle right right def mergeSort(array, left, right):
    if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right) mergeSort if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right) left + 1 < right left + 1 left 1 right middle = int((left + right) / 2.) middle int((left + right) / 2.) int (left + right) / 2. left + right left right 2. mergeSort(array, left, middle) mergeSort array left middle mergeSort(array, middle, right) mergeSort array middle right merge(array, left, middle, right) merge array left middle right array array left left right right n = int(input()) n int(input()) int input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x array = [int(x) for x in input().split()] array [int(x) for x in input().split()] mergeSort(array, 0, len(array)) mergeSort array 0 len(array) len array print(*array) print *array array print(cnt) print cnt def mergeSort(array, left, right):
    if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right) def mergeSort(array, left, right):
    if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right) mergeSort n = int(input()) int(input()) n array = [int(x) for x in input().split()] [int(x) for x in input().split()] array cnt = 0 0 cnt def merge(array, left, middle, right):
    n1 = middle - left
    n2 = right - middle
    L = array[left:left + n1] + [float("inf")]
    R = array[middle:middle + n2] + [float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1 def merge(array, left, middle, right):
    n1 = middle - left
    n2 = right - middle
    L = array[left:left + n1] + [float("inf")]
    R = array[middle:middle + n2] + [float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1 merge
cnt = 0

def merge(array, left, middle, right):
    n1 = middle - left
    n2 = right - middle
    L = array[left:left + n1] + [float("inf")]
    R = array[middle:middle + n2] + [float("inf")]
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1


def mergeSort(array, left, right):
    if left + 1 < right:
        middle = int((left + right) / 2.)
        mergeSort(array, left, middle)
        mergeSort(array, middle, right)
        merge(array, left, middle, right)


n = int(input())
array = [int(x) for x in input().split()]
mergeSort(array, 0, len(array))
print(*array)
print(cnt)
