Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02787 (python)

Fixed submission:
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])

Buggy submission (verdict: Runtime Error):
from math import ceil

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(N)] for j in range(H+1)]

for i in range(1, H+1):
    a = AB[-1][0]
    b = AB[-1][1]
    dp[i][N-1] = ceil(i / a)*b

for j in range(0, N-1)[::-1]:
    for i in range(1, H+1):
        a = AB[j][0]
        b = AB[j][1]
        x_list = []
        for k in range(0, int(ceil(i/a))+1):
            new_i = i - a*k
            x = dp[new_i][j+1] + b*k
            x_list.append(x)
        dp[i][j] = min(x_list)

print(dp[H][0])
Problem p02900 (python)

Fixed submission:
from fractions import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)
if n > 1:
    ans.add(n)

print(len(ans)+1)

Buggy submission (verdict: Runtime Error):
from functools import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)

print(len(ans)+1)

Buggy submission (verdict: Runtime Error):
from math import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)

print(len(ans)+1)
Problem p02909 (python)

Fixed submission:
S = input()

if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
 
def zal(s):
    i = 1
    j = 0
    _N = len(s)
    Z = [0]*_N
    Z[0] = _N
    res = 0
    while i < _N:
        while i + j < _N and s[j] == s[i+j]:
            j += 1
        Z[i] = j
 
        if Z[i] <= i:
            res = max(res, Z[i])
 
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < _N and k + Z[k] < j:
            Z[i+k] = Z[k]
 
            if Z[i+k] <= i+k:
                res = max(res, Z[i+k])
 
            k += 1
        i += k
        j -= k
    return res
 
ans = 0
for i in range(N):
    _S = S[i:]
    res = zal(_S)
    ans = max(ans, res)
print(ans)
Problem p03006 (python)

Fixed submission:

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort(key=lambda x: x[0])
tilt_map = {}

if N == 1:
    print(1)
else:
    for i in range(N):
        for j in range(i+1, N):
            a = xy[i]
            b = xy[j]
            tilt_x = a[0] - b[0]
            tilt_y = a[1] - b[1]
            if tilt_x == 0 and tilt_y < 0:
                tilt_y *= -1
            key = str(tilt_x) + ":" + str(tilt_y)
            if key in tilt_map:
                tilt_map[key] += 1
            else:
                tilt_map[key] = 1


    most_tilt = sorted(tilt_map.items(), key=lambda x: x[1], reverse=True)[0][1]
    print(N-most_tilt)

Buggy submission (verdict: Runtime Error):
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

tilt_map = {}

for i in range(N):
    for j in range(i+1, N):
        a = xy[i]
        b = xy[j]
        tilt_x = a[0] - b[0]
        tilt_y = a[1] - b[1]
        key = str(tilt_x) + ":" + str(tilt_y)
        if key in tilt_map:
            tilt_map[key] += 1
        else:
            tilt_map[key] = 1


most_key = sorted(tilt_map.items(), key=lambda x: x[1], reverse=True)[0][0]

idx = most_key.index(":")
m_dx = int(most_key[:idx])
m_dy = int(most_key[idx+1:])

if m_dx == 0:
    if m_dy < 0:
        m_dy *= -1
    xy.sort(key=lambda x: x[1])
else:
    if m_dx < 0:
        m_dx *= -1
        m_dy *= -1
    xy.sort(key=lambda x:x[0])

pos = xy.pop(0)
cost = 1

while len(xy) > 0:
    next_x = pos[0] + m_dx
    next_y = pos[1] + m_dy
    for _xy in xy[::]:
        if _xy[0] == next_x and _xy[1] == next_y:
            xy.remove([next_x, next_y])
            pos = [next_x, next_y]
            break
    else:
        pos = xy.pop(0)
        cost += 1
print(cost)
Problem p03007 (python)

Fixed submission:
from collections import deque

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

a.sort()

if a[0] >= 0:
    m = sum(a[1:]) - a[0]
    print(m)
    p = a.pop(0)
    while len(a) > 1:
        b = a.pop(0)
        print(*[p, b])
        p -= b
    b = a.pop()
    print(*[b, p])
elif a[-1] <= 0:
    m = -sum(a[:-1])+a[-1]
    print(m)
    p = a.pop(-1)
    while len(a) > 0:
        b = a.pop(0)
        print(*[p, b])
        p -= b
