# coding: utf-8
# Your code here!

INF = 10**10

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    a1 = [A[i+left] for i in range(n1)]
    a2 = [A[i+mid] for i in range(n2)]
    a1.append(INF)
    a2.append(INF)
    
    a1_i = a2_i = 0
    
    for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
    return right-left
    
def merge_sort(A, left, right):
    cnt = 0
    
    if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
    return cnt

n = int(input())
S = [int(i) for i in input().split()]

cnt = merge_sort(S, 0, n)

print(*S)
print(cnt)
 INF = 10**10 INF 10**10 10 10 def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    a1 = [A[i+left] for i in range(n1)]
    a2 = [A[i+mid] for i in range(n2)]
    a1.append(INF)
    a2.append(INF)
    
    a1_i = a2_i = 0
    
    for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
    return right-left
     merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid A[i+left] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) A[i+left] A i+left i left a1 = [A[i+left] for i in range(n1)] a1 [A[i+left] for i in range(n1)] A[i+mid] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) A[i+mid] A i+mid i mid a2 = [A[i+mid] for i in range(n2)] a2 [A[i+mid] for i in range(n2)] a1.append(INF) a1.append a1 append INF a2.append(INF) a2.append a2 append INF a1_i = a2_i = 0 a1_i 0 = a2_i = 0 a2_i 0 for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
     i range(right-left) range right-left right left if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
     a1[a1_i] <= a2[a2_i] a1[a1_i] a1 a1_i a2[a2_i] a2 a2_i A[left+i] = a1[a1_i] A[left+i] A left+i left i a1[a1_i] a1 a1_i a1_i += 1 a1_i 1 A[left+i] = a2[a2_i] A[left+i] A left+i left i a2[a2_i] a2 a2_i a2_i += 1 a2_i 1 return right-left right-left right left A A left left mid mid right right def merge_sort(A, left, right):
    cnt = 0
    
    if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
    return cnt merge_sort cnt = 0 cnt 0 if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
     left+1 < right left+1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 cnt += merge_sort(A, left, mid) cnt merge_sort(A, left, mid) merge_sort A left mid cnt += merge_sort(A, mid, right) cnt merge_sort(A, mid, right) merge_sort A mid right cnt += merge(A, left, mid, right) cnt merge(A, left, mid, right) merge A left mid right return cnt cnt A A left left right right 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()] cnt = merge_sort(S, 0, n) cnt merge_sort(S, 0, n) merge_sort S 0 n print(*S) print *S S print(cnt) print cnt INF = 10**10 10**10 INF n = int(input()) int(input()) n def merge_sort(A, left, right):
    cnt = 0
    
    if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
    return cnt def merge_sort(A, left, right):
    cnt = 0
    
    if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
    return cnt merge_sort S = [int(i) for i in input().split()] [int(i) for i in input().split()] S def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    a1 = [A[i+left] for i in range(n1)]
    a2 = [A[i+mid] for i in range(n2)]
    a1.append(INF)
    a2.append(INF)
    
    a1_i = a2_i = 0
    
    for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
    return right-left
     def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    a1 = [A[i+left] for i in range(n1)]
    a2 = [A[i+mid] for i in range(n2)]
    a1.append(INF)
    a2.append(INF)
    
    a1_i = a2_i = 0
    
    for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
    return right-left
     merge cnt = merge_sort(S, 0, n) merge_sort(S, 0, n) cnt
# coding: utf-8
# Your code here!

INF = 10**10

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    a1 = [A[i+left] for i in range(n1)]
    a2 = [A[i+mid] for i in range(n2)]
    a1.append(INF)
    a2.append(INF)
    
    a1_i = a2_i = 0
    
    for i in range(right-left):
        if a1[a1_i] <= a2[a2_i]:
            A[left+i] = a1[a1_i]
            a1_i += 1
        else:
            A[left+i] = a2[a2_i]
            a2_i += 1
    return right-left
    
def merge_sort(A, left, right):
    cnt = 0
    
    if left+1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(A, left, mid)
        cnt += merge_sort(A, mid, right)
        
        cnt += merge(A, left, mid, right)
        
        #print('l={}, r={}, m={}'.format(left, right, mid))    
        #print(*A)
        
    return cnt

n = int(input())
S = [int(i) for i in input().split()]

cnt = merge_sort(S, 0, n)

print(*S)
print(cnt)

