Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
if __name__ == '__main__':
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        uf.union(a, b)

    print(len(list(uf.all_group_members().values()))-1)


Fixed submission:
import sys

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
if __name__ == '__main__':
    input = sys.stdin.readline
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        uf.union(a, b)

    print(uf.group_count()-1)
Buggy python submission (verdict: Runtime Error):
MOD = 998244353

N, K = map(int, input().split())
seg = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    for s, t in seg:
        dp[i+s] += dp[i]
        dp[i+t;1] -= dp[i]
    dp[i+1] += dp[i]
    dp[i+1] %= MOD
    
print(dp[N-1])


Fixed submission:
MOD = 998244353

N, K = map(int, input().split())
seg = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    for s, t in seg:
        if (i+s) <= N:dp[i+s] += dp[i]
        if (i+t+1) <= N:dp[i+t+1] -= dp[i]
    dp[0] = 0
    dp[i+1] += dp[i]
    dp[i+1] %= MOD
    
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

cut = [0 for _ in range(MAX+1)]
for i in range(2, MAX+1, 2):
    if cut[i] != 0:
        continue
    for j in range(i, MAX+1, i):
        cut[j] = i

if reduce(math.gcd, A) != 1:
    print('not coprime')
    exit()

already = set()
for a in A:
    now = set()
    while a != 1:
        if cut[a] in already:
            print('setwise coprime')
            exit()
        a //= cut[a]
        now.add(cut[a])
    already |= now

print('pairwise coprime')

Fixed submission:
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6 + 1

cut = [2 for _ in range(MAX)]
for i in range(3, MAX, 2):
    if cut[i] != 2:
        continue
    for j in range(i, MAX, i):
        cut[j] = i

if reduce(math.gcd, A) != 1:
    print('not coprime')
    exit()

already = set()
for a in A:
    now = set()
    while a != 1:
        if cut[a] in already:
            print('setwise coprime')
            exit()
        now.add(cut[a])
        a //= cut[a]
    already |= now

print('pairwise coprime')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K % 2 == 0:
    print(-1)
    exit()

amari = 0

for i in range(1, 10**7):
    amari *= 10
    amari += 7
    amari %= K
    if amari == 0:
        print(i)
        exit()

print(-1)

Fixed submission:
K = int(input())

if K % 2 == 0:
    print(-1)
    exit()

amari = 0

for i in range(1, 10**7):
    amari *= 10
    amari += 7
    amari %= K
    if amari == 0:
        print(i)
        exit()

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = [0] * N

for _ in range(min(K, 42)):
    lights = [0] * N
    for i, flash in enumerate(A):
        lights[max(0, i-flash)] += 1
        if i+flash < N-1:
            lights[i+flash+1] -= 1
    for i in range(1, N):
        lights[i] += lights[i-1]
    A = copy.deepcopy(lights)

for i in A:
    print(int(i),end=' ')
print()

Fixed submission:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = [0] * N

for _ in range(min(K, 42)):
    lights = [0] * N
    for i, flash in enumerate(A):
        lights[max(0, i-flash)] += 1
        if i+flash < N-1:
            lights[i+flash+1] -= 1
    for i in range(1, N):
        lights[i] += lights[i-1]
    A = copy.deepcopy(lights)

for i in A:
    print(int(i),end=' ')
print()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = np.zeros(N, dtype='int32')

for _ in range(min(K, 45)):
    lights = np.zeros(N, dtype='int32')
    for i, flash in enumerate(A):
        front = i-flash if i-flash >= 0 else 0
        back = i+flash if i+ flash < N else N-1
        lights[front:back+1] += 1
    A = np.copy(lights)

for i in A:
    print(int(i),end=' ')
print()

Fixed submission:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = [0] * N

for _ in range(min(K, 42)):
    lights = [0] * N
    for i, flash in enumerate(A):
        lights[max(0, i-flash)] += 1
        if i+flash < N-1:
            lights[i+flash+1] -= 1
    for i in range(1, N):
        lights[i] += lights[i-1]
    A = copy.deepcopy(lights)

for i in A:
    print(int(i),end=' ')
print()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = np.zeros(N, dtype='int32')

for _ in range(K):
    lights = np.zeros(N, dtype='int32')
    for i, flash in enumerate(A):
        front = i-flash if i-flash >= 0 else 0
        back = i+flash if i+ flash < N else N-1
        lights[front:back+1] += 1
    A = np.copy(lights)

for i in A:
    print(int(i),end=' ')
print()

Fixed submission:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))
lights = [0] * N

