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

from fractions import gcd

n = int(input())

t = [int(input()) for _ in range(n)]

ans = t[0]
for i in range(1, n):
    ans = ans * t[i] // gcd(ans, t[i])
print(ans)


Error: TLE

Fixed submission:

import numpy as np

n = int(input())

t = [int(input()) for _ in range(n)]

print(np.lcm.reduce(np.array(t)))
Problem p03633 (Python) — buggy submission, verdict: Runtime Error

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


def lcm(a, b):
    return a * b // gcd(max(a, b), min(a, b))


N = int(input())
T = [int(input()) for i in range(N)]

A = T[0]
for i in range(N):
    A = lcm(A, T[i])
print(A)


Error: 0

Fixed submission:

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


def lcm(a, b):
    return int(a * b / gcd(max(a, b), min(a, b)))


N = int(input())
T = [int(input()) for i in range(N)]

A = T[0]
for i in range(N):
    A = lcm(A, T[i])
print(A)
Problem p03633 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
T = [int(input()) for i in range(N)]
result = T[0]

for i in range(1, N):
    n = T[i]
    m = result
    while n % m != 0:
        m, n = n % m, m
    result = (result * T[i]) // m

print(result)


Error: TLE

Fixed submission:

N = int(input())
T = [int(input()) for i in range(N)]
T.sort()
T.reverse()
result = T[0]

for i in range(1, N):
    a = 1
    while True:
        if (result * a) % T[i] == 0:
            result *= a
            break
        a += 1

print(result)
Problem p03633 (Python) — buggy submission, verdict: Runtime Error

import fractions

n = int(input())
t = []
for _ in range(n):
    t.append(int(input()))

ans = t[0]
for ti in t:
    ans = ans * ti // fractions.gcd(ans, ti)


print(ans)


Error: 0

Fixed submission:

import math

n = int(input())
t = []
for _ in range(n):
    t.append(int(input()))

ans = t[0]
for ti in t:
    ans = ans * ti // math.gcd(ans, ti)


print(ans)
Problem p03633 (Python) — buggy submission, verdict: Time Limit Exceeded

def GCD(x: int, y: int):
    if x < y:
        x, y = y, x

    if x % y == 0:
        return y
    else:
        return GCD(y, x % y)


def LCM(x: int, y: int):
    return x * y // GCD(x, y)


N = int(input())
Tlist = [int(input()) for i in range(N)]
ans = 1
for num in Tlist:
    ans = LCM(ans, num)
print(ans)


Error: TLE

Fixed submission:

N = int(input())
cycles = [int(input()) for i in range(N)]


x = 1
M = max(cycles)
while 1:
    for num in cycles:
        if (M * x) % num != 0:
            x += 1
            break
    else:
        print(M * x)
        quit()
Problem p03633 (Python) — buggy submission, verdict: Runtime Error

import fractions

n = int(input())
a = 1

for b in range(n):
    b = int(input())
    a = a * b // fractions.gcd(a, b)
print(a)


Error: 0

Fixed submission:

import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
t = list(set([int(input()) for _ in range(n)]))

print(lcm(*t))
Problem p03633 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))


Error: 0

Fixed submission:

from math import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))
Problem p03633 (Python) — buggy submission, verdict: Runtime Error

from fractions import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    res = 1
    for ti in t:
        res = lcm_base(res, ti)
    print(res)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()


Error: 0

Fixed submission:

from math import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    res = 1
    for ti in t:
        res = lcm_base(res, ti)
    print(res)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()
Problem p03634 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(1000001)

N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()


Error: 0

Fixed submission:

N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()
Problem p03635 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
print((n - 1) * (m - 1))


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


Fixed submission:

n, m = map(int, input())
print((n - 1) * (m - 1))
Problem p03636 (Python) — buggy submission, verdict: Runtime Error

s = input()

print(s[0] + str(len(s[1:-1])) + s[-1])


Error: TypeError: can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03636/Python/s904035793.py", line 3, in <module>
    print(s[0] + len(s[1:-1]) + s[-1])
TypeError: can only concatenate str (not "int") to str


Fixed submission:

s = input()

print(s[0] + len(s[1:-1]) + s[-1])
Problem p03638 (Python) — buggy submission, verdict: Runtime Error

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

