# -*- coding: utf-8 -*-

import sys
import os
import math


n = int(input())
A = list(map(int, input().split()))
cnt = 0

def merge(A, left, mid, right):
    global cnt

    S = A[left:mid]
    T = A[mid:right]
    S.append(float('inf'))
    T.append(float('inf'))

    s_i = 0
    t_i = 0
    for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1


def merge_sort(A, left, right):
    if left + 1 == right:
        # ???????????????
        return
    else:
        # ??????????????????
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

merge_sort(A, 0, len(A))
print(*A)
print(cnt) import sys sys import os os import math math n = int(input()) n int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt = 0 cnt 0 def merge(A, left, mid, right):
    global cnt

    S = A[left:mid]
    T = A[mid:right]
    S.append(float('inf'))
    T.append(float('inf'))

    s_i = 0
    t_i = 0
    for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1 merge global cnt S = A[left:mid] S A[left:mid] A left:mid left mid T = A[mid:right] T A[mid:right] A mid:right mid right S.append(float('inf')) S.append S append float('inf') float 'inf' T.append(float('inf')) T.append T append float('inf') float 'inf' s_i = 0 s_i 0 t_i = 0 t_i 0 for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1 i range(right - left) range right - left right left cnt += 1 cnt 1 if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1 S[s_i] < T[t_i] S[s_i] S s_i T[t_i] T t_i A[left + i] = S[s_i] A[left + i] A left + i left i S[s_i] S s_i s_i += 1 s_i 1 A[left + i] = T[t_i] A[left + i] A left + i left i T[t_i] T t_i t_i += 1 t_i 1 A A left left mid mid right right def merge_sort(A, left, right):
    if left + 1 == right:
        # ???????????????
        return
    else:
        # ??????????????????
        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:
        # ???????????????
        return
    else:
        # ??????????????????
        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 return 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 merge_sort(A, 0, len(A)) merge_sort A 0 len(A) len A print(*A) print *A A print(cnt) print cnt def merge(A, left, mid, right):
    global cnt

    S = A[left:mid]
    T = A[mid:right]
    S.append(float('inf'))
    T.append(float('inf'))

    s_i = 0
    t_i = 0
    for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1 def merge(A, left, mid, right):
    global cnt

    S = A[left:mid]
    T = A[mid:right]
    S.append(float('inf'))
    T.append(float('inf'))

    s_i = 0
    t_i = 0
    for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1 merge n = int(input()) int(input()) n cnt = 0 0 cnt A = list(map(int, input().split())) list(map(int, input().split())) A def merge_sort(A, left, right):
    if left + 1 == right:
        # ???????????????
        return
    else:
        # ??????????????????
        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:
        # ???????????????
        return
    else:
        # ??????????????????
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) merge_sort
# -*- coding: utf-8 -*-

import sys
import os
import math


n = int(input())
A = list(map(int, input().split()))
cnt = 0

def merge(A, left, mid, right):
    global cnt

    S = A[left:mid]
    T = A[mid:right]
    S.append(float('inf'))
    T.append(float('inf'))

    s_i = 0
    t_i = 0
    for i in range(right - left):
        cnt += 1
        if S[s_i] < T[t_i]:
            A[left + i] = S[s_i]
            s_i += 1
        else:
            A[left + i] = T[t_i]
            t_i += 1


def merge_sort(A, left, right):
    if left + 1 == right:
        # ???????????????
        return
    else:
        # ??????????????????
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

merge_sort(A, 0, len(A))
print(*A)
print(cnt)