alexjercan/bugnet huggingface dataset:
Problem p03111 (Python) — buggy submission, verdict: Runtime Error

try:
    from math import inf
except:
    inf = float("inf")
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)


Error: 0

Fixed submission:

from math import inf
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)
Problem p03111 (Python) — buggy submission, verdict: Time Limit Exceeded

import itertools

N, A, B, C = map(int, input().split())
L = [int(input()) for n in range(N)]
P = []

for n in range(1, N + 1):
    P.extend(itertools.combinations([n for n in range(N)], n))

add_len = {s: sum(L[i] for i in s) for s in P}


def cost(v, s):
    return 10 * (len(s) - 1) + abs(v - add_len[s])


res = 2 << 30
for a in P:
    cost_a = cost(A, a)
    if res < cost_a:
        continue

    for b in P:
        cost_b = cost(B, b)
        if res < cost_b:
            continue

        set_a = set(a)
        set_b = set(b)
        if len(set_a & set_b):
            continue

        for c in P:
            cost_c = cost(C, c)
            if res < cost_c:
                continue

            set_c = set(c)
            if len(set_a & set_c) or len(set_b & set_c):
                continue
            res = min(res, cost_a + cost_b + cost_c)

print(res)


Error: TLE

Fixed submission:

import itertools

N, A, B, C = map(int, input().split())
L = [int(input()) for n in range(N)]
P = []

for n in range(1, N + 1):
    P.extend(itertools.combinations([n for n in range(N)], n))

add_len = {s: sum(L[i] for i in s) for s in P}


def cost(v, s):
    return 10 * (len(s) - 1) + abs(v - add_len[s])


res = 2 << 30
for a in P:
    cost_a = cost(A, a)
    if res < cost_a:
        continue

    for b in P:
        cost_b = cost(B, b)
        if res < cost_b:
            continue

        if len(set(a) & set(b)):
            continue

        for c in P:
            cost_c = cost(C, c)
            if res < cost_c:
                continue

            if len(set(a) & set(c)) or len(set(b) & set(c)):
                continue
            res = min(res, cost_a + cost_b + cost_c)

print(res)
Problem p03113 (Python) — buggy submission, verdict: Runtime Error

def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        buf.append(mi)
        # print(buf)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03113/Python/s607630341.py", line 29, in <module>
    solve(n, k, aaa)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03113/Python/s607630341.py", line 10, in solve
    aaa[mi] += 1
IndexError: list index out of range


Fixed submission:

def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        if t == k:
            aaa[mi] += 1
        else:
            buf.append(mi)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
Problem p03125 (Python) — buggy submission, verdict: Runtime Error

a, b = list(map(int, input().split()))
r = a + b if b % a == 0 else b - a
print(r)


Error: ValueError: invalid literal for int() with base 10: '4 12'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s844412029.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '4 12'


Fixed submission:

a = int(input())
b = int(input())
r = a + b if b % a == 0 else b - a
print(r)
Problem p03125 (Python) — buggy submission, verdict: Runtime Error

a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(bool(b % a))])


Error: 0

Fixed submission:

a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(b % a)])
Problem p03125 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-


def func_a():
    argv = input().split(" ")
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a()


Error: ValueError: invalid literal for int() with base 10: '/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s435981808.py'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s435981808.py", line 19, in <module>
    func_a(sys.argv)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s435981808.py", line 6, in func_a
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
ValueError: invalid literal for int() with base 10: '/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s435981808.py'


Fixed submission:

# -*- coding: utf-8 -*-
import sys


def func_a(argv):
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a(sys.argv)
Problem p03125 (Python) — buggy submission, verdict: Runtime Error

a, b = map(int, input().split())
if b % a == 0:
    print(a + b)
else:
    print(b - a)


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s517301094.py", line 1, in <module>
    a, b = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

a, b = map(int, input())
if b % a == 0:
    print(a + b)
else:
    print(b - a)
Problem p03125 (Python) — buggy submission, verdict: Runtime Error

A, B = list(map(int, input().split()))

if B % A == 0:
    print(A + B)