result = [[None] * W for _ in range(H)]
d = 1
x, y = 0, 0
for i in range(N):
    t = a[i]
    while t > 0:
        result[y][x] = i + 1
        x += d
        if x == -1 or x == W:
            x -= d
            d = -d
            y += 1
        t -= 1

for i in range(H):
    print(*result[i])


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03638/Python/s838608670.py", line 11, in <module>
    result[y][x] = i + 1
IndexError: list index out of range


Fixed submission:

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

result = [[None] * W for _ in range(H)]
d = 1
x, y = 0, 0
for i in range(N):
    t = a[i]
    while t > 0:
        result[y][x] = i + 1
        if x == 0 or x == W - 1:
            d = -d
            y += 1
        else:
            x += d
        t -= 1

for i in range(H):
    print(*result[i])
Problem p03643 (Python) — buggy submission, verdict: Runtime Error

N = input()

print("ABC" + N)


Error: ValueError: not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03643/Python/s548681311.py", line 1, in <module>
    N, K = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)


Fixed submission:

N, K = map(int, input().split())
L = list(map(int, input().split()))

L = sorted(L, reverse=True)

print(sum(L[:K]))
Problem p03643 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
print("ABC" + str(N))


Error: 0

Fixed submission:

N = int(input())
print(f"ABC{N}")
Problem p03643 (Python) — buggy submission, verdict: Runtime Error

n = int(input())

print("ABC" + str(n))


Error: TypeError: can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03643/Python/s236213679.py", line 3, in <module>
    print("ABC" + n)
TypeError: can only concatenate str (not "int") to str


Fixed submission:

n = int(input())

print("ABC" + n)
Problem p03643 (Python) — buggy submission, verdict: Runtime Error

n = input()
print("ABC" + n)


Error: ValueError: invalid literal for int() with base 10: ''
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03643/Python/s594169915.py", line 2, in <module>
    print(int(n[3:]))
ValueError: invalid literal for int() with base 10: ''


Fixed submission:

n = input()
print(int(n[3:]))
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
cnt_list = []
for i in range(1, n + 1):
    cnt = 0
    while i % 2 == 0:
        i = i / 2
        cnt += 1
    cnt_list.append(cnt)
print(2 ** max(cnt_list))


Error: WA

Fixed submission:

n = int(input())
cnt_list = []
for i in range(1, n):
    cnt = 0
    while i % 2 == 0:
        i = i / 2
        cnt += 1
    cnt_list.append(cnt)
print(max(cnt_list))
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

""" AtCoder """

N = int(input())
ans_list = [2, 4, 8, 16, 32, 64]
ans_list = ans_list[::-1]

if N == 1:
    print(1)
    exit()

for i in range(7):
    if N >= ans_list[i]:
        print(ans_list[i])
        break


Error: 0

Fixed submission:

""" AtCoder """

N = int(input())
ans_list = [2, 4, 8, 16, 32, 64]
ans_list = ans_list[::-1]

if N == 1:
    print(1)

for i in range(7):
    if N > ans_list[i]:
        print(ans_list[i])
        break
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

import sys

N = int(sys.stdin.readline())

if N in [1, 2, 4, 8, 16, 32, 64]:
    print(N)
else:
    sorted_list = sorted([1, 2, 4, 8, 16, 32, 64, N])[::-1]
    min_index = sorted_list[sorted_list.index(N) + 1]
    print(min_index)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03644/Python/s340201772.py", line 6, in <module>
    min_index = sorted_list[sorted_list.index(N) + 1]
IndexError: list index out of range


Fixed submission:

import sys

N = int(sys.stdin.readline())

sorted_list = [1, 2, 4, 8, 16, 32, 64, N][::1]
min_index = sorted_list[sorted_list.index(N) + 1]
print(min_index)
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

# https://atcoder.jp/contests/abc068/tasks/abc068_b


def two_factor(x):
    cnt = 0
    while x % 2 == 0:
        cnt += 1
        x //= 2
    return cnt


N = int(input())
a = list(map(two_factor, range(1, N + 1)))
max_cnt = max(a)
print(a.index(max_cnt) + 1)


Error: AttributeError: 'map' object has no attribute 'index'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03644/Python/s895004544.py", line 15, in <module>
    print(a.index(max_cnt) + 1)