for _ in range(min(K, 42)):
    lights = [0] * N
    for i, flash in enumerate(A):
        lights[max(0, i-flash)] += 1
        if i+flash < N-1:
            lights[i+flash+1] -= 1
    for i in range(1, N):
        lights[i] += lights[i-1]
    A = copy.deepcopy(lights)

for i in A:
    print(int(i),end=' ')
print()
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [[0 for _ in range(S+1)] for __ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2 * dp[i][j]
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD

print(dp[N][S])

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [[0 for _ in range(S+1)] for __ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2 * dp[i][j]
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD

print(dp[N][S])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))
past = [0]*min(K, 2*10**5)
now = 1
step = 0
for i in range(K):
    past[i] = now
    now = A[now-1]
    if now in past:
        step += 1
        break

if step > 0:
    id = past.index(now)
    step = i+1 - id
    p = (K-id) % step
    now = past[id+p]

print(now)

Fixed submission:
N, K = map(int, input().split())

A = list(map(int, input().split()))
past = [0]*min(K, 2*10**5)
ps = set()
now = 1
step = 0
for i in range(K):
    past[i] = now
    ps.add(now)
    now = A[now-1]
    if now in ps:
        step += 1
        break

if step > 0:
    id = past.index(now)
    step = i+1 - id
    p = (K-id) % step
    now = past[id+p]

print(now)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))
past = []
now = 1
step = 0
for i in range(K):
    past.append(now)
    now = A[now-1]
    if now in past:
        step += 1
        break

if step > 0:
    id = past.index(now)
    step = len(past) - id
    p = (K-id) % step
    for i in range(p):
        now = A[now-1]

print(now)


Fixed submission:
N, K = map(int, input().split())

A = list(map(int, input().split()))
past = [0]*min(K, 2*10**5)
ps = set()
now = 1
step = 0
for i in range(K):
    past[i] = now
    ps.add(now)
    now = A[now-1]
    if now in ps:
        step += 1
        break

if step > 0:
    id = past.index(now)
    step = i+1 - id
    p = (K-id) % step
    now = past[id+p]

print(now)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
good = set()
bad = set()

for i in range(N):
    flag = True
    if i in bad:
        continue
    for path in paths:
        if i in path:
            bi = path[0]
            if bi == i:
                bi = path[1]
            if H[i] <= H[bi]:
                bad.add(i)
                flag = False
                break
            else:
                bad.add(bi)
    if flag:
        good.add(i)
        
print(len(good))

Fixed submission:
N, M = map(int, input().split())

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
bad = set()

for path in paths:
  if H[path[0]] == H[path[1]]:
    bad.add(path[0])
    bad.add(path[1])
  elif H[path[0]] > H[path[1]]:
    bad.add(path[1])
  else:
    bad.add(path[0])
        
print(N-len(bad))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
good = []
bad = []

for i in  range(N):
    flag = True
    if i in bad:
        continue
    for path in paths:
        if i in path:
            bi = path[0]
            if bi == i:
                bi = path[1]
            if H[i] <= H[bi]:
                bad.append(i)
                flag = False
                break
            else:
                bad.append(bi)
    if flag:
        good.append(i)
        
print(len(good))

Fixed submission:
N, M = map(int, input().split())

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

paths = []
for i in range(M):
    paths.append(list(map(int, input().split())))
    paths[-1][0] -= 1
    paths[-1][1] -= 1
    
bad = set()

for path in paths:
  if H[path[0]] == H[path[1]]:
    bad.add(path[0])
    bad.add(path[1])
  elif H[path[0]] > H[path[1]]:
    bad.add(path[1])
  else:
    bad.add(path[0])
        
print(N-len(bad))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

c = 0
for i in range(N-1):
    for j in range(i+A[i], N):
        if abs(i-j) == A[i] + A[j]:
            c += 1
            
print(c)

Fixed submission:
import collections
N = int(input())

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

plus = [0] * (N-1)
for i in range(N-1):
  plus[i] = i + A[i]

minus = [0] * (N-1)
for j in range(1, N):
  minus[j-1] = j - A[j]

sum = 0
c = dict(collections.Counter(minus))
for i in range(N-1):
  sum += c.get(plus[i], 0)
  c[minus[i]] -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

c = 0
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j) == A[i] + A[j]:
            c += 1
            
print(c)

Fixed submission:
import collections
N = int(input())

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

plus = [0] * (N-1)
for i in range(N-1):
  plus[i] = i + A[i]

minus = [0] * (N-1)
for j in range(1, N):
  minus[j-1] = j - A[j]

sum = 0
c = dict(collections.Counter(minus))
for i in range(N-1):
  sum += c.get(plus[i], 0)
  c[minus[i]] -= 1

