count = 0

def merge(array, left, mid, right):
  global count

  n1 = int(mid - left)
  n2 = int(right - mid)

  l = array[left:mid]
  r = array[mid:right]
  
  l.append(9999999999)
  r.append(9999999999)

  i, j = 0, 0

  for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1

def mergeSort(array, left, right):
  if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right)

n = int(input())
array = [int(i) for i in input().split()]
mergeSort(array, 0, n)
print(*array)
print(count)
 count = 0 count 0 def merge(array, left, mid, right):
  global count

  n1 = int(mid - left)
  n2 = int(right - mid)

  l = array[left:mid]
  r = array[mid:right]
  
  l.append(9999999999)
  r.append(9999999999)

  i, j = 0, 0

  for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1 merge global count n1 = int(mid - left) n1 int(mid - left) int mid - left mid left n2 = int(right - mid) n2 int(right - mid) int right - mid right mid l = array[left:mid] l array[left:mid] array left:mid left mid r = array[mid:right] r array[mid:right] array mid:right mid right l.append(9999999999) l.append l append 9999999999 r.append(9999999999) r.append r append 9999999999 i, j = 0, 0 i 0 j 0 for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1 k range(left, right) range left right count += 1 count 1 if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1 l[i] <= r[j] l[i] l i r[j] r j array[k] = l[i] array[k] array k l[i] l i i += 1 i 1 array[k] = r[j] array[k] array k r[j] r j j += 1 j 1 array array left left mid mid right right def mergeSort(array, left, right):
  if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right) mergeSort if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right) left + 1 < right left + 1 left 1 right mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 mergeSort(array, left, mid) mergeSort array left mid mergeSort(array, mid, right) mergeSort array mid right merge(array, left, mid, right) merge array left mid right array array left left right right n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i array = [int(i) for i in input().split()] array [int(i) for i in input().split()] mergeSort(array, 0, n) mergeSort array 0 n print(*array) print *array array print(count) print count count = 0 0 count array = [int(i) for i in input().split()] [int(i) for i in input().split()] array def merge(array, left, mid, right):
  global count

  n1 = int(mid - left)
  n2 = int(right - mid)

  l = array[left:mid]
  r = array[mid:right]
  
  l.append(9999999999)
  r.append(9999999999)

  i, j = 0, 0

  for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1 def merge(array, left, mid, right):
  global count

  n1 = int(mid - left)
  n2 = int(right - mid)

  l = array[left:mid]
  r = array[mid:right]
  
  l.append(9999999999)
  r.append(9999999999)

  i, j = 0, 0

  for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1 merge def mergeSort(array, left, right):
  if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right) def mergeSort(array, left, right):
  if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right) mergeSort n = int(input()) int(input()) n
count = 0

def merge(array, left, mid, right):
  global count

  n1 = int(mid - left)
  n2 = int(right - mid)

  l = array[left:mid]
  r = array[mid:right]
  
  l.append(9999999999)
  r.append(9999999999)

  i, j = 0, 0

  for k in range(left, right):
    count += 1
    if l[i] <= r[j]:
      array[k] = l[i]
      i += 1
    else:
      array[k] = r[j]
      j += 1

def mergeSort(array, left, right):
  if left + 1 < right:
    mid = int((left + right) / 2)
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right)

n = int(input())
array = [int(i) for i in input().split()]
mergeSort(array, 0, n)
print(*array)
print(count)

