N = int(input())
S = [int(s) for s in input().split()]

snt = 10 ** 9 + 1
cnt = 0

# L, R = [0] * 500000, [0] * 500000

def merge(S, N, left, mid, right):
    global cnt
    # N1 = mid - left
    # N2 = right - mid
    # for i in range(N1):
    #     L[i] = S[left + i]
    # for i in range(N2):
    #     R[i] = S[mid + i]
    # L[N1] = R[N2] = snt
    L = S[left:mid] + [snt]
    R = S[mid:right] + [snt]
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

def merge_sort(S, N, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right)

merge_sort(S, N, 0, N)

print(*S)
print(cnt) N = int(input()) N int(input()) int input() input int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s S = [int(s) for s in input().split()] S [int(s) for s in input().split()] snt = 10 ** 9 + 1 snt 10 ** 9 + 1 10 ** 9 10 9 1 cnt = 0 cnt 0 def merge(S, N, left, mid, right):
    global cnt
    # N1 = mid - left
    # N2 = right - mid
    # for i in range(N1):
    #     L[i] = S[left + i]
    # for i in range(N2):
    #     R[i] = S[mid + i]
    # L[N1] = R[N2] = snt
    L = S[left:mid] + [snt]
    R = S[mid:right] + [snt]
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 merge global cnt L = S[left:mid] + [snt] L S[left:mid] + [snt] S[left:mid] S left:mid left mid [snt] snt R = S[mid:right] + [snt] R S[mid:right] + [snt] S[mid:right] S mid:right mid right [snt] snt i, j = 0, 0 i 0 j 0 for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 k range(left, right) range left right cnt += 1 cnt 1 if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j S[k] = L[i] S[k] S k L[i] L i i += 1 i 1 S[k] = R[j] S[k] S k R[j] R j j += 1 j 1 S S N N left left mid mid right right def merge_sort(S, N, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right) merge_sort if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right) 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 merge_sort(S, N, left, mid) merge_sort S N left mid merge_sort(S, N, mid, right) merge_sort S N mid right merge(S, N, left, mid, right) merge S N left mid right S S N N left left right right merge_sort(S, N, 0, N) merge_sort S N 0 N print(*S) print *S S print(cnt) print cnt cnt = 0 0 cnt N = int(input()) int(input()) N def merge(S, N, left, mid, right):
    global cnt
    # N1 = mid - left
    # N2 = right - mid
    # for i in range(N1):
    #     L[i] = S[left + i]
    # for i in range(N2):
    #     R[i] = S[mid + i]
    # L[N1] = R[N2] = snt
    L = S[left:mid] + [snt]
    R = S[mid:right] + [snt]
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 def merge(S, N, left, mid, right):
    global cnt
    # N1 = mid - left
    # N2 = right - mid
    # for i in range(N1):
    #     L[i] = S[left + i]
    # for i in range(N2):
    #     R[i] = S[mid + i]
    # L[N1] = R[N2] = snt
    L = S[left:mid] + [snt]
    R = S[mid:right] + [snt]
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1 merge def merge_sort(S, N, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right) def merge_sort(S, N, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right) merge_sort snt = 10 ** 9 + 1 10 ** 9 + 1 snt S = [int(s) for s in input().split()] [int(s) for s in input().split()] S
N = int(input())
S = [int(s) for s in input().split()]

snt = 10 ** 9 + 1
cnt = 0

# L, R = [0] * 500000, [0] * 500000

def merge(S, N, left, mid, right):
    global cnt
    # N1 = mid - left
    # N2 = right - mid
    # for i in range(N1):
    #     L[i] = S[left + i]
    # for i in range(N2):
    #     R[i] = S[mid + i]
    # L[N1] = R[N2] = snt
    L = S[left:mid] + [snt]
    R = S[mid:right] + [snt]
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

def merge_sort(S, N, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(S, N, left, mid)
        merge_sort(S, N, mid, right)
        merge(S, N, left, mid, right)

merge_sort(S, N, 0, N)

print(*S)
print(cnt)
