import sys

def merge(A, left, mid, right):
  n1 = mid - left
  n2 = right - mid
  L = []
  R = []
  
  global count
  
  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])
  L.append('INFTY')
  R.append('INFTY')
  
  a = 0
  b = 0
  
  for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1

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


n = sys.stdin.readline()
n = int(n)


count = 0

data = sys.stdin.readline()
data_list = data.split(" ")

for i in range(n):
  data_list[i] = int(data_list[i])

mergeSort(data_list, 0, n)

for i in range(n):
  data_list[i] = str(data_list[i])

print " ".join(data_list)
print count import sys sys def merge(A, left, mid, right):
  n1 = mid - left
  n2 = right - mid
  L = []
  R = []
  
  global count
  
  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])
  L.append('INFTY')
  R.append('INFTY')
  
  a = 0
  b = 0
  
  for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1 merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = [] L [] R = [] R [] global count for i in range(n1):
    L.append(A[left + i])
   i range(n1) range n1 L.append(A[left + i]) L.append L append A[left + i] A left + i left i for i in range(n2):
    R.append(A[mid + i])
   i range(n2) range n2 R.append(A[mid + i]) R.append R append A[mid + i] A mid + i mid i L.append('INFTY') L.append L append 'INFTY' R.append('INFTY') R.append R append 'INFTY' a = 0 a 0 b = 0 b 0 for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1 k range(left, right) range left right if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
     L[a] <= R[b] L[a] L a R[b] R b A[k] = L[a] A[k] A k L[a] L a a += 1 a 1 A[k] = R[b] A[k] A k R[b] R b b += 1 b 1 count += 1 count 1 A A left left mid mid right right def mergeSort(A, left, right):
  if left + 1 < right:
    mid = (left + right) / 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    count = merge(A, left, mid, right) mergeSort if left + 1 < right:
    mid = (left + right) / 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    count = merge(A, 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(A, left, mid) mergeSort A left mid mergeSort(A, mid, right) mergeSort A mid right count = merge(A, left, mid, right) count merge(A, left, mid, right) merge A left mid right A A left left right right n = sys.stdin.readline() n sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline n = int(n) n int(n) int n count = 0 count 0 data = sys.stdin.readline() data sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline data_list = data.split(" ") data_list data.split(" ") data.split data split " " for i in range(n):
  data_list[i] = int(data_list[i]) i range(n) range n data_list[i] = int(data_list[i]) data_list[i] data_list i int(data_list[i]) int data_list[i] data_list i mergeSort(data_list, 0, n) mergeSort data_list 0 n for i in range(n):
  data_list[i] = str(data_list[i]) i range(n) range n data_list[i] = str(data_list[i]) data_list[i] data_list i str(data_list[i]) str data_list[i] data_list i print " ".join(data_list) " ".join " " join data_list print data_list = data.split(" ") data.split(" ") data_list def mergeSort(A, left, right):
  if left + 1 < right:
    mid = (left + right) / 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    count = merge(A, left, mid, right) def mergeSort(A, left, right):
  if left + 1 < right:
    mid = (left + right) / 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    count = merge(A, left, mid, right) mergeSort n = sys.stdin.readline() sys.stdin.readline() n data = sys.stdin.readline() sys.stdin.readline() data n = int(n) int(n) n def merge(A, left, mid, right):
  n1 = mid - left
  n2 = right - mid
  L = []
  R = []
  
  global count
  
  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])
  L.append('INFTY')
  R.append('INFTY')
  
  a = 0
  b = 0
  
  for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1 def merge(A, left, mid, right):
  n1 = mid - left
  n2 = right - mid
  L = []
  R = []
  
  global count
  
  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])
  L.append('INFTY')
  R.append('INFTY')
  
  a = 0
  b = 0
  
  for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1 merge count = 0 0 count
import sys

def merge(A, left, mid, right):
  n1 = mid - left
  n2 = right - mid
  L = []
  R = []
  
  global count
  
  for i in range(n1):
    L.append(A[left + i])
  for i in range(n2):
    R.append(A[mid + i])
  L.append('INFTY')
  R.append('INFTY')
  
  a = 0
  b = 0
  
  for k in range(left, right):
    if L[a] <= R[b]:
      A[k] = L[a]
      a += 1
    else:
      A[k] = R[b]
      b += 1
    count += 1

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


n = sys.stdin.readline()
n = int(n)


count = 0

data = sys.stdin.readline()
data_list = data.split(" ")

for i in range(n):
  data_list[i] = int(data_list[i])

mergeSort(data_list, 0, n)

for i in range(n):
  data_list[i] = str(data_list[i])

print " ".join(data_list)
print count