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

def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

  return swap_times

def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0

def mergeSort(A):
  return divide(A, 0, len(A))

swap = mergeSort(A)

print(" ".join([ str(i) for i in A]))
print(swap) 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 SWAP = 0 SWAP 0 def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

  return swap_times conquer L, R = A[left:mid], A[mid:right] L A[left:mid] A left:mid left mid R A[mid:right] A mid:right mid right INFTY = 2 ** 30 INFTY 2 ** 30 2 30 L.append(INFTY) L.append L append INFTY R.append(INFTY) R.append R append INFTY i, j = 0, 0 i 0 j 0 swap_times =  0 swap_times 0 for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

   k range(left, right) range left right if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      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 = i + 1 i i + 1 i 1 A[k] = R[j] A[k] A k R[j] R j j = j + 1 j j + 1 j 1 swap_times += 1 swap_times 1 return swap_times swap_times A A left left mid mid right right def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0 divide if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

   left+1 < right left+1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 countL = divide(A, left, mid) countL divide(A, left, mid) divide A left mid countR = divide(A, mid, right) countR divide(A, mid, right) divide A mid right return conquer(A, left, mid, right) + countL + countR conquer(A, left, mid, right) + countL + countR conquer(A, left, mid, right) + countL conquer(A, left, mid, right) conquer A left mid right countL countR return 0 0 A A left left right right def mergeSort(A):
  return divide(A, 0, len(A)) mergeSort return divide(A, 0, len(A)) divide(A, 0, len(A)) divide A 0 len(A) len A A A swap = mergeSort(A) swap mergeSort(A) mergeSort A str(i) for i in A for i in A i A for i in A str(i) str i print(" ".join([ str(i) for i in A])) print " ".join([ str(i) for i in A]) " ".join " " join [ str(i) for i in A] print(swap) print swap A = list(map(int, input().split())) list(map(int, input().split())) A def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0 def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0 divide n = int(input()) int(input()) n def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

  return swap_times def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

  return swap_times conquer SWAP = 0 0 SWAP def mergeSort(A):
  return divide(A, 0, len(A)) def mergeSort(A):
  return divide(A, 0, len(A)) mergeSort swap = mergeSort(A) mergeSort(A) swap
n = int(input())
A = list(map(int, input().split()))
SWAP = 0

def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
    swap_times += 1

  return swap_times

def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0

def mergeSort(A):
  return divide(A, 0, len(A))

swap = mergeSort(A)

print(" ".join([ str(i) for i in A]))
print(swap)
