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

cnt = 0

def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1

def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right)

mergesort(0, n)

print(*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 cnt = 0 cnt 0 def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1 merge global cnt n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = S[left:left+n1] L S[left:left+n1] S left:left+n1 left left+n1 left n1 R = S[mid:mid+n2] R S[mid:mid+n2] S mid:mid+n2 mid mid+n2 mid n2 L.append(10e10) L.append L append 10e10 R.append(10e10) R.append R append 10e10 for j in range(n2):
        R[j] = S[mid+j]
     j range(n2) range n2 R[j] = S[mid+j] R[j] R j S[mid+j] S mid+j mid j x = 0 x 0 y = 0 y 0 for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1 k range(left, right) range left right cnt += 1 cnt 1 if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1 L[x] < R[y] L[x] L x R[y] R y S[k] = L[x] S[k] S k L[x] L x x += 1 x 1 S[k] = R[y] S[k] S k R[y] R y y += 1 y 1 left left mid mid right right def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right) mergesort if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right) left+1 < right left+1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 mergesort(left, mid) mergesort left mid mergesort(mid, right) mergesort mid right merge(left, mid, right) merge left mid right left left right right mergesort(0, n) mergesort 0 n print(*S) print *S S print(cnt) print cnt cnt = 0 0 cnt n = int(input()) int(input()) n S = list(map(int, input().split())) list(map(int, input().split())) S def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right) def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right) mergesort def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1 def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1 merge
n = int(input())
S = list(map(int, input().split()))

cnt = 0

def merge(left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = S[left:left+n1]
    R = S[mid:mid+n2]
    L.append(10e10)
    R.append(10e10)
    for j in range(n2):
        R[j] = S[mid+j]
    x = 0
    y = 0
    for k in range(left, right):
        cnt += 1
        if L[x] < R[y]:
            S[k] = L[x]
            x += 1
        else:
            S[k] = R[y]
            y += 1

def mergesort(left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(left, mid)
        mergesort(mid, right)
        merge(left, mid, right)

mergesort(0, n)

print(*S)
print(cnt)
