def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)

def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left

if __name__ == "__main__":
    num = [0]
    inf = float('inf')
    n = int(input())
    S = list(map(int, input().split()))
    merge_sort(0, n)
    print(' '.join(list(map(str, S))))
    print(num[0]) def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) merge_sort if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) right-left > 1 right-left right left 1 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(left, mid) merge_sort left mid merge_sort(mid, right) merge_sort mid right merge(left, mid, right) merge left mid right left left right right def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left merge left_part = S[left:mid] left_part S[left:mid] S left:mid left mid right_part = S[mid:right] right_part S[mid:right] S mid:right mid right left_part.append(inf) left_part.append left_part append inf right_part.append(inf) right_part.append right_part append inf l, r = 0, 0 l 0 r 0 for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
     i range(left, right) range left right if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
     left_part[l] < right_part[r] left_part[l] left_part l right_part[r] right_part r S[i] = left_part[l] S[i] S i left_part[l] left_part l l += 1 l 1 S[i] = right_part[r] S[i] S i right_part[r] right_part r r += 1 r 1 num[0] += right-left num[0] num 0 right-left right left left left mid mid right right if __name__ == "__main__":
    num = [0]
    inf = float('inf')
    n = int(input())
    S = list(map(int, input().split()))
    merge_sort(0, n)
    print(' '.join(list(map(str, S))))
    print(num[0]) __name__ == "__main__" __name__ "__main__" num = [0] num [0] 0 inf = float('inf') inf float('inf') float 'inf' 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 merge_sort(0, n) merge_sort 0 n print(' '.join(list(map(str, S)))) print ' '.join(list(map(str, S))) ' '.join ' ' join list(map(str, S)) list map(str, S) map str S print(num[0]) print num[0] num 0 n = int(input()) int(input()) n inf = float('inf') float('inf') inf def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right) merge_sort num = [0] [0] num def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left merge S = list(map(int, input().split())) list(map(int, input().split())) S
def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)

def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left

if __name__ == "__main__":
    num = [0]
    inf = float('inf')
    n = int(input())
    S = list(map(int, input().split()))
    merge_sort(0, n)
    print(' '.join(list(map(str, S))))
    print(num[0])
