Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

count = 0
left_arr = []
right_arr = []


def merge(a, n, left, mid, right):
    n1 = mid - left
    for i in range(n1):
        left_arr[i] = a[left + 1]

    n2 = right - mid
    for i in range(n2):
        right_arr[i] = a[mid + i]

    left_arr[n1] = right_arr[n2] = 20 * 1000000

    i = j = 0
    for k in range(left, right):
        count += 1
        if left_arr[i] <= right_arr[j]:
            i += 1
            a[k] = left_arr[i]
        else:
            j += 1
            a[k] = right_arr[j]
    return a


def merge_sort(a, n, left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        merge_sort(a, n, left, mid)
        merge_sort(a, n, mid, right)
        arr = merge(a, n, left, mid, right)
    return arr


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    sorted_arr = merge_sort(a, n, 0, n)
    return " ".join(sorted_arr)


print(main())
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

infinity = 10 ** 9


def merge(ns, left, mid, right, count):
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1)]
    right_ns = [e for e in range(n2)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1
    return ns, count


def merge_sort(ns, left, right):
    count = 0
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        ns, count = merge(ns, left, mid, right, count)
    return ns, count


n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
ns, count = merge_sort(ns, left, right)

print(" ".join(ns))
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

infinity = 10 ** 9
count = 0


def merge(ns, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1)]
    right_ns = [e for e in range(n2)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    count = 0
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right, count)


n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
merge_sort(ns, left, right)

print(" ".join(ns))
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def merge(ns, left, mid, right):
    global count
    infinity = 10 ** 9
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1 + 1)]
    right_ns = [e for e in range(n2 + 1)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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

n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)
ns = [str(n) for n in ns]

print(" ".join(ns))
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1 + 1)]
    right_ns = [e for e in range(n2 + 1)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)
# ns = [str(n) for n in ns]

print(*ns)
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    # left_ns = [e for e in range(n1 + 1)]
    # right_ns = [e for e in range(n2 + 1)]
    left_ns = ns[left:mid]
    right_ns = ns[mid:right]

    # for i in range(n1):
    #     left_ns[i] = ns[left + i]
    # for i in range(n2):
    #     right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)

Fixed submission:
# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


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


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)