def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt

def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt

n = int(input())
S = list(map(int, input().split()))
cnt = merge_sort(S, 0, n)
print(*S)
print(cnt) def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid arr[left + i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) arr[left + i] arr left + i left i L = [arr[left + i] for i in range(n1)] L [arr[left + i] for i in range(n1)] arr[mid + i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) arr[mid + i] arr mid + i mid i R = [arr[mid + i] for i in range(n2)] R [arr[mid + i] for i in range(n2)] L.append(10 ** 9) L.append L append 10 ** 9 10 9 R.append(10 ** 9) R.append R append 10 ** 9 10 9 i = 0 i 0 j = 0 j 0 cnt = 0 cnt 0 for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
     k range(left, right) range left right cnt += 1 cnt 1 if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
     L[i] <= R[j] L[i] L i R[j] R j arr[k] = L[i] arr[k] arr k L[i] L i i += 1 i 1 arr[k] = R[j] arr[k] arr k R[j] R j j += 1 j 1 return cnt cnt arr arr left: int left mid: int mid right: int right def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt merge_sort cnt = 0 cnt 0 if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
     left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 cnt += merge_sort(arr, left, mid) cnt merge_sort(arr, left, mid) merge_sort arr left mid cnt += merge_sort(arr, mid, right) cnt merge_sort(arr, mid, right) merge_sort arr mid right cnt += merge(arr, left, mid, right) cnt merge(arr, left, mid, right) merge arr left mid right return cnt cnt arr arr left: int left right: int right 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 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 def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt merge cnt = merge_sort(S, 0, n) merge_sort(S, 0, n) cnt def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt merge_sort n = int(input()) int(input()) n S = list(map(int, input().split())) list(map(int, input().split())) S
def merge(arr, left: int, mid: int, right: int) -> int:
    n1 = mid - left
    n2 = right - mid
    L = [arr[left + i] for i in range(n1)]
    R = [arr[mid + i] for i in range(n2)]
    L.append(10 ** 9)
    R.append(10 ** 9)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
    return cnt

def merge_sort(arr, left: int, right: int) -> int:
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(arr, left, mid)
        cnt += merge_sort(arr, mid, right)
        cnt += merge(arr, left, mid, right)
    return cnt

n = int(input())
S = list(map(int, input().split()))
cnt = merge_sort(S, 0, n)
print(*S)
print(cnt)
