cp = 0
def m(L,R):
    global cp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    cp += len(L) + len(R)
def merge(A):
    global cp
    if len(A) == 1:
        return A
    if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A
n=int(input())
A=[int(i) for i in input().rstrip().split(" ")]
B = merge(A)
print(*B)
print(cp) cp = 0 cp 0 def m(L,R):
    global cp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    cp += len(L) + len(R) m global cp j = 0 j 0 for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
     l L while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
         j < len(R) and R[j] < l j < len(R) j len(R) len R R[j] < l R[j] R j l yield R[j] R[j] R j j += 1 j 1 yield l l while j < len(R):
        yield R[j]
        j += 1
     j < len(R) j len(R) len R yield R[j] R[j] R j j += 1 j 1 cp += len(L) + len(R) cp len(L) + len(R) len(L) len L len(R) len R L L R R def merge(A):
    global cp
    if len(A) == 1:
        return A
    if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A merge global cp if len(A) == 1:
        return A
     len(A) == 1 len(A) len A 1 return A A if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
     len(A) == 2 len(A) len A 2 cp += 2 cp 2 a, b = A a A b return A if a < b else (b, a) A if a < b else (b, a) a < b a b A (b, a) b a mid = len(A) // 2 mid len(A) // 2 len(A) len A 2 A[:] = m(merge(A[:mid]), merge(A[mid:])) A[:] A : m(merge(A[:mid]), merge(A[mid:])) m merge(A[:mid]) merge A[:mid] A :mid mid merge(A[mid:]) merge A[mid:] A mid: mid return A A A A n=int(input()) n int(input()) int input() input int(i) for i in input().rstrip().split(" ") for i in input().rstrip().split(" ") i input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " for i in input().rstrip().split(" ") int(i) int i A=[int(i) for i in input().rstrip().split(" ")] A [int(i) for i in input().rstrip().split(" ")] B = merge(A) B merge(A) merge A print(*B) print *B B print(cp) print cp B = merge(A) merge(A) B A=[int(i) for i in input().rstrip().split(" ")] [int(i) for i in input().rstrip().split(" ")] A def m(L,R):
    global cp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    cp += len(L) + len(R) def m(L,R):
    global cp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    cp += len(L) + len(R) m def merge(A):
    global cp
    if len(A) == 1:
        return A
    if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A def merge(A):
    global cp
    if len(A) == 1:
        return A
    if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A merge n=int(input()) int(input()) n cp = 0 0 cp
cp = 0
def m(L,R):
    global cp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    cp += len(L) + len(R)
def merge(A):
    global cp
    if len(A) == 1:
        return A
    if len(A) == 2:
        cp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A
n=int(input())
A=[int(i) for i in input().rstrip().split(" ")]
B = merge(A)
print(*B)
print(cp)