print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())

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

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j) == a[i] + a[j]:
            count += 1
            
print(count)

Fixed submission:
import collections
N = int(input())

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

plus = [0] * (N-1)
for i in range(N-1):
  plus[i] = i + A[i]

minus = [0] * (N-1)
for j in range(1, N):
  minus[j-1] = j - A[j]

sum = 0
c = dict(collections.Counter(minus))
for i in range(N-1):
  sum += c.get(plus[i], 0)
  c[minus[i]] -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j) == A[i] + A[j]:
            count += 1
            
print(count)

Fixed submission:
import collections
N = int(input())

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

plus = [0] * (N-1)
for i in range(N-1):
  plus[i] = i + A[i]

minus = [0] * (N-1)
for j in range(1, N):
  minus[j-1] = j - A[j]

sum = 0
c = dict(collections.Counter(minus))
for i in range(N-1):
  sum += c.get(plus[i], 0)
  c[minus[i]] -= 1

print(sum)
Buggy python submission (verdict: Runtime Error):
import itertools
N, M, Q = map(int, input().split())
l = []
for _ in range(Q):
    l.append(tuple(map(int, input().split())))
    
c = itertools.combinations_with_replacement(list(range(1, M+1)), N)

m = 0
for i in c:
    flag = True
    sum = 0
    for j in l:
        if c[i[1]-1] - c[i[0]-1] == i[2]:
            sum += i[3]
    m = max(m, sum)
        
print(m)

Fixed submission:
import itertools
N, M, Q = map(int, input().split())
l = []
for _ in range(Q):
    l.append(tuple(map(int, input().split())))
    
c = list(itertools.combinations_with_replacement(list(range(1, M+1)), N))

m = 0
for i in c:
    flag = True
    sum = 0
    for j in l:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            sum += j[3]
    m = max(m, sum)
        
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, M, Q = map(int, input().split())
l = []
for _ in range(Q):
    l.append(tuple(map(int, input().split())))
    
c = list(itertools.combinations(list(range(1, M+1))*Q, N))

max = 0
for i in c:
    i = list(i)
    i.sort()
    sum = 0
    for j in l:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            sum += j[3]
    if max < sum:
        max = sum
        
print(max)

Fixed submission:
import itertools
N, M, Q = map(int, input().split())
l = []
for _ in range(Q):
    l.append(tuple(map(int, input().split())))
    
c = list(itertools.combinations_with_replacement(list(range(1, M+1)), N))

m = 0
for i in c:
    flag = True
    sum = 0
    for j in l:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            sum += j[3]
    m = max(m, sum)
        
print(m)
Buggy python submission (verdict: Runtime Error):
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)

Fixed submission:
s, w = map(int, input().split())

if s <= w:
  print('unsafe')
else:
  print('safe')

Buggy python submission (verdict: Runtime Error):
s, w = map(int, input().split())

if s =< w:
  print('unsafe')
else:
  print('safe')

Fixed submission:
s, w = map(int, input().split())

if s <= w:
  print('unsafe')
else:
  print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

l = [int(s[i:]) % 2019 for i in range(len(s))]
d = {}

for i in l:
  d[i] = d.get(i, 0) + 1

count = 0  
for i in d:
  count += d[i]*(d[i]-1)//2

count += l.count(0)

print(count)

Fixed submission:
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0

l = [int(s[i:]) % 2019 for i in range(len(s))]
d = {}

for i in l:
  d[i] = d.get(i, 0) + 1
  
for i in d:
  count += d[i]*(d[i]-1)//2

count += l.count(0)

print(count)

Fixed submission:
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
"""
2019 4038 6057 8076 10095
12114 14133 16152 18171
"""

s = input()
count = 0

for i in range(len(s)-4):
  for j in range(4, len(s)-i):
    if int(s[i:i+j+1]) % 2019 == 0:
      count += 1

if int(s[-4:])%2019 == 0:
  count += 1
print(count)

Fixed submission:
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

ans = [a.count(i+1) for i in range(n)]

for i in ans:
  print(i)

Fixed submission:
n = int(input())

a = [0 for _ in range(n)]
for i in input().split():
  a[int(i)-1] += 1


for i in a:
  print(i)
Buggy python submission (verdict: Runtime Error):
n = input()
sum = 0

for i in range(1, n+1):
  if i % 3 != 0 and i % 5 != 0:
    sum += i

print(sum)

Fixed submission:
n = int(input())
sum = 0

for i in range(1, n+1):
  if i % 3 != 0 and i % 5 != 0:
    sum += i