else:
    mi = list(filter(lambda x: x < 0, a))
    pl = list(filter(lambda x: x >= 0, a))
    m = -sum(mi) + sum(pl)
    print(m)
    lp = pl.pop(0)
    mi = deque(mi)
    while len(pl) > 0:
        b = pl.pop()
        c = mi.pop()
        print(*[c, b])
        c -= b
        mi.append(c)
    while len(mi) > 0:
        b = mi.pop()
        print(*[lp, b])
        lp -= b

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

a.sort()
xy = [[] for i in range(N-1)]
cnt = 0
while len(a) > 2:
    if a[len(a)-1] > 0 and a[len(a)-2] > 0:
        n = a[0] - a[len(a)-1]
        xy[cnt] = [a[0], a[len(a)-1]]
        a = [n]
        a.extend(a[1:len(a) - 1])
    else:
        n = a[len(a)-1] - a[0]
        xy[cnt] = [a[len(a)-1], a[0]]
        a = a[1:len(a) - 1]
        a.extend([n])
    cnt += 1

m = a[1] - a[0]
xy[cnt] = [a[1], a[0]]
print(m)
for _xy in xy:
    print(str(_xy[0]) + " " + str(_xy[1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

a.sort()
xy = [[] for i in range(N-1)]
cnt = 0
while len(a) > 2:
    if a[len(a)-1] > 0 and a[len(a)-2] > 0:
        n = a[0] - a[len(a)-1]
        xy[cnt] = [a[0], a[len(a)-1]]
        a = [n].extend(a[1:len(a) - 1])
    else:
        n = a[len(a)-1] - a[0]
        xy[cnt] = [a[len(a)-1], a[0]]
        a = a[1:len(a) - 1].extend([n])
    cnt += 1

m = a[1] - a[0]
xy[cnt] = [a[1], a[0]]
print(m)
for _xy in xy:
    print(str(_xy[0]) + " " + str(_xy[1]))
Problem p03047 (python)

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

print(N + 1 - K)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input())

print(N + 1 - K)
Problem p03067 (python)

Fixed submission:
a, b, c = [int(i) for i in input().split()]

if a <= c and c <= b:
    print("Yes")
elif b <= c and c <= a:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]

if a <= c and c <= b:
    print("Yes")
elif: b <= c and c <= a:
    print("Yes")
else:
    print("No")
Problem p03074 (python)

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

s = '1' + s + '1'

cnt_1 = []
cnt_0 = []
stack_1 = 0
stack_0 = 0
for i in s:
    if i == '1':
        if stack_0 > 0:
            cnt_0.append(stack_0)
            stack_0 = 0
        stack_1 += 1
    else:
        if stack_1 > 0:
            cnt_1.append(stack_1)
            stack_1 = 0
        stack_0 += 1
if stack_1 > 0:
    cnt_1.append(stack_1)

if len(cnt_1) == 0 or len(cnt_0) == 0:
    print(n)
    exit()
cnt_1[0] -= 1
cnt_1[-1] -= 1

if k > len(cnt_0):
    k = len(cnt_0)
cum_1 = [sum(cnt_1[:k+1])]
cum_0 = [sum(cnt_0[:k])]
for i in range(1, len(cnt_1)-k):
    cum = cum_1[i-1] + cnt_1[i+k] - cnt_1[i-1]
    cum_1.append(cum)
for i in range(1, len(cnt_0)-k+1):
    cum = cum_0[i-1] + cnt_0[i+k-1] - cnt_0[i-1]
    cum_0.append(cum)
res = []

for v, w in zip(cum_1, cum_0):
    res.append(v+w)
print(max(res))

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

s = '1' + s + '1'

cnt_1 = []
cnt_0 = []
stack_1 = 0
stack_0 = 0
for i in s:
    if i == '1':
        if stack_0 > 0:
            cnt_0.append(stack_0)
            stack_0 = 0
        stack_1 += 1
    else:
        if stack_1 > 0:
            cnt_1.append(stack_1)
            stack_1 = 0
        stack_0 += 1
if stack_1 > 0:
    cnt_1.append(stack_1)

if len(cnt_1) == 0 or len(cnt_0) == 0:
    print(n)
    exit()
cnt_1[0] -= 1
cnt_1[-1] -= 1
cum_1 = []
cum_0 = []
for i in range(len(cnt_1)-k):
    cum_1.append(sum(cnt_1[i:i+k+1]))
for i in range(len(cnt_0)-k+1):
    cum_0.append(sum(cnt_0[i:i+k]))

res = []
for v, w in zip(cum_1, cum_0):
    res.append(v+w)
print(max(res))

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

s = '1' + s + '1'

cnt_1 = []
cnt_0 = []
stack_1 = 0
stack_0 = 0
for i in s:
    if i == '1':
        if stack_0 > 0:
            cnt_0.append(stack_0)
            stack_0 = 0
        stack_1 += 1
    else:
        if stack_1 > 0:
            cnt_1.append(stack_1)
            stack_1 = 0
        stack_0 += 1
if stack_1 > 0:
    cnt_1.append(stack_1)
cnt_1[0] -= 1
cnt_1[-1] -= 1
if len(cnt_1) == 0 or len(cnt_0) == 0:
    print(n)
    exit()
cum_1 = []
cum_0 = []
for i in range(len(cnt_1)-k):
    cum_1.append(sum(cnt_1[i:i+k+1]))
for i in range(len(cnt_0)-k+1):
    cum_0.append(sum(cnt_0[i:i+k]))

res = []
for v, w in zip(cum_1, cum_0):
    res.append(v+w)
print(max(res))
Problem p03096 (python)

Fixed submission:
n = int(input())
c = [int(input()) for _ in range(n)]
v_c = []
MOD = 10**9+7

for i,v in enumerate(c):
    if i > 0 and v == c[i-1]:
        continue
    v_c.append(v)

dp = [1]*(n+1)
color_cnt = [-1]*(2*10**5+5)
for i in range(1, len(v_c)+1):
    color = v_c[i-1]
    if color_cnt[color] > 0:
        dp[i] = dp[i-1] + dp[color_cnt[color]]
    else:
        dp[i] = dp[i-1]
    dp[i] %= MOD
    color_cnt[color] = i
print(dp[len(v_c)])

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [int(input()) for _ in range(n)]
v_c = []
for i,v in enumerate(c):
    if i > 0 and v == c[i-1]:
        continue
    v_c.append(v)

dp = [1]*(n+1)
color_cnt = [-1]*(2*10**5)
for i in range(len(v_c)-1, -1, -1):
    color = v_c[i]
    if color_cnt[color] > 0:
        # 増やす
        dp[i] = dp[i+1] + dp[color_cnt[color]]
    else:
        dp[i] = dp[i+1]
    color_cnt[color] = i
print(dp[0])
Problem p03106 (python)

Fixed submission:
from fractions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
from functions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
from functools import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break
Problem p03138 (python)

Fixed submission:
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(41)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i

ans = 0
for _a in a:
    ans += x ^ _a
print(ans)

Buggy submission (verdict: Runtime Error):
from math import log2
N, K = map(int, input().split())
a = list(map(int, input().split()))
x = 0
if K == 0:
    x = 0
else:
    for i in range(int(log2(K))+1)[::-1]:
        cnt_1 = 0
        for _a in a:
            if _a & 2**i == 2**i:
                cnt_1 += 1
        if cnt_1 <= len(a)/2 and (x + 2**i) <= K:
            x += 2**i
            
ans = 0
for _a in a:
    ans += x ^ _a
print(ans)
Problem p03196 (python)

Fixed submission:
import os
N, P = map(int, input().split())

def trial_division(n):
    if n < 2:
        return []
    prime_factors = []
    for p in range(2, int( n**0.5)):
        if p*p > n: break
        cnt = 0
        while n % p == 0:
            cnt += 1
            n //= p
        prime_factors.append([p, cnt])
    if n > 1:
        prime_factors.append([n, 1])
    return prime_factors

prime_factors = trial_division(P)
ans = 1
for p in prime_factors:
    if p[1] >= N:
        ans *= p[0]**(p[1] // N)
print(ans)

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())

i = 2
ans = 1
while True:
    if i**N > P:
        break
    if P % i**N == 0:
        P /= i**N
        ans *= i
    else:
        i += 1

print(ans)
Problem p03262 (python)

Fixed submission:
import fractions
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]

