import math

class MergeSort:
    cnt = 0
    def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
    def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a

if __name__ == '__main__':
    n = int(input().rstrip())
    s = [int(i) for i in input().rstrip().split(" ")]
    x = MergeSort()
    print(" ".join(map(str, x.mergeSort(s, n, 0, n))))
    print(x.cnt) import math math class MergeSort:
    cnt = 0
    def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
    def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a MergeSort cnt = 0 cnt 0 def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
     merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid l = a[left:(left+n1)] l a[left:(left+n1)] a left:(left+n1) left left+n1 left n1 r = a[mid:(mid+n2)] r a[mid:(mid+n2)] a mid:(mid+n2) mid mid+n2 mid n2 l.append(2000000000) l.append l append 2000000000 r.append(2000000000) r.append r append 2000000000 i = 0 i 0 j = 0 j 0 for k in range(left, right):
            self.cnt += 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 self.cnt += 1 self.cnt self cnt 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 return a a self self a a n n left left mid mid right right def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a mergeSort if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
         left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 self.mergeSort(a, n, left, mid) self.mergeSort self mergeSort a n left mid self.mergeSort(a, n, mid, right) self.mergeSort self mergeSort a n mid right self.merge(a, n, left, mid, right) self.merge self merge a n left mid right return a a self self a a n n left left right right if __name__ == '__main__':
    n = int(input().rstrip())
    s = [int(i) for i in input().rstrip().split(" ")]
    x = MergeSort()
    print(" ".join(map(str, x.mergeSort(s, n, 0, n))))
    print(x.cnt) __name__ == '__main__' __name__ '__main__' n = int(input().rstrip()) n int(input().rstrip()) int input().rstrip() ().rstrip () input rstrip int(i) for i in input().rstrip().split(" ") for i in input().rstrip().split(" ") i input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " for i in input().rstrip().split(" ") int(i) int i s = [int(i) for i in input().rstrip().split(" ")] s [int(i) for i in input().rstrip().split(" ")] x = MergeSort() x MergeSort() MergeSort print(" ".join(map(str, x.mergeSort(s, n, 0, n)))) print " ".join(map(str, x.mergeSort(s, n, 0, n))) " ".join " " join map(str, x.mergeSort(s, n, 0, n)) map str x.mergeSort(s, n, 0, n) x.mergeSort x mergeSort s n 0 n print(x.cnt) print x.cnt x cnt class MergeSort:
    cnt = 0
    def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
    def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a class MergeSort:
    cnt = 0
    def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
    def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a MergeSort s = [int(i) for i in input().rstrip().split(" ")] [int(i) for i in input().rstrip().split(" ")] s n = int(input().rstrip()) int(input().rstrip()) n x = MergeSort() MergeSort() x
import math

class MergeSort:
    cnt = 0
    def merge(self, a, n, left, mid, right): 
        n1 = mid - left
        n2 = right - mid
        l = a[left:(left+n1)]
        r = a[mid:(mid+n2)]
        l.append(2000000000)
        r.append(2000000000)
        i = 0
        j = 0
        for k in range(left, right):
            self.cnt += 1
            if l[i] <= r[j]:
                a[k] = l[i]
                i += 1
            else:
                a[k] = r[j]
                j += 1
        return a
        
    def mergeSort(self, a, n, left, right):
        if left + 1 < right:
            mid = (left + right) // 2
            self.mergeSort(a, n, left, mid)
            self.mergeSort(a, n, mid, right)
            self.merge(a, n, left, mid, right)
        return a

if __name__ == '__main__':
    n = int(input().rstrip())
    s = [int(i) for i in input().rstrip().split(" ")]
    x = MergeSort()
    print(" ".join(map(str, x.mergeSort(s, n, 0, n))))
    print(x.cnt)