cnt = 0
def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1

def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r)


n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a, 0, n - 1)
print(' '.join(map(str, a)))
print(cnt)
 cnt = 0 cnt 0 def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1 merge global cnt l = 0 l 0 l_e = mid - left l_e mid - left mid left r = 0 r 0 r_e = right - mid - 1 r_e right - mid - 1 right - mid right mid 1 L = a[left:mid + 1] L a[left:mid + 1] a left:mid + 1 left mid + 1 mid 1 R = a[mid + 1:right + 1] R a[mid + 1:right + 1] a mid + 1:right + 1 mid + 1 mid 1 right + 1 right 1 csr = left csr left while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
     l <= l_e and r <= r_e l <= l_e l l_e r <= r_e r r_e cnt += 1 cnt 1 if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
         L[l] < R[r] L[l] L l R[r] R r a[csr] = L[l] a[csr] a csr L[l] L l l += 1 l 1 a[csr] = R[r] a[csr] a csr R[r] R r r += 1 r 1 csr += 1 csr 1 if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1 l == l_e + 1 l l_e + 1 l_e 1 while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
     r <= r_e r r_e a[csr] = R[r] a[csr] a csr R[r] R r r += 1 r 1 csr += 1 csr 1 cnt += 1 cnt 1 while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1 l <= l_e l l_e a[csr] = L[l] a[csr] a csr L[l] L l l += 1 l 1 csr += 1 csr 1 cnt += 1 cnt 1 a a left left mid mid right right def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r) merge_sort mid = (l + r) // 2 mid (l + r) // 2 l + r l r 2 if l < r:
        merge_sort(a, l, mid)
     l < r l r merge_sort(a, l, mid) merge_sort a l mid if l + 1 < r:
        merge_sort(a, mid + 1, r)
     l + 1 < r l + 1 l 1 r merge_sort(a, mid + 1, r) merge_sort a mid + 1 mid 1 r if l < r:
        merge(a, l, mid, r) l < r l 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(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 a = [int(i) for i in input().split()] a [int(i) for i in input().split()] merge_sort(a, 0, n - 1) merge_sort a 0 n - 1 n 1 print(' '.join(map(str, a))) print ' '.join(map(str, a)) ' '.join ' ' join map(str, a) map str a print(cnt) print cnt def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r) def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r) merge_sort def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1 def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1 merge n = int(input()) int(input()) n cnt = 0 0 cnt a = [int(i) for i in input().split()] [int(i) for i in input().split()] a
cnt = 0
def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1

def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r)


n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a, 0, n - 1)
print(' '.join(map(str, a)))
print(cnt)