AttributeError: 'map' object has no attribute 'index'


Fixed submission:

# https://atcoder.jp/contests/abc068/tasks/abc068_b


def two_factor(x):
    cnt = 0
    while x % 2 == 0:
        cnt += 1
        x //= 2
    return cnt


N = int(input())
a = map(two_factor, range(1, N + 1))
max_cnt = max(a)
print(a.index(max_cnt) + 1)
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

N = int(input())

if N == 1:
    print(1)
else:
    ans = 2
    while ans * 2 <= N:
        ans *= 2
    print(ans)


Error: 0

Fixed submission:

N = int(input())

if N == 1:
    print(0)
else:
    ans = 2
    while ans * 2 <= N:
        ans *= 2
print(ans)
Problem p03644 (Python) — buggy submission, verdict: Runtime Error

def resolve():
    n = int(input())
    ans = 0
    for i in range(2, n + 1, 2):
        c = 0
        while i % 2 == 0:
            i //= 2
            c += 1
        if c > ans:
            ans = c
    print(2**ans)


if __name__ == "__main__":
    resolve()


Error: 0

Fixed submission:

import math


def resolve():
    n = int(input())
    print(2 ** int(math.log2(n)))


if __name__ == "__main__":
    resolve()
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n, m = map(int, input().split())

    islands_to_1 = [0 for _ in range(n + 1)]
    islands_to_n = []
    for _ in range(m):
        boat = list(map(int, input().split()))
        if 1 in boat:
            islands_to_1[boat[1]] = 1

        if n in boat:
            islands_to_n.append(min(boat))

    for island_to_n in islands_to_n:
        if islands_to_1[island_to_n] == 1:
            print("POSSIBLE")
            return

    print("IMPOSSIBLE")
    return


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    n, m = map(int, input().split())

    islands_to_1 = []
    islands_to_n = []
    for _ in range(m):
        boat = list(map(int, input().split()))
        if 1 in boat:
            islands_to_1.append(max(boat))

        if n in boat:
            islands_to_n.append(min(boat))

    for island_to_1 in islands_to_1:
        if island_to_1 in islands_to_n:
            print("POSSIBLE")
            return

    print("IMPOSSIBLE")
    return


if __name__ == "__main__":
    main()
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    visited.append(now)
    if now == N - 1:
        ends = visited[:]
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

if N - 1 in ends:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: TLE

Fixed submission:

N, M = map(int, input().split())
ab_list = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

lis = [[] for i in range(N)]

for i in range(M):
    lis[ab_list[i][0]].append(ab_list[i][1])

que = [[0, 0, lis[0], []]]
ends = []
res = False

while que:
    count, now, next_nodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in next_nodes:
        if node in visited or count == 2:
            continue
        que.append([count + 1, node, lis[node], visited[:]])

print()

if N - 1 in set(sum(ends, [])):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
d = []
flag = 0
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])
        if b[i] == N:
            flag = 1
    if b[i] == N:
        d.append(a[i])
        if a[i] == 1:
            flag = 1
e = set(c) | set(d)
if len(c) + len(d) == len(e):
    flag = 0
else:
    flag = 1

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Error: TLE

Fixed submission:

N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])

flag = 0
for k in c:
    if k == N:
        flag = 1
        break
    else:
        for i in range(M):
            if a[i] == k and b[i] == N:
                flag = 1
                break
    if flag == 1:
        break

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
start = []
goal = []
flag = False
for x in range(M):
    if ab[x][0] == 1:
        start.append(ab[x][1])

    if ab[x][1] == N:
        goal.append(ab[x][0])

start_goal = set(start) & set(goal)

if start_goal:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: TLE

Fixed submission:

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
second = []
flag = False
for x in range(M):
    if ab[x][0] == 1:
        second.append(ab[x][1])

for y in range(len(second)):
    for z in range(M):
        if ab[z][0] == second[y] and ab[z][1] == N:
            flag = True
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

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

one2 = set()
toN = set()

for _ in range(M):
    a, b = map(int, input().split())

    if a == 1:
        one2.add(b)

    if b == N:
        toN.add(a)

inter = one2 & toN

if len(inter) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: TLE

Fixed submission:

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

one2 = []
toN = []