else:
    print(B - A)


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03125/Python/s504979530.py", line 1, in <module>
    A, B = list(map(int, input()))
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

A, B = list(map(int, input()))

if B % A == 0:
    print(A + B)
else:
    print(B - A)
Problem p03126 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
k = [i[1:] for i in [list(map(int, input().split())) for i in range(N)]]
k_1 = [flatten for inner in k for flatten in inner]
count_k = 0
for i in range(1, M + 1):
    if k_1.count(i) == N:
        count_k += 1

print(count_k)


Error: 0

Fixed submission:

N, M = map(int, input().split())
a_k = [list(map(int, input().split())) for i in range(N)]
a_k.sort()

a_non = []
for i in range(1, len(a_k)):
    if len(a_k[0]) <= 1:
        break

    for j in range(1, len(a_k[0])):
        if a_k[0][j] not in a_k[i][1:]:
            a_non.append(j)

for j in range(len(a_non)):
    a_k[0].pop(a_non[j])


print(len(a_k[0]) - 1)
Problem p03126 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
ans = [0] * m
for _ in range(n):
    a = list(map(int, input().split()))

    for i in a[1:]:
        ans[i - 1] += 1

print(ans.count(n))


Error: 0

Fixed submission:

n, m = map(int, input().split())
ans = [0] * m

for _ in range(n):
    a = list(map(int, input().split()))
    for i in a[1:]:
        ans[i] += 1

print(ans.count(n))
Problem p03126 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
loved_by_everyone = [0] * M
for _ in range(N):
    like_list = list(map(int, input().split()))
    for like in like_list[1:]:
        loved_by_everyone[like - 1] += 1

kinds = 0
for food in loved_by_everyone:
    kinds += 1 if food == N else 0
print(kinds)


Error: 0

Fixed submission:

N, M = map(int, input().split())
loved_by_everyone = [0] * M
for _ in range(N):
    like_list = list(map(int, input().split()))
    for like in like_list[1:]:
        loved_by_everyone[like] += 1

kinds = 0
for food in loved_by_everyone:
    kinds += 1 if food == N else 0
print(kinds)
Problem p03126 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
favorites = set(i for i in range(1, M + 1))
for _ in range(N):
    K, *fav = map(int, input().split())
    favorites = favorites & set(fav)
print(len(favorites))


Error: 0

Fixed submission:

N, M = map(int, input().split())
favorites = {*tuple(range(1, M + 1))}
for _ in range(N):
    K, *fav = map(int, input().split())
    favorites = favorites & set(fav)
print(len(favorites))
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


N = int(input())
A = [int(x) for x in input().split()]

ans = A[0]

for i in range(1, N):
    ans = gcd(ans, A[i])

print(ans)


Error: 0

Fixed submission:

from math import gcd

N = int(input())
A = [int(x) for x in input().split()]

ans = A[0]

for i in range(1, N):
    ans = gcd(ans, A[i])

print(ans)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(20000)


def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


n = int(input())
A = inpl()
A.sort()
ans = gcd(A[0], A[1])
for a in A:
    ans = gcd(ans, a)
print(ans)


Error: 0

Fixed submission:

import sys

sys.setrecursionlimit(20000)


def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


n = int(input())
A = inpl()

ans = gcd(A[0], A[1])
for a in A:
    ans = gcd(ans, a)
print(ans)
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

# Ai.sort()

i = 1
min = 1000000000
a = Ai[0]
for a2 in Ai[1:]:
    a_gcd = fractions.gcd(a, a2)
    if min > a_gcd:
        min = a_gcd
        if min <= 2:
            print(min)
            quit()

print(min)


Error: TLE

Fixed submission:

import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

i = 1
min = 1000000000
for a in Ai:
    for a2 in Ai[i:]:
        a_gcd = fractions.gcd(a, a2)
        if min > a_gcd:
            min = a_gcd
            if min <= 2:
                print(min)
                quit()
    i += 1

print(min)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from functools import reduce
from fractions import gcd

N = int(input())
A = [int(i) for i in input().split()]

print(reduce(gcd, A))


