import math
count = 0
def merge(a,left,mid,right):
    global count
    # n1 = mid-left
    # n2 = right - mid
    L = A[left:mid]+[1e9]#[0]*(n1+1)
    R = A[mid:right]+[1e9]#[0]*(n2+1)
    # for i in range(n1):
        # L[i] = A[left+i]
    # for i in range(n2):
        # R[i] = A[mid+i]
    # L[n1] = 1e9
    # R[n2] = 1e9
    i, j = [0,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
        count+=1
        
def mergesort(A,l,r):
    if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r)
N = int(input())
A = [int(x) for x in input().split(" ")]
A.append(1e9)
mergesort(A,0,N)
for i in range(len(A)):
    if i < len(A)-2:
        print(A[i],end=" ")
    else:
        print(A[i])
        break

print(count) import math math count = 0 count 0 def merge(a,left,mid,right):
    global count
    # n1 = mid-left
    # n2 = right - mid
    L = A[left:mid]+[1e9]#[0]*(n1+1)
    R = A[mid:right]+[1e9]#[0]*(n2+1)
    # for i in range(n1):
        # L[i] = A[left+i]
    # for i in range(n2):
        # R[i] = A[mid+i]
    # L[n1] = 1e9
    # R[n2] = 1e9
    i, j = [0,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
        count+=1
         merge global count L = A[left:mid]+[1e9] L A[left:mid]+[1e9] A[left:mid] A left:mid left mid [1e9] 1e9 R = A[mid:right]+[1e9] R A[mid:right]+[1e9] A[mid:right] A mid:right mid right [1e9] 1e9 i, j = [0,0] i [0,0] 0 0 j for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i+=1
        else:
            A[k] = R[j]
            j+=1
        count+=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 count+=1 count 1 a a left left mid mid right right def mergesort(A,l,r):
    if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r) mergesort if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r) (l+1) < r l+1 l 1 r mid = math.floor((l+r)/2) mid math.floor((l+r)/2) math.floor math floor (l+r)/2 l+r l r 2 mergesort(A,l,mid) mergesort A l mid mergesort(A,mid,r) mergesort A mid r merge(A,l,mid,r) merge A l mid r A A l l r r 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 A = [int(x) for x in input().split(" ")] A [int(x) for x in input().split(" ")] A.append(1e9) A.append A append 1e9 mergesort(A,0,N) mergesort A 0 N for i in range(len(A)):
    if i < len(A)-2:
        print(A[i],end=" ")
    else:
        print(A[i])
        break i range(len(A)) range len(A) len A if i < len(A)-2:
        print(A[i],end=" ")
    else:
        print(A[i])
        break i < len(A)-2 i len(A)-2 len(A) len A 2 print(A[i],end=" ") print A[i] A i end=" " end " " print(A[i]) print A[i] A i break print(count) print count count = 0 0 count def mergesort(A,l,r):
    if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r) def mergesort(A,l,r):
    if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r) mergesort def merge(a,left,mid,right):
    global count
    # n1 = mid-left
    # n2 = right - mid
    L = A[left:mid]+[1e9]#[0]*(n1+1)
    R = A[mid:right]+[1e9]#[0]*(n2+1)
    # for i in range(n1):
        # L[i] = A[left+i]
    # for i in range(n2):
        # R[i] = A[mid+i]
    # L[n1] = 1e9
    # R[n2] = 1e9
    i, j = [0,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
        count+=1
         def merge(a,left,mid,right):
    global count
    # n1 = mid-left
    # n2 = right - mid
    L = A[left:mid]+[1e9]#[0]*(n1+1)
    R = A[mid:right]+[1e9]#[0]*(n2+1)
    # for i in range(n1):
        # L[i] = A[left+i]
    # for i in range(n2):
        # R[i] = A[mid+i]
    # L[n1] = 1e9
    # R[n2] = 1e9
    i, j = [0,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
        count+=1
         merge N = int(input()) int(input()) N A = [int(x) for x in input().split(" ")] [int(x) for x in input().split(" ")] A
import math
count = 0
def merge(a,left,mid,right):
    global count
    # n1 = mid-left
    # n2 = right - mid
    L = A[left:mid]+[1e9]#[0]*(n1+1)
    R = A[mid:right]+[1e9]#[0]*(n2+1)
    # for i in range(n1):
        # L[i] = A[left+i]
    # for i in range(n2):
        # R[i] = A[mid+i]
    # L[n1] = 1e9
    # R[n2] = 1e9
    i, j = [0,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
        count+=1
        
def mergesort(A,l,r):
    if (l+1) < r:
        mid = math.floor((l+r)/2)
        mergesort(A,l,mid)
        mergesort(A,mid,r)
        merge(A,l,mid,r)
N = int(input())
A = [int(x) for x in input().split(" ")]
A.append(1e9)
mergesort(A,0,N)
for i in range(len(A)):
    if i < len(A)-2:
        print(A[i],end=" ")
    else:
        print(A[i])
        break

print(count)
