#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????????????????????Merge Sort??????????????±??????????????\??????????????¢?????´???????????§???
?¬?????????????????£????????????¨?????§????????????

merge(A, left, mid, right)
  n1 = mid - left;
  n2 = right - mid;
  L[0...n1], R[0...n2] ?????????
  for i = 0 to n1-1
    L[i] = A[left + i]
  for i = 0 to n2-1
    R[i] = A[mid + i]
  L[n1] = INFTY
  R[n2] = INFTY
  i = 0
  j = 0
  for k = left to right-1
    if L[i] <= R[j]
      A[k] = L[i]
      i = i + 1
    else 
      A[k] = R[j]
      j = j + 1

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

n ????????´??°???????????°??? S ????????????????????????????????£???????????????????????§
???????????´?????????????????°????????????????????????????????????
?????????merge???????????????????????°????????°?????±????????????????????????
"""

MAX = 1000000001

def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid

#    L = []
#    R = []
#    for i in range(n1):
#        L.append(A[left + i])
#
#    for i in range(n2):
#        R.append(A[mid + i])

    L = A[left:mid]
    R = A[mid:right]

    L.append(MAX)
    R.append(MAX)
#    print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2))
#    print("left:{} right:{}".format(L,R))
    i = 0
    j = 0
    for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1
    return cnt

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

def main():
    """ ????????? """
    n = int(input())
    S = list(map(int,input().split()))
    cnt = mergeSort(S, 0, n, 0)
    print(" ".join(map(str,S)))
    print(cnt)

if __name__ == '__main__':
    main() """
?????????????????????Merge Sort??????????????±??????????????\??????????????¢?????´???????????§???
?¬?????????????????£????????????¨?????§????????????

merge(A, left, mid, right)
  n1 = mid - left;
  n2 = right - mid;
  L[0...n1], R[0...n2] ?????????
  for i = 0 to n1-1
    L[i] = A[left + i]
  for i = 0 to n2-1
    R[i] = A[mid + i]
  L[n1] = INFTY
  R[n2] = INFTY
  i = 0
  j = 0
  for k = left to right-1
    if L[i] <= R[j]
      A[k] = L[i]
      i = i + 1
    else 
      A[k] = R[j]
      j = j + 1

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

