from sys import stdin

INF = 1000000007

def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1

def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r)

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
mergeSort(S, 0, n)
print(*S)
print(count) from sys import stdin INF = 1000000007 INF 1000000007 def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1 merge global count L = A[l:m] + [INF] L A[l:m] + [INF] A[l:m] A l:m l m [INF] INF R = A[m:r] + [INF] R A[m:r] + [INF] A[m:r] A m:r m r [INF] INF li = 0 li 0 ri = 0 ri 0 for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1 j range(l, r) range l r count += 1 count 1 if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1 L[li] <= R[ri] L[li] L li R[ri] R ri A[j] = L[li] A[j] A j L[li] L li li += 1 li 1 A[j] = R[ri] A[j] A j R[ri] R ri ri += 1 ri 1 A A l l m m r r def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r) mergeSort if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r) r-l > 1 r-l r l 1 mid = l + (r-l)//2 mid l + (r-l)//2 l (r-l)//2 r-l r l 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(stdin.readline().rstrip()) n int(stdin.readline().rstrip()) int stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x S = [int(x) for x in stdin.readline().rstrip().split()] S [int(x) for x in stdin.readline().rstrip().split()] count = 0 count 0 mergeSort(S, 0, n) mergeSort S 0 n print(*S) print *S S print(count) print count n = int(stdin.readline().rstrip()) int(stdin.readline().rstrip()) n def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1 def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1 merge def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r) def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r) mergeSort INF = 1000000007 1000000007 INF count = 0 0 count S = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] S
from sys import stdin

INF = 1000000007

def merge(A, l, m, r):
    global count
    L = A[l:m] + [INF]
    R = A[m:r] + [INF]
    li = 0
    ri = 0
    for j in range(l, r):
        count += 1
        if L[li] <= R[ri]:
            A[j] = L[li]
            li += 1
        else:
            A[j] = R[ri]
            ri += 1

def mergeSort(A, l, r):
    if r-l > 1:
        mid = l + (r-l)//2
        mergeSort(A, l, mid)
        mergeSort(A, mid, r)
        merge(A, l, mid, r)

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
mergeSort(S, 0, n)
print(*S)
print(count)