Error: ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03127/Python/s208362126.py", line 2, in <module>
    from functools import gcd
ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)


Fixed submission:

from functools import reduce
from functools import gcd

N = int(input())
A = [int(i) for i in input().split()]

print(reduce(gcd, A))
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))

while True:
    if len(A) == 1:
        break
    pop_i = []
    A.sort()
    for i in range(1, len(A)):
        life = A[i] % A[0]
        if life == 1:
            print(life)
            exit()
        else:
            A[i] = life
    A = [n for n in A if n > 0]

print(A[0])


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

while True:
    if len(A) == 1:
        break
    max_i = A.index(max(A))
    min_i = A.index(min(A))
    life = A[max_i] % A[min_i]
    if life == 0:
        A.pop(max_i)
    else:
        A[max_i] = life

print(A[0])
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

def gcd(b, a):
    while b:
        a, b = b, a % b
    return a


input()
a = sorted((map(int, input().split())))
ans = a[0]
for i in range(1, len(a)):
    ans = gcd(ans, a[i])
print(ans)


Error: 0

Fixed submission:

import math

input()
a = sorted((map(int, input().split())))
ans = a[0]
for i in range(1, len(a)):
    ans = math.gcd(ans, a[i])
print(ans)
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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

ans = a[0]
for i in range(1, len(a)):
    ans = gcd(ans, a[i])
print(ans)


Error: TLE

Fixed submission:

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

while len(a) >= 2:
    min_a = min(a)

    # 最小値が２つある場合に一回はskipする
    flag = False
    for i in range(len(a)):
        if a[i] == min_a and not flag:
            flag = True
            continue
        if flag or a[i] != min_a:
            a[i] = a[i] % min_a
    while True:
        if a.count(0) > 0:
            a.remove(0)
        else:
            break
print(a[0])
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd

N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)

x = A[0]
for i in range(1, N):
    x = gcd(x, A[i])
print(x)


Error: 0

Fixed submission:

from math import gcd

N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)

x = A[0]
for i in range(1, N):
    x = gcd(x, A[i])
print(x)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

n = int(input())

zombies = [int(c) for c in input().split()]


def gcd(a, b):
    c = a % b
    if c == 0:
        return b
    else:
        return gcd(b, c)


m = zombies[0]
for i in range(1, len(zombies)):
    m = gcd(m, zombies[i])

print(m)


Error: 0

Fixed submission:

n = int(input())

zombies = [int(c) for c in input().split()]


def gcd(a, b):
    mod = a % b
    if mod == 0:
        return b
    else:
        return gcd(b, mod)


def saidai_koyakusu(n, ns):
    if len(ns) == 1:
        return ns[0]
    return gcd(n, saidai_koyakusu(ns[0], ns[1:]))


if len(zombies) == 1:
    print(zombies[0])
else:
    print(saidai_koyakusu(zombies[0], zombies[1:]))
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

""" AtCoder """

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

ans = A[0]

for i in range(1, N):
    ans = gcd(ans, A[i])

print(ans)


Error: 0

Fixed submission:

""" AtCoder """

import math

N = int(input())
A = list(map(int, input().split()))

ans = A[0]

for i in range(1, N):
    ans = math.gcd(ans, A[i])

print(ans)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

import sys

readline = sys.stdin.buffer.readline


def sss(A, N):
    A.sort()
    while A[0] == 0:
        A.remove(0)
    for i in range(1, len(A)):
        A[i] = A[i] % A[0]
    if A[0] == sum(A):
        print(sum(A))
    else:
        return sss(A, N)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    sss(A, N)


main()


Error: 0

Fixed submission:

import sys

readline = sys.stdin.buffer.readline


def sss(A, N):
    A.sort()
    if A[0] == 0:
        A.remove(0)
    for i in range(1, len(A)):
        A[i] = A[i] % A[0]
    if A[0] == sum(A):
        print(sum(A))
    else:
        return sss(A, N)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    sss(A, N)


main()
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            if i % a[0] == 1:
                print(1)
                exit()
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])


Error: TLE

Fixed submission:

n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:20])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

