Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())

E = lcm(C, D)
count_A = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//E
count_B = B - B//C - B//D + B//E

print(count_B - count_A)

Fixed submission:
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
if A % C == 0:
    ac -= 1
if A % D == 0:
    ad -= 1
if A % E == 0:
    ae -= 1
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Buggy python submission (verdict: Runtime Error):
# C問題
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Fixed submission:
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
if A % C == 0:
    ac -= 1
if A % D == 0:
    ad -= 1
if A % E == 0:
    ae -= 1
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
i = 1
while D <= X:
    D += L[i-1]
    i += 1
print(i-1)

Fixed submission:
# -*-coding: utf-8 -*-
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
for i in range(1, N+1):
    D += L[i-1]
    # print(i+1, D)
    if D > X:
        ans = i
        break
    if i == N:
        ans = i+1

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key = lambda x:(-x[1]))

i_a = 0
i_bc = 0
while i_a < N:
    if i_bc == M:
        break
    for j in range(BC[i_bc][0]):
        if i_a + j > N:
            i_a = N
            continue
        if A[i_a + j] >= BC[i_bc][1]:
            i_a = N
        else:
            A[i_a + j] = BC[i_bc][1]
    i_a += BC[i_bc][0]
    i_bc += 1

print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key = lambda x:(-x[1]))

i_a = 0
i_bc = 0
while i_a < N:
    if i_bc == M:
        break
    for j in range(BC[i_bc][0]):
        if i_a + j >= N:
            i_a = N
            continue
        if A[i_a + j] >= BC[i_bc][1]:
            i_a = N
        else:
            A[i_a + j] = BC[i_bc][1]
    i_a += BC[i_bc][0]
    i_bc += 1

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
#B問題
R, G, B, N = map(int, input().split())

