# -*- coding:utf-8 -*-
import sys


def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
    return cnt


def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0


if __name__ == "__main__":
    lst = [val.split() for val in sys.stdin.read().splitlines()]
    data = [int(n) for n in lst[1]]
    cnt = mergeSort(data, 0, int(lst[0][0]))
    print(" ".join([str(n) for n in data]))
    print(cnt) import sys sys def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
    return cnt merge L = lst[left: mid] L lst[left: mid] lst left: mid left mid R = lst[mid: right] R lst[mid: right] lst mid: right mid right l_len = len(L) l_len len(L) len L r_len = len(R) r_len len(R) len R cnt = 0 cnt 0 i = 0 i 0 j = 0 j 0 for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
     k range(left, right) range left right cnt += 1 cnt 1 if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
     l_len <= i l_len i lst[k] = R[j] lst[k] lst k R[j] R j j += 1 j 1 elif r_len <= j:
            lst[k] = L[i]
            i += 1
         r_len <= j r_len j lst[k] = L[i] lst[k] lst k L[i] L i i += 1 i 1 elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
         L[i] <= R[j] L[i] L i R[j] R j lst[k] = L[i] lst[k] lst k L[i] L i i += 1 i 1 lst[k] = R[j] lst[k] lst k R[j] R j j += 1 j 1 return cnt cnt lst lst left left mid mid right right def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0 mergeSort if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0 left + 1 < right left + 1 left 1 right mid = (left + right) >> 1 mid (left + right) >> 1 left + right left right 1 cnt = mergeSort(lst, left, mid) cnt mergeSort(lst, left, mid) mergeSort lst left mid cnt += mergeSort(lst, mid, right) cnt mergeSort(lst, mid, right) mergeSort lst mid right return merge(lst, left, mid, right) + cnt merge(lst, left, mid, right) + cnt merge(lst, left, mid, right) merge lst left mid right cnt return 0 0 lst lst left left right right if __name__ == "__main__":
    lst = [val.split() for val in sys.stdin.read().splitlines()]
    data = [int(n) for n in lst[1]]
    cnt = mergeSort(data, 0, int(lst[0][0]))
    print(" ".join([str(n) for n in data]))
    print(cnt) __name__ == "__main__" __name__ "__main__" val.split() for val in sys.stdin.read().splitlines() for val in sys.stdin.read().splitlines() val sys.stdin.read().splitlines() sys.stdin.read().splitlines sys.stdin.read() sys.stdin.read sys.stdin sys stdin read splitlines for val in sys.stdin.read().splitlines() val.split() val.split val split lst = [val.split() for val in sys.stdin.read().splitlines()] lst [val.split() for val in sys.stdin.read().splitlines()] int(n) for n in lst[1] for n in lst[1] n lst[1] lst 1 for n in lst[1] int(n) int n data = [int(n) for n in lst[1]] data [int(n) for n in lst[1]] cnt = mergeSort(data, 0, int(lst[0][0])) cnt mergeSort(data, 0, int(lst[0][0])) mergeSort data 0 int(lst[0][0]) int lst[0][0] [0] lst 0 0 str(n) for n in data for n in data n data for n in data str(n) str n print(" ".join([str(n) for n in data])) print " ".join([str(n) for n in data]) " ".join " " join [str(n) for n in data] print(cnt) print cnt def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
    return cnt def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
    return cnt merge def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0 def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0 mergeSort data = [int(n) for n in lst[1]] [int(n) for n in lst[1]] data cnt = mergeSort(data, 0, int(lst[0][0])) mergeSort(data, 0, int(lst[0][0])) cnt lst = [val.split() for val in sys.stdin.read().splitlines()] [val.split() for val in sys.stdin.read().splitlines()] lst
# -*- coding:utf-8 -*-
import sys


def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1
    return cnt


def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0


if __name__ == "__main__":
    lst = [val.split() for val in sys.stdin.read().splitlines()]
    data = [int(n) for n in lst[1]]
    cnt = mergeSort(data, 0, int(lst[0][0]))
    print(" ".join([str(n) for n in data]))
    print(cnt)