comp = 0
def m(L, R):
    global comp
    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
    comp += len(L) + len(R)
def merge(A):
    global comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 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, *A = map(int, open(0).read().split())
B = merge(A)
print(*B)
print(comp) comp = 0 comp 0 def m(L, R):
    global comp
    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
    comp += len(L) + len(R) m global comp 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 comp += len(L) + len(R) comp len(L) + len(R) len(L) len L len(R) len R L L R R def merge(A):
    global comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 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 comp if len(A) == 1:
        return A
     len(A) == 1 len(A) len A 1 return A A if len(A) == 2:
        comp += 2
        a, b = A
        return A if a < b else (b, a)
     len(A) == 2 len(A) len A 2 comp += 2 comp 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, *A = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split *A A B = merge(A) B merge(A) merge A print(*B) print *B B print(comp) print comp def merge(A):
    global comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 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 comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 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, *A = map(int, open(0).read().split()) map(int, open(0).read().split()) n B = merge(A) merge(A) B comp = 0 0 comp def m(L, R):
    global comp
    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
    comp += len(L) + len(R) def m(L, R):
    global comp
    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
    comp += len(L) + len(R) m
comp = 0
def m(L, R):
    global comp
    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
    comp += len(L) + len(R)
def merge(A):
    global comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 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, *A = map(int, open(0).read().split())
B = merge(A)
print(*B)
print(comp)