x_list.sort()

current_gcd = 0
for i in range(0, n):
    gap = abs(start - x_list[i])
    current_gcd = fractions.gcd(current_gcd, gap)

print(current_gcd)

Buggy submission (verdict: Runtime Error):
import function
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]
x_list.append(start)
x_list.sort()


current_gcd = x_list[1] - x_list[0]
for i in range(1, n-1):
    gap = x_list[i+1] - x_list[i]
    current_gcd = function.gcd(current_gcd, gap)

print(current_gcd)
Problem p03280 (python)

Fixed submission:
a, b = [int(i) for i in input().split()]

print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print((a-1)*(b-1))
Problem p03283 (python)

Fixed submission:
N,M,Q = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
 
for _ in range(M):
    L,R = map(int,input().split())
    l[L-1][R-1] += 1
 
csum = [[0 for i in range(N+1)] for j in range(N+1)]
 
for i in range(1,N+1):
    for j in range(1,N+1):
        csum[i][j] = csum[i][j-1] + csum[i-1][j] - csum[i-1][j-1] + l[i-1][j-1]
 
for _ in range(Q):
    p,q = map(int,input().split())
    print(csum[q][q]-csum[q][p-1]-csum[p-1][q]+csum[p-1][p-1])

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
start_sets = [set() for _ in range(n+2)]
end_sets = [set() for _ in range(n+2)]
for i in range(m):
    l, r = map(int, input().split())
    start_sets[l].add(i)
    end_sets[r].add(i)

