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

def merge(A, left, mid, right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = float("inf")
    R[n2] = float("inf")
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return cnt
            
def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
    return cnt

cnt = merge_sort(S, 0, n)
print(' '.join( map(str, S) ))
print(cnt) 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, left, mid, right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = float("inf")
    R[n2] = float("inf")
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return cnt
             merge cnt = 0 cnt 0 n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = [0]*(n1+1) L [0]*(n1+1) [0] 0 n1+1 n1 1 R = [0]*(n2+1) R [0]*(n2+1) [0] 0 n2+1 n2 1 for i in range(n1):
        L[i] = A[left + i]
     i range(n1) range n1 L[i] = A[left + i] L[i] L i A[left + i] A left + i left i for i in range(n2):
        R[i] = A[mid + i]
     i range(n2) range n2 R[i] = A[mid + i] R[i] R i A[mid + i] A mid + i mid i L[n1] = float("inf") L[n1] L n1 float("inf") float "inf" R[n2] = float("inf") R[n2] R n2 float("inf") float "inf" i = 0 i 0 j = 0 j 0 for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     k range(left, right) range left right 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 left left mid mid right right def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
    return cnt merge_sort if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
     left + 1 < right left + 1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 cnt_left = merge_sort(A, left, mid) cnt_left merge_sort(A, left, mid) merge_sort A left mid cnt_right = merge_sort(A, mid, right) cnt_right merge_sort(A, mid, right) merge_sort A mid right cnt_merge = merge(A, left, mid, right) cnt_merge merge(A, left, mid, right) merge A left mid right cnt = cnt_left + cnt_right + cnt_merge cnt cnt_left + cnt_right + cnt_merge cnt_left + cnt_right cnt_left cnt_right cnt_merge cnt = 0 cnt 0 return cnt cnt A A left left right right cnt = merge_sort(S, 0, n) cnt merge_sort(S, 0, n) merge_sort S 0 n 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 = merge_sort(S, 0, n) merge_sort(S, 0, n) cnt def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
    return cnt def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
    return cnt merge_sort def merge(A, left, mid, right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = float("inf")
    R[n2] = float("inf")
    i = 0
    j = 0
    for k in range(left, right):
        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, left, mid, right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = float("inf")
    R[n2] = float("inf")
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return cnt
             merge
n = int(input())
S = list(map(int, input().split()))

def merge(A, left, mid, right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = float("inf")
    R[n2] = float("inf")
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return cnt
            
def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        cnt_left = merge_sort(A, left, mid)
        cnt_right = merge_sort(A, mid, right)
        cnt_merge = merge(A, left, mid, right)
        cnt = cnt_left + cnt_right + cnt_merge
    else:
        cnt = 0
    return cnt

cnt = merge_sort(S, 0, n)
print(' '.join( map(str, S) ))
print(cnt)
