n = int(input())
A = list(map(int, input().split()))

count = 0

inf = 999999999999999999

def mergeSort(left, right):
  if right - left <= 1:
    return A[left:right]
  mid = (left + right) // 2
  return merge(mergeSort(left, mid), mergeSort(mid, right))

def merge(left, right):
  global count
  result = []
  
  left.append(inf)
  right.append(inf)
  left_i = 0
  right_i = 0
  while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
  return result

print(*mergeSort(0, n))
print(count) n = int(input()) n int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split count = 0 count 0 inf = 999999999999999999 inf 999999999999999999 def mergeSort(left, right):
  if right - left <= 1:
    return A[left:right]
  mid = (left + right) // 2
  return merge(mergeSort(left, mid), mergeSort(mid, right)) mergeSort if right - left <= 1:
    return A[left:right]
   right - left <= 1 right - left right left 1 return A[left:right] A[left:right] A left:right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 return merge(mergeSort(left, mid), mergeSort(mid, right)) merge(mergeSort(left, mid), mergeSort(mid, right)) merge mergeSort(left, mid) mergeSort left mid mergeSort(mid, right) mergeSort mid right left left right right def merge(left, right):
  global count
  result = []
  
  left.append(inf)
  right.append(inf)
  left_i = 0
  right_i = 0
  while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
  return result merge global count result = [] result [] left.append(inf) left.append left append inf right.append(inf) right.append right append inf left_i = 0 left_i 0 right_i = 0 right_i 0 while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
   True if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
     right[right_i] == inf right[right_i] right right_i inf result.extend(left[left_i:-1]) result.extend result extend left[left_i:-1] left left_i:-1 left_i -1 count += len(left[left_i:-1]) count len(left[left_i:-1]) len left[left_i:-1] left left_i:-1 left_i -1 break if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

     left[left_i] == inf left[left_i] left left_i inf result.extend(right[right_i:-1]) result.extend result extend right[right_i:-1] right right_i:-1 right_i -1 count += len(right[right_i:-1]) count len(right[right_i:-1]) len right[right_i:-1] right right_i:-1 right_i -1 break if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
     left[left_i] < right[right_i] left[left_i] left left_i right[right_i] right right_i result.append(left[left_i]) result.append result append left[left_i] left left_i left_i += 1 left_i 1 result.append(right[right_i]) result.append result append right[right_i] right right_i right_i += 1 right_i 1 count += 1 count 1 return result result left left right right print(*mergeSort(0, n)) print *mergeSort(0, n) mergeSort(0, n) mergeSort 0 n print(count) print count def merge(left, right):
  global count
  result = []
  
  left.append(inf)
  right.append(inf)
  left_i = 0
  right_i = 0
  while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
  return result def merge(left, right):
  global count
  result = []
  
  left.append(inf)
  right.append(inf)
  left_i = 0
  right_i = 0
  while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
  return result merge count = 0 0 count def mergeSort(left, right):
  if right - left <= 1:
    return A[left:right]
  mid = (left + right) // 2
  return merge(mergeSort(left, mid), mergeSort(mid, right)) def mergeSort(left, right):
  if right - left <= 1:
    return A[left:right]
  mid = (left + right) // 2
  return merge(mergeSort(left, mid), mergeSort(mid, right)) mergeSort n = int(input()) int(input()) n A = list(map(int, input().split())) list(map(int, input().split())) A inf = 999999999999999999 999999999999999999 inf
n = int(input())
A = list(map(int, input().split()))

count = 0

inf = 999999999999999999

def mergeSort(left, right):
  if right - left <= 1:
    return A[left:right]
  mid = (left + right) // 2
  return merge(mergeSort(left, mid), mergeSort(mid, right))

def merge(left, right):
  global count
  result = []
  
  left.append(inf)
  right.append(inf)
  left_i = 0
  right_i = 0
  while True:
    if right[right_i] == inf:
      result.extend(left[left_i:-1])
      count += len(left[left_i:-1])
      break
    if left[left_i] == inf:
      result.extend(right[right_i:-1])
      count += len(right[right_i:-1])
      break

    if left[left_i] < right[right_i]:
      result.append(left[left_i])
      left_i += 1
    else:
      result.append(right[right_i])
      right_i += 1
    count += 1
  return result

print(*mergeSort(0, n))
print(count)
