import sys
MAXINT = 1000000001

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


def merge(A, l, m, r, cnt):
  n1 = m - l
  n2 = r - m
  L = [A[i] for i in range(l, l+n1)]
  R = [A[i] for i in range(m, m+n2)]
  L.append(MAXINT)
  R.append(MAXINT)
  i = 0
  j = 0
  for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  return cnt


def mergesort(A, l, r, cnt):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
  return cnt

cnt = 0
cnt = mergesort(S, 0, n, cnt)
print(" ".join(map(str,S)))
print(cnt)

 import sys sys MAXINT = 1000000001 MAXINT 1000000001 n = int(input()) n int(input()) int input() input S = list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def merge(A, l, m, r, cnt):
  n1 = m - l
  n2 = r - m
  L = [A[i] for i in range(l, l+n1)]
  R = [A[i] for i in range(m, m+n2)]
  L.append(MAXINT)
  R.append(MAXINT)
  i = 0
  j = 0
  for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  return cnt merge n1 = m - l n1 m - l m l n2 = r - m n2 r - m r m A[i] for i in range(l, l+n1) for i in range(l, l+n1) i range(l, l+n1) range l l+n1 l n1 for i in range(l, l+n1) A[i] A i L = [A[i] for i in range(l, l+n1)] L [A[i] for i in range(l, l+n1)] A[i] for i in range(m, m+n2) for i in range(m, m+n2) i range(m, m+n2) range m m+n2 m n2 for i in range(m, m+n2) A[i] A i R = [A[i] for i in range(m, m+n2)] R [A[i] for i in range(m, m+n2)] L.append(MAXINT) L.append L append MAXINT R.append(MAXINT) R.append R append MAXINT i = 0 i 0 j = 0 j 0 for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
   k range(l,r) range l r cnt += 1 cnt 1 if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[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 += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 return cnt cnt A A l l m m r r cnt cnt def mergesort(A, l, r, cnt):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
  return cnt mergesort if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
   l + 1 < r l + 1 l 1 r m = (l + r) // 2 m (l + r) // 2 l + r l r 2 cnt = mergesort(A, l, m, cnt) cnt mergesort(A, l, m, cnt) mergesort A l m cnt cnt = mergesort(A, m, r, cnt) cnt mergesort(A, m, r, cnt) mergesort A m r cnt cnt = merge(A,l,m,r, cnt) cnt merge(A,l,m,r, cnt) merge A l m r cnt return cnt cnt A A l l r r cnt cnt cnt = 0 cnt 0 cnt = mergesort(S, 0, n, cnt) cnt mergesort(S, 0, n, cnt) mergesort S 0 n cnt print(" ".join(map(str,S))) print " ".join(map(str,S)) " ".join " " join map(str,S) map str S print(cnt) print cnt n = int(input()) int(input()) n S = list(map(int,input().split())) list(map(int,input().split())) S cnt = mergesort(S, 0, n, cnt) mergesort(S, 0, n, cnt) cnt MAXINT = 1000000001 1000000001 MAXINT cnt = 0 0 cnt def mergesort(A, l, r, cnt):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
  return cnt def mergesort(A, l, r, cnt):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
  return cnt mergesort def merge(A, l, m, r, cnt):
  n1 = m - l
  n2 = r - m
  L = [A[i] for i in range(l, l+n1)]
  R = [A[i] for i in range(m, m+n2)]
  L.append(MAXINT)
  R.append(MAXINT)
  i = 0
  j = 0
  for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  return cnt def merge(A, l, m, r, cnt):
  n1 = m - l
  n2 = r - m
  L = [A[i] for i in range(l, l+n1)]
  R = [A[i] for i in range(m, m+n2)]
  L.append(MAXINT)
  R.append(MAXINT)
  i = 0
  j = 0
  for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  return cnt merge
import sys
MAXINT = 1000000001

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


def merge(A, l, m, r, cnt):
  n1 = m - l
  n2 = r - m
  L = [A[i] for i in range(l, l+n1)]
  R = [A[i] for i in range(m, m+n2)]
  L.append(MAXINT)
  R.append(MAXINT)
  i = 0
  j = 0
  for k in range(l,r):
    cnt += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  return cnt


def mergesort(A, l, r, cnt):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = mergesort(A, l, m, cnt)
    cnt = mergesort(A, m, r, cnt)
    cnt = merge(A,l,m,r, cnt)
  return cnt

cnt = 0
cnt = mergesort(S, 0, n, cnt)
print(" ".join(map(str,S)))
print(cnt)


