#coding:utf-8
#1_5_B
def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0]

def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count]

n = int(input())
S = list(map(int, input().split()))
numbers, count = merge_sort(S)
print(*numbers)
print(count) def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0] merge_sort if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

     len(array) > 1 len(array) len array 1 L, countL = merge_sort(array[0:len(array)//2]) L merge_sort(array[0:len(array)//2]) merge_sort array[0:len(array)//2] array 0:len(array)//2 0 len(array)//2 len(array) len array 2 countL R, countR = merge_sort(array[len(array)//2:]) R merge_sort(array[len(array)//2:]) merge_sort array[len(array)//2:] array len(array)//2: len(array)//2 len(array) len array 2 countR return merge(L, R, countL+countR) merge(L, R, countL+countR) merge L R countL+countR countL countR if len(array) == 1:
        return [array, 0] len(array) == 1 len(array) len array 1 return [array, 0] [array, 0] array 0 array array def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count] merge L.append(10**9+1) L.append L append 10**9+1 10**9 10 9 1 R.append(10**9+1) R.append R append 10**9+1 10**9 10 9 1 response = [] response [] i = 0 i 0 j = 0 j 0 for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
     k range(len(L)-1 + len(R)-1) range len(L)-1 + len(R)-1 len(L)-1 + len(R) len(L)-1 len(L) len L 1 len(R) len R 1 if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
     L[i] <= R[j] L[i] L i R[j] R j response.append(L[i]) response.append response append L[i] L i i += 1 i 1 count += 1 count 1 response.append(R[j]) response.append response append R[j] R j j += 1 j 1 count += 1 count 1 return [response, count] [response, count] response count L L R R count=0 count 0 n = int(input()) n int(input()) int input() input S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split numbers, count = merge_sort(S) numbers merge_sort(S) merge_sort S count print(*numbers) print *numbers numbers print(count) print count numbers, count = merge_sort(S) merge_sort(S) numbers def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count] def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count] merge def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0] def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0] merge_sort S = list(map(int, input().split())) list(map(int, input().split())) S count = merge_sort(S) merge_sort(S) count n = int(input()) int(input()) n
#coding:utf-8
#1_5_B
def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0]

def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count]

n = int(input())
S = list(map(int, input().split()))
numbers, count = merge_sort(S)
print(*numbers)
print(count)