
def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1

def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right)

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

for i in range(len(s)-1):
      print(s[i], end = " ")
print(s[n-1])
print(count)
 def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1 merge global count n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = s[left:mid] + [1000000001] L s[left:mid] + [1000000001] s[left:mid] s left:mid left mid [1000000001] 1000000001 R = s[mid:right] + [1000000001] R s[mid:right] + [1000000001] s[mid:right] s mid:right mid right [1000000001] 1000000001 i = 0 i 0 j = 0 j 0 for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1 k range(left,right) range left right count += 1 count 1 if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j s[k] = L[i] s[k] s k L[i] L i i += 1 i 1 s[k] = R[j] s[k] s k R[j] R j j += 1 j 1 s s left left mid mid right right def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right) mergesort if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, 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(s, left, mid) mergesort s left mid mergesort(s, mid, right) mergesort s mid right merge(s, left, mid, right) merge s left mid right s s left left right right n = int(input()) n int(input()) int input() input count = 0 count 0 s = list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mergesort(s, 0, n) mergesort s 0 n for i in range(len(s)-1):
      print(s[i], end = " ") i range(len(s)-1) range len(s)-1 len(s) len s 1 print(s[i], end = " ") print s[i] s i end = " " end " " print(s[n-1]) print s[n-1] s n-1 n 1 print(count) print count n = int(input()) int(input()) n def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1 def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1 merge s = list(map(int, input().split())) list(map(int, input().split())) s def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right) def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right) mergesort count = 0 0 count

def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1

def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right)

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

for i in range(len(s)-1):
      print(s[i], end = " ")
print(s[n-1])
print(count)

