n = int(input())
s = list(map(int, input().split()))
count = 0

def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count)

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)

def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1


if __name__ == '__main__':
    main()
 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 count = 0 count 0 def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count) main mergeSort(s, 0, n) mergeSort s 0 n print(' '.join(map(str, s))) print ' '.join(map(str, s)) ' '.join ' ' join map(str, s) map str s print(count) print count 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 def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1 merge global count 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 i = 0 i 0 j = 0 j 0 l.append(float('inf')) l.append l append float('inf') float 'inf' r.append(float('inf')) r.append r append float('inf') float 'inf' for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1 k range(left, right, 1) range left right 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 count += 1 count 1 a a left left mid mid right right if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1 def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1 merge n = int(input()) int(input()) n 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) 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 def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count) def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count) main s = list(map(int, input().split())) list(map(int, input().split())) s count = 0 0 count
n = int(input())
s = list(map(int, input().split()))
count = 0

def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count)

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)

def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1


if __name__ == '__main__':
    main()

