cnt = 0


def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b


def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right)

n = int(input())
l = list(map(int,input().split()))
merge_sort(l,0,n-1)
for i in range(n-1):
    print(l[i],end = ' ')
print(l[-1])
print(cnt) cnt = 0 cnt 0 def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b merge global cnt i = left i left j = mid+1 j mid+1 mid 1 b = [] b [] while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
     i <= mid and j <= right i <= mid i mid j <= right j right if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
     a[i] <= a[j] a[i] a i a[j] a j cnt+=1 cnt 1 b.append(a[i]) b.append b append a[i] a i i += 1 i 1 cnt+=1 cnt 1 b.append(a[j]) b.append b append a[j] a j j += 1 j 1 if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
     i == mid+1 i mid+1 mid 1 while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
     j <= right j right cnt+=1 cnt 1 b.append(a[j]) b.append b append a[j] a j j += 1 j 1 while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
     i <= mid i mid cnt+=1 cnt 1 b.append(a[i]) b.append b append a[i] a i i += 1 i 1 a[left:right+1] = b a[left:right+1] a left:right+1 left right+1 right 1 b a a left left mid mid right right def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right) merge_sort if left == right:
        return

     left == right left right return mid = (left+right)//2 mid (left+right)//2 left+right left right 2 merge_sort(a, left, mid) merge_sort a left mid merge_sort(a, mid+1, right) merge_sort a mid+1 mid 1 right merge(a, left, mid, right) merge a left mid right a a left left right right n = int(input()) n int(input()) int input() input l = list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split merge_sort(l,0,n-1) merge_sort l 0 n-1 n 1 for i in range(n-1):
    print(l[i],end = ' ') i range(n-1) range n-1 n 1 print(l[i],end = ' ') print l[i] l i end = ' ' end ' ' print(l[-1]) print l[-1] l -1 print(cnt) print cnt n = int(input()) int(input()) n def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right) def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right) merge_sort def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b merge cnt = 0 0 cnt l = list(map(int,input().split())) list(map(int,input().split())) l
cnt = 0


def merge(a, left, mid, right):
    global cnt
    i = left
    j = mid+1
    b = []
    while i <= mid and j <= right:
        if a[i] <= a[j]:
            cnt+=1
            b.append(a[i])
            i += 1
        else:
            cnt+=1
            b.append(a[j])
            j += 1
    if i == mid+1:
        while j <= right:
            cnt+=1
            b.append(a[j])
            j += 1
    else:
        while i <= mid:
            cnt+=1
            b.append(a[i])
            i += 1
    a[left:right+1] = b


def merge_sort(a, left, right):
    if left == right:
        return

    mid = (left+right)//2
    merge_sort(a, left, mid)
    merge_sort(a, mid+1, right)
    merge(a, left, mid, right)

n = int(input())
l = list(map(int,input().split()))
merge_sort(l,0,n-1)
for i in range(n-1):
    print(l[i],end = ' ')
print(l[-1])
print(cnt)
