INF = 2*int(1e9)
cnt = 0
def merge(A, left, mid, right):
    global cnt
    nl = mid - left
    nr = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1


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

def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    mergeSort(s, 0, n)
    for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

    print(cnt)
main() INF = 2*int(1e9) INF 2*int(1e9) 2 int(1e9) int 1e9 cnt = 0 cnt 0 def merge(A, left, mid, right):
    global cnt
    nl = mid - left
    nr = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1 merge global cnt nl = mid - left nl mid - left mid left nr = right - mid nr right - mid right mid L = A[left:mid] L A[left:mid] A left:mid left mid R = A[mid:right] R A[mid:right] A mid:right mid right L.append(INF) L.append L append INF R.append(INF) R.append R append INF i = 0 i 0 j = 0 j 0 for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1 k range(left, right) range left right cnt = cnt +  1 cnt cnt +  1 cnt 1 if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            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 = i +  1 i i +  1 i 1 A[k] = R[j] A[k] A k R[j] R j j = j + 1 j j + 1 j 1 A A left left mid mid right right def mergeSort(A, left, right):
    if left+1<right:
        mid = (left+right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) mergeSort if left+1<right:
        mid = (left+right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) left+1<right left+1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 mergeSort(A, left, mid) mergeSort A left mid mergeSort(A, mid, right) mergeSort A mid right merge(A, left, mid, right) merge A left mid right A A left left right right def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    mergeSort(s, 0, n)
    for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

    print(cnt) main n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s = [int(i) for i in input().split()] s [int(i) for i in input().split()] mergeSort(s, 0, n) mergeSort s 0 n for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

     i range(n) range n if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

     i == n-1 i n-1 n 1 print(s[i]) print s[i] s i print(s[i], end=' ') print s[i] s i end=' ' end ' ' print(cnt) print cnt main() main cnt = 0 0 cnt def merge(A, left, mid, right):
    global cnt
    nl = mid - left
    nr = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1 def merge(A, left, mid, right):
    global cnt
    nl = mid - left
    nr = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1 merge INF = 2*int(1e9) 2*int(1e9) INF def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    mergeSort(s, 0, n)
    for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

    print(cnt) def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    mergeSort(s, 0, n)
    for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

    print(cnt) main def mergeSort(A, left, right):
    if left+1<right:
        mid = (left+right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) def mergeSort(A, left, right):
    if left+1<right:
        mid = (left+right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) mergeSort
INF = 2*int(1e9)
cnt = 0
def merge(A, left, mid, right):
    global cnt
    nl = mid - left
    nr = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        cnt = cnt +  1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i +  1
        else:
            A[k] = R[j]
            j = j + 1


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

def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    mergeSort(s, 0, n)
    for i in range(n):
        if i == n-1:
            print(s[i])
        else:
            print(s[i], end=' ')

    print(cnt)
main()
