import sys
#import time

compare_counter = 0
array = [0 for x in range(500000)]

def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    #print(left, mid, right)
    i = j = 0
    global compare_counter
    compare_counter += (right - left)
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1


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


def main():
    #start = time.time()
    n = int(input())
    for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
    merge_sort(0, n)
    #print("time", time.time()-start)
    print(" ".join(map(str, array[:n])))
    print(compare_counter)
    #print("time",time.time()-start)
    return


main() import sys sys compare_counter = 0 compare_counter 0 0 for x in range(500000) for x in range(500000) x range(500000) range 500000 for x in range(500000) 0 array = [0 for x in range(500000)] array [0 for x in range(500000)] def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    #print(left, mid, right)
    i = j = 0
    global compare_counter
    compare_counter += (right - left)
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1 merge n_fore = mid - left n_fore mid - left mid left n_rear = right - mid n_rear right - mid right mid l_fore = array[left:left + n_fore] l_fore array[left:left + n_fore] array left:left + n_fore left left + n_fore left n_fore l_fore.append(sys.maxsize) l_fore.append l_fore append sys.maxsize sys maxsize l_rear = array[mid:mid + n_rear] l_rear array[mid:mid + n_rear] array mid:mid + n_rear mid mid + n_rear mid n_rear l_rear.append(sys.maxsize) l_rear.append l_rear append sys.maxsize sys maxsize i = j = 0 i 0 = j = 0 j 0 global compare_counter compare_counter += (right - left) compare_counter right - left right left for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1 k range(left, right) range left right if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1 l_fore[i] < l_rear[j] l_fore[i] l_fore i l_rear[j] l_rear j array[k] = l_fore[i] array[k] array k l_fore[i] l_fore i i += 1 i 1 array[k] = l_rear[j] array[k] array k l_rear[j] l_rear j j += 1 j 1 left left mid mid right right def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)
    return merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(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(left, mid) merge_sort left mid merge_sort(mid, right) merge_sort mid right merge(left, mid, right) merge left mid right return left left right right def main():
    #start = time.time()
    n = int(input())
    for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
    merge_sort(0, n)
    #print("time", time.time()-start)
    print(" ".join(map(str, array[:n])))
    print(compare_counter)
    #print("time",time.time()-start)
    return main n = int(input()) n int(input()) int input() input for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
     idx tmp enumerate(input().split()) enumerate input().split() ().split () input split array[idx] = int(tmp) array[idx] array idx int(tmp) int tmp merge_sort(0, n) merge_sort 0 n print(" ".join(map(str, array[:n]))) print " ".join(map(str, array[:n])) " ".join " " join map(str, array[:n]) map str array[:n] array :n n print(compare_counter) print compare_counter return main() main def main():
    #start = time.time()
    n = int(input())
    for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
    merge_sort(0, n)
    #print("time", time.time()-start)
    print(" ".join(map(str, array[:n])))
    print(compare_counter)
    #print("time",time.time()-start)
    return def main():
    #start = time.time()
    n = int(input())
    for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
    merge_sort(0, n)
    #print("time", time.time()-start)
    print(" ".join(map(str, array[:n])))
    print(compare_counter)
    #print("time",time.time()-start)
    return main def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)
    return def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)
    return merge_sort compare_counter = 0 0 compare_counter array = [0 for x in range(500000)] [0 for x in range(500000)] array def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    #print(left, mid, right)
    i = j = 0
    global compare_counter
    compare_counter += (right - left)
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1 def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    #print(left, mid, right)
    i = j = 0
    global compare_counter
    compare_counter += (right - left)
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1 merge
import sys
#import time

compare_counter = 0
array = [0 for x in range(500000)]

def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    #print(left, mid, right)
    i = j = 0
    global compare_counter
    compare_counter += (right - left)
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            j += 1


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


def main():
    #start = time.time()
    n = int(input())
    for idx, tmp in enumerate(input().split()):
        array[idx] = int(tmp)
    #print("time", time.time()-start)
    merge_sort(0, n)
    #print("time", time.time()-start)
    print(" ".join(map(str, array[:n])))
    print(compare_counter)
    #print("time",time.time()-start)
    return


main()