def gcd(x, y):
    if y > x:
        x, y = y, x
    while y != 0:
        x, y = y, x % y
    return x


N = int(input())
A = [int(i) for i in input().split()]
ans = A[N - 1]
for i in range(N - 1):
    ans = gcd(ans, A[i])
print(ans)


Error: 0

Fixed submission:

import math

N = int(input())
A = [int(i) for i in input().split()]
ans = A[N - 1]
for i in range(N - 1):
    ans = math.gcd(ans, A[i])
print(ans)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd

n = int(input())
A = [int(i) for i in input().split()]

a = A[0]
for i in range(1, n):
    a = gcd(a, A[i])

print(a)


Error: ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03127/Python/s946665504.py", line 1, in <module>
    from functools import gcd
ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)


Fixed submission:

from functools import gcd

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

a = A[0]
for i in range(1, n):
    a = gcd(a, A[i])

print(a)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

import fractions

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
print(ans)


Error: 0

Fixed submission:

import math

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = math.gcd(ans, A[i])
print(ans)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd
from functools import reduce

N = int(input())
A = [int(i) for i in input().split()]
print(reduce(gcd, A))


Error: 0

Fixed submission:

import math
from functools import reduce


N = int(input())
A = [int(i) for i in input().split()]
print(reduce(math.gcd, A))
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd
from functools import reduce

input()
print(reduce(gcd, map(int, input().split())))


Error: 0

Fixed submission:

import math
from functools import reduce

input()
print(reduce(math.gcd, map(int, input().split())))
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

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


def gcd(x, y):
    while y != 0:
        x, y = y, x % y

    return x


ret = gcd(a[0], a[1])

for e in a[2:]:
    ret = gcd(ret, e)

print(ret)


Error: 0

Fixed submission:

from math import gcd

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

ret = gcd(a[0], a[1])
for e in a[2:]:
    ret = gcd(ret, e)

print(ret)
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

import fractions
from functools import reduce

N = int(input())
As = map(int, input().split())

print(reduce(fractions.gcd, As))


Error: ModuleNotFoundError: No module named 'fraction'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03127/Python/s866739157.py", line 1, in <module>
    import fraction
ModuleNotFoundError: No module named 'fraction'


Fixed submission:

import fraction
from functools import reduce

N = int(input())
As = map(int, input().split())

print(reduce(fraction.gcd, As))
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd
from functools import reduce

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

print(reduce(gcd, a))


Error: ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03127/Python/s745389063.py", line 1, in <module>
    from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)


Fixed submission:

from fractions import gcd

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

print(gcd(a))
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

from functools import reduce

n = int(input())
lst = [int(i) for i in input().split()]


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


print(reduce(gcd, lst))


Error: TLE

Fixed submission:

n = int(input())
lst = [int(i) for i in input().split()]

if all([i % min(lst) == 0 for i in lst]):
    print(min(lst))
    exit()

gcm = 1
j = 2
lmt = int(min(lst) ** 0.5) + 1
while j <= lmt:
    if all([i % j == 0 for i in lst]):
        lst = [i / j for i in lst]
        gcm *= j
    else:
        j += 1

print(gcm)
Problem p03127 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-
N = map(int, input())
A = list(map(int, input().split()))

while len(A) >= 2:
    idx = A.index(min(A))
    x = A.pop(idx)
    B = list()
    for i in range(len(A)):
        if A[i] % x != 0:
            B.append(A[i] % x)
    B.append(x)
    A = B[:]

print(A[0])


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-
N = map(int, input())
A = list(map(int, input().split()))

while len(A) >= 2:
    x = A.pop(A.index(max(A)))
    y = min(A)
    n = x % y
    if n == 0:
        pass
    else:
        A.append(n)

print(A[0])
Problem p03127 (Python) — buggy submission, verdict: Runtime Error

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


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


if n == 1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if n == 2:
        print(element)
    else:
        for i in range(2, n):
            element = gcd(element, x[i])
        print(element)


Error: 0

Fixed submission:

import functools
import math

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

gcd = functools.reduce(math.gcd, a)
print(gcd)