from bisect import bisect_right as br
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt)
main()
 from bisect import bisect_right as br import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 int1 = lambda x: int(x) - 1 int1 lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x p2D = lambda x: print(*x, sep="\n") p2D lambda x: print(*x, sep="\n") print(*x, sep="\n") print *x x sep="\n" sep "\n" x def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res MergeSort def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

     merge res=0 res 0 inf = float("inf") inf float("inf") float "inf" L = aa[left2:mid2] + [inf] L aa[left2:mid2] + [inf] aa[left2:mid2] aa left2:mid2 left2 mid2 [inf] inf R = aa[mid2:right2] + [inf] R aa[mid2:right2] + [inf] aa[mid2:right2] aa mid2:right2 mid2 right2 [inf] inf Li = Ri = 0 Li 0 = Ri = 0 Ri 0 for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
         ai range(left2, right2) range left2 right2 res+=1 res 1 if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
         L[Li] < R[Ri] L[Li] L Li R[Ri] R Ri aa[ai] = L[Li] aa[ai] aa ai L[Li] L Li Li += 1 Li 1 aa[ai] = R[Ri] aa[ai] aa ai R[Ri] R Ri Ri += 1 Ri 1 return res res aa aa left2 left2 mid2 mid2 right2 right2 res=0 res 0 if right == -1: right = len(aa)
     right == -1 right -1 if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
     left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 res+=MergeSort(aa, left, mid) res MergeSort(aa, left, mid) MergeSort aa left mid res+=MergeSort(aa, mid, right) res MergeSort(aa, mid, right) MergeSort aa mid right res+=merge(aa, left, mid, right) res merge(aa, left, mid, right) merge aa left mid right return res res aa aa left=0 left 0 right=-1 right -1 def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt) main n=int(input()) n int(input()) int input() input aa=list(map(int, input().split())) aa list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt=MergeSort(aa) cnt MergeSort(aa) MergeSort aa print(*aa) print *aa aa print(cnt) print cnt main() main def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res MergeSort p2D = lambda x: print(*x, sep="\n") lambda x: print(*x, sep="\n") p2D int1 = lambda x: int(x) - 1 lambda x: int(x) - 1 int1 def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt) def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt) main
from bisect import bisect_right as br
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def MergeSort(aa, left=0, right=-1):
    def merge(aa, left2, mid2, right2):
        res=0
        inf = float("inf")
        L = aa[left2:mid2] + [inf]
        R = aa[mid2:right2] + [inf]
        Li = Ri = 0
        for ai in range(left2, right2):
            res+=1
            if L[Li] < R[Ri]:
                aa[ai] = L[Li]
                Li += 1
            else:
                aa[ai] = R[Ri]
                Ri += 1
        return res

    res=0
    if right == -1: right = len(aa)
    if left + 1 < right:
        mid = (left + right) // 2
        res+=MergeSort(aa, left, mid)
        res+=MergeSort(aa, mid, right)
        res+=merge(aa, left, mid, right)
    return res

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cnt=MergeSort(aa)
    print(*aa)
    print(cnt)
main()