for _ in range(M):
    a, b = map(int, input().split())

    if a == 1:
        one2.append(b)

    if b == N:
        toN.append(a)

flag = False
for a in one2:
    if a in toN:
        flag = True
        break

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

# グラフわからんのでグラフアルゴリズム忘れた
# dfsでやる 限度2回c
# なんかしらんけどdfsが2TLEになるので諦めた それぞれの島について1とNがあれば良い

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

for g in graph[1 : n - 1]:
    c = 0
    for v in g:
        if c >= 2:
            break
        if v == 0 or v == n - 1:
            c += 1
    if c == 2:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Error: TLE

Fixed submission:

# グラフわからんのでグラフアルゴリズム忘れた
# dfsでやる 限度2回

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)


def dfs(t, c, used):
    if c != 0 and t == n - 1:
        return True
    if c == 0:
        return False
    flag = False
    for g in graph[t]:
        if g in used:
            continue
        next_used = used[:]
        next_used.append(g)
        flag = dfs(g, c - 1, next_used)
        if flag:
            break
    return flag


for x in graph[0]:
    if dfs(x, 2, [x]):
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = map(int, input().split())
l = [0] * n
r = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        r.append(b)
    if b == n:
        l[a - 1] = 1
ans = "IMPOSSIBLE"
for i in r:
    if l[i - 1] == 1:
        ans = "POSSIBLE"
print(ans)


Error: TLE

Fixed submission:

n, m = map(int, input().split())
r = [[0, 0] for _ in range(m)]
ln = []
l1 = []
for i in range(m):
    r[i][0], r[i][1] = map(int, input().split())
    if r[i][1] == n:
        ln.append(i)
    if r[i][0] == 1:
        l1.append(i)
ans = "IMPOSSIBLE"
for i in l1:
    for j in ln:
        if r[i][1] == r[j][0]:
            ans = "POSSIBLE"
            break
print(ans)
Problem p03645 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        s2.add(a)

if len(s1.intersection(s2)) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: AttributeError: 'set' object has no attribute 'count'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03645/Python/s877436493.py", line 13, in <module>
    if s2.count(x) >= 1:
AttributeError: 'set' object has no attribute 'count'


Fixed submission:

N, M = map(int, input().split())
s1 = set()
s2 = set()

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        s1.add(b)
    if b == N:
        s2.add(a)

for x in s1:
    if s2.count(x) >= 1:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
"""
check = 0


for i in range(m):
    if a[i] == 1:
        check = b[i]
        for j in range(m):
            if a[j] == check and b[j] == n:
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")

"""
start = []
leave = []
for i in range(m):
    if a[i] == 1:
        start.append(b[i])
    elif b[i] == n:
        leave.append(a[i])

if set(start) & set(leave):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: TLE

Fixed submission:

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

check = 0


for i in range(m):
    if a[i] == 1:
        check = b[i]
        for j in range(m):
            if a[j] == check and b[j] == n:
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

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

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(pot_ends):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Error: TLE

Fixed submission:

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

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

for i in set(pot_starts):
    if i in pot_ends:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
Problem p03645 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = map(int, input().split())
a = [input().split() for _ in range(m)]
A = []
B = []

for i in range(m):
    if a[i][0] == "1":
        A.append(a[i][1])
    if a[i][1] == str(n):
        B.append(a[i][0])
print("POSSIBLE" if set(A) & set(B) else "IMPOSSIBLE")


Error: TLE

Fixed submission:

n, m = map(int, input().split())
a = [input().split() for _ in range(m)]
A = set()
B = set()

for i in range(m):
    if a[i][0] == "1":
        A.add(a[i][1])
    if a[i][1] == str(n):
        B.add(a[i][0])
    if A & B:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")
Problem p03649 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
ans = 0
flag = True
while flag:
    flag = False
    for i in range(N):
        if A[i] >= N:
            count = A[i] // N
            ans += count
            for j in range(N):
                A[j] += count
            A[i] -= count
            A[i] %= N
            flag = True

print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
ans = 0
flag = True
while flag:
    flag = False
    for i in range(N):
        if A[i] >= N:
            count = A[i] // N
            ans += count
            for j in range(N):
                A[j] += count
            A[i] -= count
            A[i] %= N
            flag = True
            break

print(ans)