import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 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, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0])

if __name__ == '__main__':
    resolve() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INF = 10**10 INF 10**10 10 10 def I(): return int(input()) I def F(): return float(input()) F def SS(): return input() SS int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x def LI(): return [int(x) for x in input().split()] LI int(x)-1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in input().split()] LI_ float(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() float(x) float x def LF(): return [float(x) for x in input().split()] LF def LSS(): return input().split() LSS def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 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, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0]) resolve n = I() n I() I S = LI() S LI() LI cnt = [0] cnt [0] 0 def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 1

     merge L = A[left:mid] L A[left:mid] A left:mid left mid R = A[mid:right] R A[mid:right] A mid:right mid 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):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 1

     k range(left, right) range left right 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 cnt[0] += 1 cnt[0] cnt 0 1 A A left left mid mid 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, mid, right)

     mergeSort if left+1 < right:
            mid = (left+right)//2
            mergeSort(A, left, mid)
            mergeSort(A, mid, right)
            merge(A, left, mid, 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, mid, right) merge A left mid right A A left left right right mergeSort(S, 0, n) mergeSort S 0 n print(*S) print *S S print(cnt[0]) print cnt[0] cnt 0 if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve def LF(): return [float(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] LF def LSS(): return input().split() def LSS(): return input().split() LSS INF = 10**10 10**10 INF def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 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, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0]) def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 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, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0]) resolve def LI_(): return [int(x)-1 for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] LI_ def F(): return float(input()) def F(): return float(input()) F def I(): return int(input()) def I(): return int(input()) I def LI(): return [int(x) for x in input().split()] def LI(): return [int(x) for x in input().split()] LI def SS(): return input() def SS(): return input() SS input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    S = LI()

    cnt = [0]

    def merge(A, left, mid, right):
        L = A[left:mid]
        R = A[mid:right]
        L.append(INF)
        R.append(INF)
        i = 0
        j = 0
        for k in range(left, right):
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
            cnt[0] += 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, mid, right)

    mergeSort(S, 0, n)
    print(*S)
    print(cnt[0])

if __name__ == '__main__':
    resolve()