for i in range(1, n+2):
    start_sets[i] |= start_sets[i-1]
    end_sets[i] |= end_sets[i-1]

ans = []
for _ in range(q):
    p, q = map(int, input().split())
    start = start_sets[q]-start_sets[p-1]
    end = end_sets[q] - end_sets[p-1]
    res = start & end
    ans.append(len(res))
print(*ans, sep="\n")
Problem p03297 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    if b > a:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if c > b:
        print('Yes')
        continue
    g = gcd(b, d)
    max_mod_b = b - g + a % g
    if max_mod_b > c:
        print('No')
    else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
import math
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    if b > a:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if c > b:
        print('Yes')
        continue
    g = math.gcd(b, d)
    max_mod_b = b - g + a % g
    if max_mod_b > c:
        print('No')
    else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
import math
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    _a = a
    is_ok = True
    for j in range(10000):
        if b > a:
            is_ok = False
            break
        if b > d:
            is_ok = False
            break
        if c > b:
            is_ok = True
            break
        g = math.gcd(b, d)
        max_mod_b = b - g + a % g
        if max_mod_b > c:
            print('No')
        else:
            print('Yes')

Buggy submission (verdict: Runtime Error):
import math
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    _a = a
    is_ok = True
    for j in range(10000):
        if b > a:
            is_ok = False
            break
        if b > d:
            is_ok = False
            break
        if c > b:
            is_ok = True
            break
        g = math.gcd(b, d)
        max_mod_b = b - g + a & g
        if max_mod_b > c:
            print('Yes')
        else:
            print('No')
Problem p03387 (python)

Fixed submission:
A, B, C = map(int, input().split())

is_odd_list = [A % 2 == 0, B % 2 == 0, C % 2 == 0]
if all(is_odd_list) or not any(is_odd_list):
    ans = 0
else:
    if sum(is_odd_list) == 1:
        is_odd_list = [not i for i in is_odd_list]
    A = A + is_odd_list[0]
    B = B + is_odd_list[1]
    C = C + is_odd_list[2]
    ans = 1

num_list = sorted([A, B, C])
ans += (num_list[2] - num_list[0]) / 2 + (num_list[2] - num_list[1]) / 2
print(int(ans))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

is_odd_list = [A % 2 == 0, B % 2 == 0, C % 2 == 0]
if all(is_odd_list) or not any(is_odd_list):
    ans = 0
else:
    if sum(is_odd_list) == 1:
        is_odd_list = not is_odd_list
    A = A + is_odd_list[0]
    B = B + is_odd_list[1]
    C = C + is_odd_list[2]
    ans = 1

num_list = sorted([A, B, C])
ans += (num_list[2] - num_list[0]) / 2 + (num_list[2] - num_list[1]) / 2
print(int(ans))
Problem p03651 (python)

