Buggy python submission (verdict: Time Limit Exceeded):
comp = 0
def merge(A, left, right):
    global comp
    if not left +1 < right:
        return [A[left]]
    mid = (left + right) // 2
    L = merge(A, left, mid)
    R = merge(A, mid, right)
    result = []
    i = j = 0
    while i < len(L) and j < len(R):
        comp += 1
        if L[i] <= R[j]:
            result.append(L[i])
            i += 1
        else:
            result.append(R[j])
            j += 1
    while i < len(L):
        comp += 1
        result.append(L[i])
        i += 1
    while j < len(R):
        comp += 1
        result.append(R[j])
        j += 1
    return result
n = int(input())
*A, = map(int, input().split())
B = merge(A, 0, n)
print(*B)
print(comp)

Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
comp = 0
def merge(A, left, right):
    global comp
    if not left+1 < right:
        return [A[left]]
    if left+2 == right:
        comp += 2
        a, b = A[left:right]
        return (a, b) if a < b else (b, a)
    mid = (left + right) // 2
    L = merge(A, left, mid)
    R = merge(A, mid, right)
    result = []
    i = j = 0
    while i < len(L) and j < len(R):
        comp += 1
        if L[i] <= R[j]:
            result.append(L[i])
            i += 1
        else:
            result.append(R[j])
            j += 1
    if i < len(L):
        result.extend(L[i:])
        comp += len(L) - i
    if j < len(R):
        result.extend(R[j:])
        comp += len(R) - j
    return result

n, *A = map(int, open(0).read().split())
B = merge(A, 0, n)
print(*B)
print(comp)

Fixed submission:
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)

Buggy python submission (verdict: Time Limit Exceeded):
comp = 0
def m(L, R):
    global comp
    i = j = 0
    while i < len(L) and j < len(R):
        comp += 1
        if L[i] <= R[j]:
            yield L[i]
            i += 1
        else:
            yield R[j]
            j += 1
    comp += len(L) - i + len(R) - j
    while i < len(L):
        yield L[i]
        i += 1
    while j < len(R):
        yield R[j]
        j += 1
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
    L = merge(A[:mid])
    R = merge(A[mid:])
    A[:] = m(L, R)
    return A

n, *A = map(int, open(0).read().split())
B = merge(A)
print(*B)
print(comp)

Fixed submission:
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)