n = int(raw_input())
S = map(int, raw_input().split())
cnt = 0

def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    #L[:n1] = A[left:mid]
    #R[:n2] = A[mid:right]
    for i in xrange(n1):
        L[i] = A[left + i]
    for i in xrange(n2):
        R[i] = A[mid + i]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
    return 0

def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0

def main():
    mergeSort(S, 0, len(S))
    print ' '.join(map(str, S))
    print cnt
    return 0

main() n = int(raw_input()) n int(raw_input()) int raw_input() raw_input S = map(int, raw_input().split()) S map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split cnt = 0 cnt 0 def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    #L[:n1] = A[left:mid]
    #R[:n2] = A[mid:right]
    for i in xrange(n1):
        L[i] = A[left + i]
    for i in xrange(n2):
        R[i] = A[mid + i]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
    return 0 merge global cnt 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 xrange(n1):
        L[i] = A[left + i]
     i xrange(n1) xrange n1 L[i] = A[left + i] L[i] L i A[left + i] A left + i left i for i in xrange(n2):
        R[i] = A[mid + i]
     i xrange(n2) xrange 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 xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
     k xrange(left,right) xrange left right if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 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 cnt += 1 cnt 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 cnt += 1 cnt 1 return 0 0 A A left left mid mid right right def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0 mergeSort if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
     right - left > 1 right - left right left 1 mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 mergeSort(A, left, mid) mergeSort A left mid mergeSort(A, mid, right) mergeSort A mid right merge(A, left, mid, right) merge A left mid right return 0 0 A A left left right right def main():
    mergeSort(S, 0, len(S))
    print ' '.join(map(str, S))
    print cnt
    return 0 main mergeSort(S, 0, len(S)) mergeSort S 0 len(S) len S print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print return 0 0 main() main n = int(raw_input()) int(raw_input()) n def main():
    mergeSort(S, 0, len(S))
    print ' '.join(map(str, S))
    print cnt
    return 0 def main():
    mergeSort(S, 0, len(S))
    print ' '.join(map(str, S))
    print cnt
    return 0 main def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    #L[:n1] = A[left:mid]
    #R[:n2] = A[mid:right]
    for i in xrange(n1):
        L[i] = A[left + i]
    for i in xrange(n2):
        R[i] = A[mid + i]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
    return 0 def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    #L[:n1] = A[left:mid]
    #R[:n2] = A[mid:right]
    for i in xrange(n1):
        L[i] = A[left + i]
    for i in xrange(n2):
        R[i] = A[mid + i]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
    return 0 merge cnt = 0 0 cnt def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0 def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0 mergeSort S = map(int, raw_input().split()) map(int, raw_input().split()) S
n = int(raw_input())
S = map(int, raw_input().split())
cnt = 0

def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    #L[:n1] = A[left:mid]
    #R[:n2] = A[mid:right]
    for i in xrange(n1):
        L[i] = A[left + i]
    for i in xrange(n2):
        R[i] = A[mid + i]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
            cnt += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += 1
    return 0

def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0

def main():
    mergeSort(S, 0, len(S))
    print ' '.join(map(str, S))
    print cnt
    return 0

main()