import sys

INF = 10**9

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]

z = 0


def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right)


mergesort(A, 0, N)

print(" ".join([str(x) for x in A]))
print(z) import sys sys INF = 10**9 INF 10**9 10 9 N = int(sys.stdin.readline()) N int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x A = [int(x) for x in sys.stdin.readline().split()] A [int(x) for x in sys.stdin.readline().split()] z = 0 z 0 def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge global z n1 = (right - left) // 2 + left n1 (right - left) // 2 + left (right - left) // 2 right - left right left 2 left L = A[left:n1] L A[left:n1] A left:n1 left n1 R = A[n1:right] R A[n1:right] A n1:right n1 right L.append(INF) L.append L append INF R.append(INF) R.append R append INF i = 0 i 0 j = 0 j 0 for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 k range(left, right) range left right z += 1 z 1 if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j A[k] = L[i] A[k] A k L[i] L i i += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 A A left left right right def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right) mergesort if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 mergesort(A, left, mid) mergesort A left mid mergesort(A, mid, right) mergesort A mid right merge(A, left, right) merge A left right A A left left right right mergesort(A, 0, N) mergesort A 0 N str(x) for x in A for x in A x A for x in A str(x) str x print(" ".join([str(x) for x in A])) print " ".join([str(x) for x in A]) " ".join " " join [str(x) for x in A] print(z) print z A = [int(x) for x in sys.stdin.readline().split()] [int(x) for x in sys.stdin.readline().split()] A def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right) def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right) mergesort N = int(sys.stdin.readline()) int(sys.stdin.readline()) N z = 0 0 z INF = 10**9 10**9 INF def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge
import sys

INF = 10**9

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]

z = 0


def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right)


mergesort(A, 0, N)

print(" ".join([str(x) for x in A]))
print(z)