print(sum)
Buggy python submission (verdict: Runtime Error):
s = [1, 2, 3]
a = int(input())
b = int(input())

_ = s.pop(a-1)
_ = s.pop(b-1)

print(s[0])

Fixed submission:
a = int(input())
b = int(input())

for i in range(3):
  if i+1 != a and i+1 != b:
    print(i+1)

Buggy python submission (verdict: Runtime Error):
s = [1, 2, 3]
a = int(input())
b = int(input())

_ = s.pop(a)
_ = s.pop(b)

print(s[0])

Fixed submission:
a = int(input())
b = int(input())

for i in range(3):
  if i+1 != a and i+1 != b:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s, t = map(int, input().split())

for i, j in zip(s, t):
  print(s+t, end='')
  
print()

Fixed submission:
n = int(input())
s, t = input().split()

for i, j in zip(s, t):
  print(i+j, end='')
  
print()
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())

prime = [2]
for i in range(3, 10**5):
  flag = True
  for j in prime:
    if i % j == 0:
      flag = False
      break
  if flag:
    prime.append(i)

a_dict = dict()
b_dict = dict()

for i in prime:
  if a < i and b < i:
    break
  while a % i == 0:
    a /= i
    a_dict[i] = a_dict.get(i, 0) + 1
  while b % i == 0:
    b /= i
    b_dict[i] = b_dict.get(i, 0) + 1

ab = 1
for i in prime:
  ad = a_dict.get(i, 0)
  bd = b_dict.get(i, 0)
  n = ad if ad > bd else bd
  ab = ab * (i**n)
  
print(ab)

Fixed submission:
import math
a, b = map(int, input().split())

prime = [2]
for i in range(3, 10**5, 2):
  flag = True
  for j in prime:
    if j > math.sqrt(i):
      break
    if i % j == 0:
      flag = False
      break
  if flag:
    prime.append(i)

a_dict = dict()
b_dict = dict()
used = set()

for i in prime:
  if a < i and b < i:
    break
  while a % i == 0:
    a /= i
    a_dict[i] = a_dict.get(i, 0) + 1
    used.add(i)
  while b % i == 0:
    b /= i
    b_dict[i] = b_dict.get(i, 0) + 1
    used.add(i)

ab = 1
for i in used:
  ad = a_dict.get(i, 0)
  bd = b_dict.get(i, 0)
  n = ad if ad > bd else bd
  ab = ab * (i**n)
  
print(ab)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
news = ''
t = False
for i in range(len(S)-1):
    if t:
        t = False
        continue
    if S[i] == 'B' and S[i+1] == 'C':
        news += 'D'
        t = True
        continue
    news += S[i]

ans = 0
cnt = 0
for s in news:
    if s == 'A':
        cnt += 1
    elif s == 'D':
        ans += cnt
    else:
        cnt = 0

print(ans)

Fixed submission:
S = input()
news = S.replace('BC', 'D')

ans, cnt = 0, 0
for s in news:
    if s == 'A':
        cnt += 1
    elif s == 'D':
        ans += cnt
    else:
        cnt = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
while len(A) > 1:
    tmp = A[0] % A[1]
    A = A[1:]
    if tmp == 0:
        continue
    i = 0
    while i < len(A) and A[i] > tmp:
        i += 1
    if i == len(A):
        A.append(tmp)
    else:
        A.insert(i, tmp)

print(A[0])

Fixed submission:
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))

print(reduce(math.gcd, A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
while len(A) > 1:
    tmp = A[0] % A[1]
    A = A[1:]
    if tmp == 0:
        continue
    i = 0
    while i < len(A) and A[i] > tmp:
        i += 1
    if i == len(A):
        A.append(tmp)
    else:
        A.insert(i, tmp)

print(A[0])

Fixed submission:
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))

print(reduce(math.gcd, A))
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())
dp = np.zeros((N+1, W+1), dtype=int)

w,v = [],[]
for _ in range(N):
    w_,v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)

for row in range(N):
    dp[row+1,:w[row]] = dp[row,:w[row]]
    dp[row+1,w[row]:] = np.maximum(dp[row,w[row]:],v[row]+dp[row,:-w[row]])

print(dp[N,-1])

Fixed submission:
import numpy as np
N, W = map(int, input().split())
dp = np.zeros((N+1, W+1), dtype=int)

w,v = [],[]
for _ in range(N):
    w_,v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)

for row in range(N):
    dp[row+1,:w[row]] = dp[row,:w[row]]
    dp[row+1,w[row]:] = np.maximum(dp[row,w[row]:],v[row]+dp[row,:-w[row]])

print(dp[N,-1])