ans = 0
for r in range(0, N // R + 1):
    for g in range(0, N // G + 1):
        if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
            ans += 1
print(ans)            

Fixed submission:
#B問題
import math
R, G, B, N = map(int, input().split())

ans = 0
if R == G == B == 1:
    print (int((N+2)*(N+1)/2))
else:
    for r in range(0, N // R + 1):
        for g in range(0, N // G + 1):
            if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
                ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#B問題
R, G, B, N = map(int, input().split())

ans = 0
for r in range(0, N // R + 1):
    for g in range(0, 3001 - r):
        if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
            ans += 1
print(ans)            

Fixed submission:
#B問題
import math
R, G, B, N = map(int, input().split())

ans = 0
if R == G == B == 1:
    print (int((N+2)*(N+1)/2))
else:
    for r in range(0, N // R + 1):
        for g in range(0, N // G + 1):
            if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
                ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#B問題
R, G, B, N = map(int, input().split())

ans = 0
for r in range(0, 3001):
    for g in range(0, 3001 - r):
        if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
            ans += 1
print(ans)            

Fixed submission:
#B問題
import math
R, G, B, N = map(int, input().split())

ans = 0
if R == G == B == 1:
    print (int((N+2)*(N+1)/2))
else:
    for r in range(0, N // R + 1):
        for g in range(0, N // G + 1):
            if (N - R*r - G*g) % B == 0 and (N - R*r - G*g)/B >=0:
                ans += 1
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A
# http://drken1215.hatenablog.com/entry/2019/05/05/223200
# を参考に解いた
# 多点スタートと考えて解く

from collections import deque
# 入力
H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

# 4方向を定義
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

# BFSのためのデータ構造
dist = [[-1] * W for _ in range(H)]
que_x = deque()     # H
que_y = deque()     # W

# 多点スタート地点を決める
# スタート地点は0とする
for i in range(H):
    for k in range(W):
        if field[i][k] == "#":
            dist[i][k] = 0
            que_x.append(i)
            que_y.append(k)

# 多点スタート
# 0のところから順に1を増やしていく
# ex): 3地点a, b, cからスタートとすると
# aから周囲4箇所に1をつける -> bから周囲4箇所に1をつける -> cから周囲4箇所に1をつける
# aの周囲4箇所の内1点から周囲4箇所に2をつける -> aの周囲4箇所の内2点目から周囲4箇所に2をつける
# aの周囲4箇所が終われば次はbの周囲4箇所，それが終わればcの周囲4箇所
while que_x and que_y:
    x = que_x[0]
    y = que_y[0]
    que_x.popleft()
    que_y.popleft()
    for direct in range(4):
        nx = x + dx[direct]
        ny = y + dy[direct]
        if nx < 0 or H <= nx or ny < 0 or W <= ny:      # 場外はスルー
            continue
        if dist[nx][ny] == -1:      # まだ見ていない時
            que_x.append(nx)
            que_y.append(ny)
            dist[nx][ny] = dist[x][y] + 1       # 距離の更新

# distの最大値が答え (= 最も遠いところ)
tmp = [0] * H
for i in range(H):
    tmp[i] = max(dist[i])

print(max(tmp))

Fixed submission:
# AGC033A
# http://drken1215.hatenablog.com/entry/2019/05/05/223200
# を参考に解いた
# 多点スタートと考えて解く

from collections import deque
# 入力
H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

# 4方向を定義
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

# BFSのためのデータ構造
dist = [[-1] * W for _ in range(H)]
que_x = deque()     # H
que_y = deque()     # W

# 多点スタート地点を決める
# スタート地点は0とする
for i in range(H):
    for k in range(W):
        if field[i][k] == "#":
            dist[i][k] = 0
            que_x.append(i)
            que_y.append(k)

# 多点スタート
# 0のところから順に1を増やしていく
# ex): 3地点a, b, cからスタートとすると
# aから周囲4箇所に1をつける -> bから周囲4箇所に1をつける -> cから周囲4箇所に1をつける
# aの周囲4箇所の内1点から周囲4箇所に2をつける -> aの周囲4箇所の内2点目から周囲4箇所に2をつける
# aの周囲4箇所が終われば次はbの周囲4箇所，それが終わればcの周囲4箇所
while que_x and que_y:
    x = que_x[0]
    y = que_y[0]
    que_x.popleft()
    que_y.popleft()
    for direct in range(4):
        nx = x + dx[direct]
        ny = y + dy[direct]
        if nx < 0 or H <= nx or ny < 0 or W <= ny:      # 場外はスルー
            continue
        if dist[nx][ny] == -1:      # まだ見ていない時
            que_x.append(nx)
            que_y.append(ny)
            dist[nx][ny] = dist[x][y] + 1       # 距離の更新

# distの最大値が答え (= 最も遠いところ)
tmp = [0] * H
for i in range(H):
    tmp[i] = max(dist[i])

print(max(tmp))
Buggy python submission (verdict: Runtime Error):
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))

Fixed submission:
b = input()
if b == "A":
    print("T")
elif b == "T":
    print("A")
elif b == "C":
    print("G")
else:
    print("C")
Buggy python submission (verdict: Time Limit Exceeded):
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
cnt_list = [0] * N
tmp = 0
for i in range(N):
    if i in ind:
        tmp += 1
    cnt_list[i] = tmp
##print(cnt_list)

for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])

Fixed submission:
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
cnt_list = [0] * N
tmp = 0
for i in range(N-1):
    cnt_list[i] = tmp
    if S[i] == "A" and S[i+1] == "C":
        tmp += 1
cnt_list[N-1] = tmp
##print(cnt_list)
for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])

Buggy python submission (verdict: Runtime Error):
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))

Fixed submission:
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
cnt_list = [0] * N
tmp = 0
for i in range(N-1):
    cnt_list[i] = tmp
    if S[i] == "A" and S[i+1] == "C":
        tmp += 1
cnt_list[N-1] = tmp
##print(cnt_list)
for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])

Buggy python submission (verdict: Time Limit Exceeded):
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))

Fixed submission:
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
cnt_list = [0] * N
tmp = 0
for i in range(N-1):
    cnt_list[i] = tmp
    if S[i] == "A" and S[i+1] == "C":
        tmp += 1
cnt_list[N-1] = tmp
##print(cnt_list)
for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])
Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF
    ret1 = dfs(cur+1, a, b, c)
    ret2 = dfs(cur+1, a+L[cur], b, c) + 10
    ret3 = dfs(cur+1, a, b+L[cur], c) + 10
    ret4 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret1 + ret2 + ret3 + ret4)