Fixed submission:
from functools import reduce
from fractions import gcd

POSSIBLE = "POSSIBLE"
IMPOSSIBLE = "IMPOSSIBLE"
n, k = map(int, input().split())
a = list(map(int, input().split()))

# max(a) < k → だめ
# N == 1 ぴったじゃなきゃだめ
# N > 1
## 互いに素な数が含まれている → ○
## 含まれてないが、kがその倍数 → ○
if max(a) < k:
    print(IMPOSSIBLE)
    exit()
if n == 1:
    if k == a[0]:
        print(POSSIBLE)
    else:
        print(IMPOSSIBLE)
else:
    g = reduce(lambda a, b: gcd(a, b), a)
    if g == 1:
        print(POSSIBLE)
    else:
        if k % g == 0:
            print(POSSIBLE)
        else:
            print(IMPOSSIBLE)

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce
from math import gcd

POSSIBLE = "POSSIBLE"
IMPOSSIBLE = "IMPOSSIBLE"
n, k = map(int, input().split())
a = list(map(int, input().split()))

# max(a) < k → だめ
# N == 1 ぴったじゃなきゃだめ
# N > 1
## 互いに素な数が含まれている → ○
## 含まれてないが、kがその倍数 → ○
if max(a) < k:
    print(IMPOSSIBLE)
    exit()
if n == 1:
    if k == a[0]:
        print(POSSIBLE)
    else:
        print(IMPOSSIBLE)
else:
    g = reduce(lambda a, b: gcd(a, b), a)
    if g == 1:
        print(POSSIBLE)
    else:
        if k % g == 0:
            print(POSSIBLE)
        else:
            print(IMPOSSIBLE)
Problem p03680 (python)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]

can = False
cnt = 0
idx = a[0]-1
while True:
    cnt += 1
    if cnt > N:
        break
    if idx == 1:
        can = True
        break
    idx = a[idx] - 1

if can:
    print(cnt)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]

stack = [2]

can = False
while True:
    if stack[len(stack)-1] == 1:
        can = True
        break
    c = stack[len(stack)-1]
    i = a.index(c)+1
    if i in stack:
        break
    stack.append(i)

if can:
    print(len(stack)-1)
else:
    print(-1)
Problem p02631 (python)

Fixed submission:
#import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
    all_xor = all_xor ^ _a
for _a in a:
    print(all_xor ^ _a)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
    all_xor = all_xor ^ _a
for _a in a:
    print(all_xor ^ _a)
Problem p02687 (python)

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [[] for i in range(M)]
for i in range(M):
    AB[i] = list(map(int, input().split()))

cnt = 0
memo_loser = []
for bridge in AB:
    

    value = min(H[bridge[0]-1], H[bridge[1]-1])
    if value == H[bridge[0]-1] and not bridge[0] in memo_loser:
        memo_loser.append(bridge[0])
    if value == H[bridge[1] - 1] and not bridge[1] in memo_loser:
        memo_loser.append(bridge[1])
print(N - len(memo_loser))
Problem p02900 (python)

Fixed submission:
from math import gcd
import random
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


def is_prime3(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


A, B = map(int, input().split())
l = make_divisors(gcd(A, B))
_l = factorization(gcd(A, B))
ans = 0
#print(gcd(A, B))
#print(l)
#print(_l)
for num in l:
    if is_prime3(num):
        #print(num)
        ans += 1
print(ans + 1)

Buggy submission (verdict: Runtime Error):
from math import gcd
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    #return pow(2, q-1, q) == 1
    return (2 ** (q - 1)) % q == 1


A, B = map(int, input().split())
l = make_divisors(gcd(A, B))
ans = 0
for num in l:
    if is_prime(num):
        ans += 1
print(ans + 1)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
dif = r - l
ans = 30000
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r >= 673:
            ans = 0
        else:
            for i in range(mod_l, mod_r + 1):
                for j in range(i + 1, mod_r + 1):
                    ans = min(ans, (i * j) % 2019)
    else:
        ans = 0
#print(dif, mod_l, mod_r)
print(ans%2019)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
dif = r - l
ans = 0
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r <= 673:
            ans = 0
        else:
            ans = mod_l * (mod_l + 1)
    else:
        ans = 0
print(dif, mod_l, mod_r)
print(ans%2019)