import sys
input = sys.stdin.readline
MAX = 500000
SENTINEL = 2000000000
L = [0]*(MAX//2 + 2)
R = [0]*(MAX//2 + 2)
cnt = 0

def Merge(A,n,left,mid,right,cnt):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    L_i = 0
    R_i = 0
    for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
    return cnt

def MergeSort(A,n,left,right,cnt):
    if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
    return cnt

if __name__ == "__main__":
    n = int(input())
    array = list(map(int,input().split()))
    cnt = 0
    SENTINEL = 2*10**9
    cnt = MergeSort(array,n,0,n,cnt)
    print(" ".join(map(str,array)))
    print(cnt)
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MAX = 500000 MAX 500000 SENTINEL = 2000000000 SENTINEL 2000000000 L = [0]*(MAX//2 + 2) L [0]*(MAX//2 + 2) [0] 0 MAX//2 + 2 MAX//2 MAX 2 2 R = [0]*(MAX//2 + 2) R [0]*(MAX//2 + 2) [0] 0 MAX//2 + 2 MAX//2 MAX 2 2 cnt = 0 cnt 0 def Merge(A,n,left,mid,right,cnt):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    L_i = 0
    R_i = 0
    for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
    return cnt Merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid for i in range(n1):
        L[i] = A[left + i]
     i range(n1) range n1 L[i] = A[left + i] L[i] L i A[left + i] A left + i left i for i in range(n2):
        R[i] = A[mid + i]
     i range(n2) range n2 R[i] = A[mid + i] R[i] R i A[mid + i] A mid + i mid i L[n1] = SENTINEL L[n1] L n1 SENTINEL R[n2] = SENTINEL R[n2] R n2 SENTINEL L_i = 0 L_i 0 R_i = 0 R_i 0 for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
     k range(left,right) range left right cnt += 1 cnt 1 if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
     L[L_i] <= R[R_i] L[L_i] L L_i R[R_i] R R_i A[k] = L[L_i] A[k] A k L[L_i] L L_i L_i += 1 L_i 1 A[k] = R[R_i] A[k] A k R[R_i] R R_i R_i += 1 R_i 1 return cnt cnt A A n n left left mid mid right right cnt cnt def MergeSort(A,n,left,right,cnt):
    if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
    return cnt MergeSort if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
     left + 1 < right left + 1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 cnt = MergeSort(A,n,left,mid,cnt) cnt MergeSort(A,n,left,mid,cnt) MergeSort A n left mid cnt cnt = MergeSort(A,n,mid,right,cnt) cnt MergeSort(A,n,mid,right,cnt) MergeSort A n mid right cnt cnt = Merge(A,n,left,mid,right,cnt) cnt Merge(A,n,left,mid,right,cnt) Merge A n left mid right cnt return cnt cnt A A n n left left right right cnt cnt if __name__ == "__main__":
    n = int(input())
    array = list(map(int,input().split()))
    cnt = 0
    SENTINEL = 2*10**9
    cnt = MergeSort(array,n,0,n,cnt)
    print(" ".join(map(str,array)))
    print(cnt) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input array = list(map(int,input().split())) array list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cnt = 0 cnt 0 SENTINEL = 2*10**9 SENTINEL 2*10**9 2 10**9 10 9 cnt = MergeSort(array,n,0,n,cnt) cnt MergeSort(array,n,0,n,cnt) MergeSort array n 0 n cnt print(" ".join(map(str,array))) print " ".join(map(str,array)) " ".join " " join map(str,array) map str array print(cnt) print cnt L = [0]*(MAX//2 + 2) [0]*(MAX//2 + 2) L MAX = 500000 500000 MAX cnt = 0 0 cnt SENTINEL = 2*10**9 2*10**9 SENTINEL cnt = MergeSort(array,n,0,n,cnt) MergeSort(array,n,0,n,cnt) cnt def Merge(A,n,left,mid,right,cnt):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    L_i = 0
    R_i = 0
    for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
    return cnt def Merge(A,n,left,mid,right,cnt):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    L_i = 0
    R_i = 0
    for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
    return cnt Merge R = [0]*(MAX//2 + 2) [0]*(MAX//2 + 2) R n = int(input()) int(input()) n SENTINEL = 2000000000 2000000000 SENTINEL input = sys.stdin.readline sys.stdin.readline input array = list(map(int,input().split())) list(map(int,input().split())) array def MergeSort(A,n,left,right,cnt):
    if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
    return cnt def MergeSort(A,n,left,right,cnt):
    if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
    return cnt MergeSort cnt = 0 0 cnt
import sys
input = sys.stdin.readline
MAX = 500000
SENTINEL = 2000000000
L = [0]*(MAX//2 + 2)
R = [0]*(MAX//2 + 2)
cnt = 0

def Merge(A,n,left,mid,right,cnt):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    L_i = 0
    R_i = 0
    for k in range(left,right):
        cnt += 1
        if L[L_i] <= R[R_i]:
            A[k] = L[L_i]
            L_i += 1
        else:
            A[k] = R[R_i]
            R_i += 1
    return cnt

def MergeSort(A,n,left,right,cnt):
    if left + 1 < right:
        mid = (left + right)//2
        cnt = MergeSort(A,n,left,mid,cnt)
        cnt = MergeSort(A,n,mid,right,cnt)
        cnt = Merge(A,n,left,mid,right,cnt)
    return cnt

if __name__ == "__main__":
    n = int(input())
    array = list(map(int,input().split()))
    cnt = 0
    SENTINEL = 2*10**9
    cnt = MergeSort(array,n,0,n,cnt)
    print(" ".join(map(str,array)))
    print(cnt)