print(dfs(0,0,0,0))


Fixed submission:
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

ans = 10 ** 10

# 4bit search
for i in range(4**N):
    mask = i
    NowCost = 0
    Group0 = []
    Group1 = []
    Group2 = []
    NonGroup = []
    for j in range(N-1, -1, -1):
        if mask % 4 == 0:
            Group0.append(L[j])
            mask //= 4
        elif mask % 4 == 1:
            Group1.append(L[j])
            mask //= 4
        elif mask % 4 == 2:
            Group2.append(L[j])
            mask //= 4
        else:
            NonGroup.append(L[j])
            mask //= 4
    if len(Group0) == 0 or len(Group1) == 0 or len(Group2) == 0:
        continue
    NowCost += 10 * (len(Group0) - 1)
    LengthGroup0 = sum(Group0)
    NowCost += 10 * (len(Group1) - 1)
    LengthGroup1 = sum(Group1)
    NowCost += 10 * (len(Group2) - 1)
    LengthGroup2 = sum(Group2)
    NowCost += abs(A - LengthGroup0)
    NowCost += abs(B - LengthGroup1)
    NowCost += abs(C - LengthGroup2)
    ans = min(ans, NowCost)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#C Monsters Battle Rpyale

N = int(input())
monster_life_lst = list(map(int, input().split()))
flag = False 
while True:
    monster_life_lst.sort()
    if len(monster_life_lst) == 1:
        flag = True
        out_flag = monster_life_lst[0]
        break
    else:
        monster_life_lst[1] -= monster_life_lst[0]
        if monster_life_lst[1] == 0:
            monster_life_lst.remove(0)

def out(out_flag):
    print(out_flag)

out(out_flag)

Fixed submission:
n = int(input())
monster_life_lst = list(map(int, input().split()))


while True:
    while 0 in monster_life_lst:
        monster_life_lst.remove(0)
    monster_life_lst.sort()
    for i in range(1, len(monster_life_lst)):
        monster_life_lst[i] = monster_life_lst[i] % monster_life_lst[0]
    if len(monster_life_lst) == 1:
        out_flag = monster_life_lst[0]
        break

def out(out_flag):
    print(out_flag)

out(out_flag)
Buggy python submission (verdict: Time Limit Exceeded):
#C
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]

x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
else:
    xl = []
    for i in range(0, m-1):
        xl.append(x[i+1] - x[i])
    k = 1
    while k < n:
        xl.remove(max(xl))
        k += 1
    print(sum(xl))

Fixed submission:
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]

x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
else:
    xl = []
    for i in range(0, m-1):
        xl.append(x[i+1] - x[i])
    xl.sort(reverse = True)
    del xl[:n-1]
    print(sum(xl))

Buggy python submission (verdict: Runtime Error):
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]

x = list(map(int, input().split()))
x.sort()
if m == 1:
    print(0)
else:
    xl = []
    for i in range(0, m-1):
        xl.append(x[i+1] - x[i])
    k = 1
    while k < n:
        xl.remove(max(xl))
        k += 1
    print(sum(xl))

Fixed submission:
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]

x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
else:
    xl = []
    for i in range(0, m-1):
        xl.append(x[i+1] - x[i])
    xl.sort(reverse = True)
    del xl[:n-1]
    print(sum(xl))
Buggy python submission (verdict: Time Limit Exceeded):
# # Educational DP Contest B
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float("inf")] * N

dp[0] = 0
for i in range(1, N):
    cost_list = [float("inf")] * K
    for k in range(1, K+1):
        if i - k < 0:
            break
        cost_list[k-1] = dp[i-k] + abs(H[i] - H[i-k])
    dp[i] = min(cost_list)
print(dp[N-1])

Fixed submission:
# # Educational DP Contest B
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float("inf")] * N