n ????????´??°???????????°??? S ????????????????????????????????£???????????????????????§
???????????´?????????????????°????????????????????????????????????
?????????merge???????????????????????°????????°?????±????????????????????????
""" MAX = 1000000001 MAX 1000000001 def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid

#    L = []
#    R = []
#    for i in range(n1):
#        L.append(A[left + i])
#
#    for i in range(n2):
#        R.append(A[mid + i])

    L = A[left:mid]
    R = A[mid:right]

    L.append(MAX)
    R.append(MAX)
#    print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2))
#    print("left:{} right:{}".format(L,R))
    i = 0
    j = 0
    for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1
    return cnt merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = A[left:mid] L A[left:mid] A left:mid left mid R = A[mid:right] R A[mid:right] A mid:right mid right L.append(MAX) L.append L append MAX R.append(MAX) R.append R append MAX i = 0 i 0 j = 0 j 0 for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 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 cnt += 1 cnt 1 return cnt cnt A A left left mid mid right right cnt cnt def mergeSort(A, left, right, cnt):
    if left + 1 < right:
        mid = int((left + right) / 2)
        cnt = mergeSort(A, left, mid, cnt)
        cnt = mergeSort(A, mid, right, cnt)
        cnt = merge(A, left, mid, right, cnt)
    return cnt mergeSort if left + 1 < right:
        mid = int((left + right) / 2)
        cnt = mergeSort(A, left, mid, cnt)
        cnt = mergeSort(A, mid, right, cnt)
        cnt = merge(A, left, mid, right, cnt)
     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 cnt = mergeSort(A, left, mid, cnt) cnt mergeSort(A, left, mid, cnt) mergeSort A left mid cnt cnt = mergeSort(A, mid, right, cnt) cnt mergeSort(A, mid, right, cnt) mergeSort A mid right cnt cnt = merge(A, left, mid, right, cnt) cnt merge(A, left, mid, right, cnt) merge A left mid right cnt return cnt cnt A A left left right right cnt cnt def main():
    """ ????????? """
    n = int(input())
    S = list(map(int,input().split()))
    cnt = mergeSort(S, 0, n, 0)
    print(" ".join(map(str,S)))
    print(cnt) main """ ????????? """ 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 cnt = mergeSort(S, 0, n, 0) cnt mergeSort(S, 0, n, 0) mergeSort S 0 n 0 print(" ".join(map(str,S))) print " ".join(map(str,S)) " ".join " " join map(str,S) map str S print(cnt) print cnt if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid

#    L = []
#    R = []
#    for i in range(n1):
#        L.append(A[left + i])
#
#    for i in range(n2):
#        R.append(A[mid + i])

    L = A[left:mid]
    R = A[mid:right]

    L.append(MAX)
    R.append(MAX)
#    print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2))
#    print("left:{} right:{}".format(L,R))
    i = 0
    j = 0
    for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1
    return cnt def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid

#    L = []
#    R = []
#    for i in range(n1):
#        L.append(A[left + i])
#
#    for i in range(n2):
#        R.append(A[mid + i])

    L = A[left:mid]
    R = A[mid:right]

    L.append(MAX)
    R.append(MAX)
#    print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2))
#    print("left:{} right:{}".format(L,R))
    i = 0
    j = 0
    for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1
    return cnt merge def main():
    """ ????????? """
    n = int(input())
    S = list(map(int,input().split()))
    cnt = mergeSort(S, 0, n, 0)
    print(" ".join(map(str,S)))
    print(cnt) def main():
    """ ????????? """
    n = int(input())
    S = list(map(int,input().split()))
    cnt = mergeSort(S, 0, n, 0)
    print(" ".join(map(str,S)))
    print(cnt) main MAX = 1000000001 1000000001 MAX def mergeSort(A, left, right, cnt):
    if left + 1 < right:
        mid = int((left + right) / 2)
        cnt = mergeSort(A, left, mid, cnt)
        cnt = mergeSort(A, mid, right, cnt)
        cnt = merge(A, left, mid, right, cnt)
    return cnt def mergeSort(A, left, right, cnt):
    if left + 1 < right:
        mid = int((left + right) / 2)
        cnt = mergeSort(A, left, mid, cnt)
        cnt = mergeSort(A, mid, right, cnt)
        cnt = merge(A, left, mid, right, cnt)
    return cnt mergeSort
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????????????????????Merge Sort??????????????±??????????????\??????????????¢?????´???????????§???
?¬?????????????????£????????????¨?????§????????????

merge(A, left, mid, right)
  n1 = mid - left;
  n2 = right - mid;
  L[0...n1], R[0...n2] ?????????
  for i = 0 to n1-1
    L[i] = A[left + i]
  for i = 0 to n2-1
    R[i] = A[mid + i]
  L[n1] = INFTY
  R[n2] = INFTY
  i = 0
  j = 0
  for k = left to right-1
    if L[i] <= R[j]
      A[k] = L[i]
      i = i + 1
    else 
      A[k] = R[j]
      j = j + 1

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

n ????????´??°???????????°??? S ????????????????????????????????£???????????????????????§
???????????´?????????????????°????????????????????????????????????
?????????merge???????????????????????°????????°?????±????????????????????????
"""

MAX = 1000000001

def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid

#    L = []
#    R = []
#    for i in range(n1):
#        L.append(A[left + i])
#
#    for i in range(n2):
#        R.append(A[mid + i])

    L = A[left:mid]
    R = A[mid:right]

    L.append(MAX)
    R.append(MAX)
#    print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2))
#    print("left:{} right:{}".format(L,R))
    i = 0
    j = 0
    for k in range(left, right):
#        print("k:{} i:{} j:{}".format(k,i,j))
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        cnt += 1
    return cnt

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

def main():
    """ ????????? """
    n = int(input())
    S = list(map(int,input().split()))
    cnt = mergeSort(S, 0, n, 0)
    print(" ".join(map(str,S)))
    print(cnt)

if __name__ == '__main__':
    main()