dp[0] = 0
for i in range(1, N):
    cost_list = [float("inf")] * K
    for k in range(1, K+1):
        if i - k < 0:
            break
        cost_list[k-1] = dp[i-k] + abs(H[i] - H[i-k])
    dp[i] = min(cost_list)
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
# # Educational DP Contest D
# 方針：dp[i][w] := i番目の物の中から，重さwを超えない時の価値の最大値
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+10) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w >= wv[i][0]:       # 重さwv[i][0]を入れられるか
            dp[i+1][w] = max(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])

Fixed submission:
# # Educational DP Contest D
# 方針：dp[i][w] := i番目の物の中から，重さwを超えない時の価値の最大値
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+10) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w >= wv[i][0]:       # 重さwv[i][0]を入れられるか
            dp[i+1][w] = max(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, X = map(int, input().split())

def burger(n):
    if n == 0:
        return 'P'
    ans = 'B' + burger(n-1) + 'P' + burger(n-1) + 'B'
    return ans

eat = burger(N)[ : X]
print(eat.count('P'))

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

a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count = 0

for i in range(1, N+1):
    ii = str(i)
    if "0" in ii or "1" in ii or "2" in ii or "4" in ii or "6" in ii or "8" in ii or "9" in ii:
        pass
    elif "3" in ii and "5" in ii and "7" in ii:
        count += 1
    else:
        pass

print(count)


Fixed submission:
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ans = 1 if all (s.count(c) > 0 for c in "753") else 0
    
    for c in "753":
        ans += dfs(s+c)
    return ans
print(dfs('0'))
Buggy python submission (verdict: Runtime Error):
# AGC028
#from fractions import gcd
from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
l = lcm(N, M)

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

if N == l:
    tmp = N // M
    for i in range(tmp):
        if S[i * tmp] == T[i]:
            pass
        else:
            print(-1)
            exit()
if M == l:
    tmp = M // N
    for i in range(tmp):
        if T[i * tmp] == S[i]:
            pass
        else:
            print(-1)
            exit()

G = gcd(N, M)
if G != 1:
    for g in range(G):
        if S[g * N // G] == T[g * M // G]:
            pass
        else:
            print(-1)
            exit()
print(l)

Fixed submission:
# AGC028
from fractions import gcd
#from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
l = lcm(N, M)
if S[0] != T[0]:
    print(-1)
    exit()
if N == 1 or M == 1:
    if N == 1:
        print(M)
    if M == 1:
        print(N)
    exit()

if N == l:
    tmp = N // M
    for i in range(tmp):
        if S[i * tmp] == T[i]:
            pass
        else:
            print(-1)
            exit()
if M == l:
    tmp = M // N
    for i in range(tmp):
        if T[i * tmp] == S[i]:
            pass
        else:
            print(-1)
            exit()

G = gcd(N, M)
if G != 1:
    for g in range(G):
        if S[g * N // G] == T[g * M // G]:
            pass
        else:
            print(-1)
            exit()
print(l)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N, M = map(int, input().split())
k = 0
while True:
    if M % (N + k) == 0:
        ans = M // (N+k)
        break
    k += 1
print(ans)

Fixed submission:
def is_prime(N):
    if N == 1:
        return False
    for k in range(2, int(N**0.5) + 1):
        if N % k == 0:
            return False
    return True


N, M = map(int, input().split())
k = 0
if N != 1:
    if is_prime(M):
        print(1)
        exit()
while True:
    if M % (N + k) == 0:
        ans = M // (N+k)
        break
    k += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N, M = map(int, input().split())
k = 0
while True:
    if M % (N + k) == 0:
        ans = M // (N+k)
        break
    k += 1
print(ans)

Fixed submission:
def is_prime(N):
    if N == 1:
        return False
    for k in range(2, int(N**0.5) + 1):
        if N % k == 0:
            return False
    return True


N, M = map(int, input().split())
k = 0
if N != 1:
    if is_prime(M):
        print(1)
        exit()
while True:
    if M % (N + k) == 0:
        ans = M // (N+k)
        break
    k += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC102-C
import numpy as np
import statistics
N = int(input())
A = list(map(int, input().split()))
B = np.array(range(1, N+1))
A = np.array(A)
C = abs(A - B)
b = int(round(statistics.mode(C)))
print(sum(abs(C - b)))

Fixed submission:
# ABC102-C
import numpy as np
import statistics
import collections
N = int(input())
A = list(map(int, input().split()))
B = np.array(range(1, N+1))
A = np.array(A)
C = A - B
b = np.median(C)
print(int(np.sum(abs(C - b))))
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
lst = [a, b, c].sort()
a = lst[0]
b = lst[1]
v = lst[2]
if d > abs(a-b) and d > abs(c - b):
    print("No")
else:
    print("Yes")

Fixed submission:
a, b, c, d = map(int, input().split())
if d >= abs(c-a):
    ans = "Yes"
else:
    if d >= abs(b-a) and d >= abs(c-b):
        ans = "Yes"
    else:
        ans = "No"
print(ans)
Buggy python submission (verdict: Runtime Error):
ans_list = []
for i in range(2, 10):
    ans_list.append(2 ** i)
for i in range(2, 7):
    ans_list.append(3 ** i)
for i in range(2, 5):
    ans_list.append(5 ** i)
for i in range(2, 4):
    ans_list.append(7 ** i)
num = [11, 13, 17, 19, 23, 29, 31]
for i in num:
    ans_list.append(i ** 2)
X = int(input())
for i in range(X, 0, -1):
    if i in ans_list:
        ans = i
        break
print(ans)

Fixed submission:
# ABC097-B
ans_list = [1]
for i in range(2, 10):
    ans_list.append(2 ** i)
for i in range(2, 7):
    ans_list.append(3 ** i)
for i in range(2, 5):
    ans_list.append(5 ** i)    
for i in range(2, 4):
    ans_list.append(6 ** i)
    ans_list.append(7 ** i)
    ans_list.append(10 ** i)
num = [11,12, 13, 14, 15, 17, 18, 19, 20, 21, 22,  23,24, 25, 26, 27, 28,  29, 30,  31]
for i in num:
    ans_list.append(i ** 2)
X = int(input())
for i in range(X, 0, -1):
    if i in ans_list:
        ans = i
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
# AGC023
import collections
from scipy.special import comb
N = int(input())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]
c = collections.Counter(S)
c = c.most_common()
for i in range(len(c)):
    if c[i][1] == 1:
        pass
    if c[i][1] == 2:
        ans += 1
    else:
        ans += comb(c[i][1], 2)
print(int(ans))

Fixed submission:
# AGC023
import collections
N = int(input())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]
c = collections.Counter(S)
c = c.most_common()
for i in range(len(c)):
    tmp = c[i][1]
    if tmp == 1:
        pass
    else:
        ans += tmp*(tmp-1) // 2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# AGC023
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
ans = 0
for i in range(N):
    tmp = A[i:N]
    rest = np.cumsum(tmp)
    ans += np.count_nonzero(rest == 0)
print(ans)

Fixed submission:
# AGC023
import collections
N = int(input())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]
c = collections.Counter(S)
c = c.most_common()
for i in range(len(c)):
    tmp = c[i][1]
    if tmp == 1:
        pass
    else:
        ans += tmp*(tmp-1) // 2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
s_set = list(set(s))
t_set = list(set(t))
check_list = []
for i in s_set:
    check_list.append(s.count(i) - t.count(i))
print(max(max(check_list), 0)

Fixed submission:
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
s_set = list(set(s))
t_set = list(set(t))
check_list = []
for i in s_set:
    check_list.append(s.count(i) - t.count(i))
print(max(max(check_list), 0))
Buggy python submission (verdict: Runtime Error):
N, M = map(int , input().split())
if N == 1 and M == 1:
    print(1)
elif N == 1 and M == 2:
    print(0)
elif N == 2 and M == 1:
    print(0)
elif N == 1 or M == 1:
    print(NM - 2)
else:
    print((N-2) * (M-2))

Fixed submission:
N, M = map(int , input().split())
if N == 1 and M == 1:
    print(1)
elif N == 1 and M == 2:
    print(0)
elif N == 2 and M == 1:
    print(0)
elif N == 1 or M == 1:
    print(N*M - 2)
else:
    print((N-2) * (M-2))