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

Fixed submission:
import bisect
A, B, Q = map(int, input().split())

INF = 10 ** 11 + 1
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

"""
def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	if hi < lo:
		return lo
	mi = (lo + hi) // 2
	if v < a[mi]:
		return bsr(a, v, lo, mi - 1)
	else:
		return bsr(a, v, mi + 1, hi)
"""

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	#print(sr, sl, tr, tl, cost)
	print(min(cost))
	#break

Buggy submission (verdict: Runtime Error):
#import math
A, B, Q = map(int, input().split())

#inf = math.inf
inf = 2 **31 - 1

S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def bsearch_sub(a, v, imin, imax):
	if imax < imin:
		return imax + 1
	else:
		imid = imin + (imax - imin) // 2
		if v < a[imid]:
			return bsearch_sub(a, v, imin, imid - 1)
		elif a[imid] <= v:
			return bsearch_sub(a, v, imid + 1, imax)

def bsearch(a, v):
	return bsearch_sub(a, v, 0, len(a) - 1)

#print(S)
#print(T)
#print()

for x in X:
	s, t = bsearch(S, x), bsearch(T, x)
	#print(s, t, x)
	s1, s2, t1, t2 = S[s - 1], S[s], T[t - 1], T[t]
	r = []
	for sv in [s1, s2]:
		for tv in [t1, t2]:
			r += [abs(x - sv) + abs(sv - tv)]
			r += [abs(x - tv) + abs(sv - tv)]
	print(min(r))

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

inf = math.inf

S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def bsearch_sub(a, v, imin, imax):
	if imax < imin:
		return imax + 1
	else:
		imid = imin + (imax - imin) // 2
		if v < a[imid]:
			return bsearch_sub(a, v, imin, imid - 1)
		elif a[imid] <= v:
			return bsearch_sub(a, v, imid + 1, imax)

def bsearch(a, v):
	return bsearch_sub(a, v, 0, len(a) - 1)

#print(S)
#print(T)
#print()

for x in X:
	s, t = bsearch(S, x), bsearch(T, x)
	#print(s, t, x)
	s1, s2, t1, t2 = S[s - 1], S[s], T[t - 1], T[t]
	r = []
	for sv in [s1, s2]:
		for tv in [t1, t2]:
			r += [abs(x - sv) + abs(sv - tv)]
			r += [abs(x - tv) + abs(sv - tv)]
	print(min(r))
Problem p03147 (python)

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

h = [0] + H
c = 0
for i in range(1, 100 + 1):
	for j in range(1, N + 1):
		if h[j - 1] < i and i <= h[j]:
			c += 1
print(c)

Buggy submission (verdict: Runtime Error):
import sys

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N = parse(int)
    H = (0, *map(int, next(args).split()))

    c = 0
    debug(H)
    for h in range(100):
        for n in range(1, N + 1):
            if H[n - 1] - h <= 0 and 0 < H[n] - h:
                c += 1
    print(c)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()
Problem p03161 (python)

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

INF = 10 ** 18

h = H
dp = [0] * N

for n in range(1, N):
	l, r = max(0, n - K), n
	dp[n] = min([dpl + abs(hl - h[r]) for dpl, hl in zip(dp[l:r], h[l:r])])
	#print(dp)
print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
    for j in range(max(i - k, 0), i):
      	np = dp[j] + abs(h[i] - h[j])
        dp[i] = dp[i] if dp[i] < np else np 

print(dp[n - 1])
Problem p03164 (python)

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

#import math
INF = 10 ** 12 # math.inf
V = 10 ** 5 + 10

dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0

for i, (w, v) in enumerate(WV):
	for n in range(V):
		if v <= n:
			dp[i + 1][n] = min(dp[i + 1][n], dp[i][n - v] + w)
		dp[i + 1][n] = min(dp[i + 1][n], dp[i][n])
"""
for line in dp:
	for cell in line:
		if cell == INF:
			print("  INF", end="")
		else:
			print("{:5d}".format(cell), end="")
	print()
"""
r = 0
for i in range(V):
	if dp[-1][i] <= W:
		r = i
print(r)

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

import math
INF = math.inf
V = 10 ** 5 + 10

dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0

for i, (w, v) in enumerate(WV):
	for n in range(V):
		if v <= n:
			dp[i + 1][n] = min(dp[i + 1][n], dp[i][n - v] + w)
		dp[i + 1][n] = min(dp[i + 1][n], dp[i][n])
"""
for line in dp:
	for cell in line:
		if cell == INF:
			print("  INF", end="")
		else:
			print("{:5d}".format(cell), end="")
	print()
"""
r = 0
for i in range(V):
	if dp[-1][i] <= W:
		r = i
print(r)
Problem p03165 (python)

Fixed submission:
def main():
	S, T = input(), input()

	Z = 3010
	dp = [[0] * Z for _ in range(Z)]
	for i in range(len(S)):
		for j in range(len(T)):
			if S[i] == T[j]:
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

	#for line in dp:
	#	print(line)
	#print(dp[len(S)][len(T)])
	i, j, result = len(S), len(T), ""
	while 0 < i and 0 < j:
		if dp[i][j] == dp[i - 1][j]:
			i -= 1
		elif dp[i][j] == dp[i][j - 1]:
			j -= 1
		else:
			result = S[i - 1] + result
			i -= 1
			j -= 1
	print(result)

main()

Buggy submission (verdict: Runtime Error):
def main():
	S, T = input(), input()

	Z = 20 # 3010
	dp = [[0] * Z for _ in range(Z)]
	for i in range(len(S)):
		for j in range(len(T)):
			if S[i] == T[j]:
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

	#for line in dp:
	#	print(line)
	#print(dp[len(S)][len(T)])
	i, j, result = len(S), len(T), ""
	while 0 < i and 0 < j:
		if dp[i][j] == dp[i - 1][j]:
			i -= 1
		elif dp[i][j] == dp[i][j - 1]:
			j -= 1
		else:
			result = S[i - 1] + result
			i -= 1
			j -= 1
	print(result)

main()
Problem p03282 (python)

Fixed submission:
import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
	print("1")
	exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])

Buggy submission (verdict: Runtime Error):
import re

S = input()
K = int(input()[:4])

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K - 1)])

Buggy submission (verdict: Runtime Error):
import re

S = input()
K = int(input())

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K)])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

c = 0
for s in S:
	if "1" == s:
		c += 1
	else:
		break

print(["1", S[c]][not((K - 1) < c)])
Problem p03284 (python)

Fixed submission:
N, K = map(int, input().split())
print([0, 1][0<N % K])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
print([0, 1][N % K])
Problem p03450 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
LRD = [list(map(int, input().split())) for _ in range(M)]

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

visited = [False] * N
depths = [-1] * N
def dfs(v, p, d):
	if visited[v]:
		return True
	visited[v] = True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0):
		print("No")
		break
else:
	print("Yes")

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

def dfs(v, p, d, depths):
	if depths[v] != -1:
		return True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth, depths)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0, [-1] * N):
		print("No")
		break
else:
	print("Yes")
Problem p03565 (python)

Fixed submission:
S = list(input())[::-1]
T = list(input())[::-1]

for n in range(0, len(S) - len(T) + 1):
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
	else:
		S[n:n + len(T)] = T
		print("".join(S[::-1]).replace("?", "a"))
		break
else:
	print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
S = list(input())[::-1]
T = list(input())[::-1]

i, c = 0, False

while True:
	f = False
	for j, t in enumerate(T):
		if t == S[i + j]:
			f = True
			continue
		if "?" == S[i + j]:
			continue
		break
	else:
		if f:
			S[i:i + len(T)] = T
			i += len(T) - 1
			c = True
			#print(S)
	i += 1
	if (len(S) - len(T)) <= i:
		break

if c:
	print("".join(S[::-1]).replace("?", "a"))
else:
	print("UNRESTORABLE")
Problem p03816 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1_000_000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
Problem p03857 (python)

Fixed submission:
from collections import defaultdict as dd

N, K, L = list(map(int, input().split()))
PQ = [list(map(int, input().split())) for _ in range(K)]
RS = [list(map(int, input().split())) for _ in range(L)]

def uft_root(g, a):
	if g[a] < 0:
		return a
	g[a] = uft_root(g, g[a])
	return g[a]

def uft_size(g, a):
	return -g[uft_root(g, a)]

def uft_merge(g, a, b):
	a, b = uft_root(g, a), uft_root(g, b)
	if a == b:
		return
	size_a, size_b = uft_size(g, a), uft_size(g, b)
	if size_a < size_b:
		a, b = b, a
		size_a, size_b = size_b, size_a
	g[a] -= size_b
	g[b] = a

uft_pq = [-1] * N
uft_rs = [-1] * N

for p, q in PQ:
	p, q = p - 1, q - 1
	uft_merge(uft_pq, p, q)
for r, s in RS:
	r, s = r - 1, s - 1
	uft_merge(uft_rs, r, s)

group = dd(int)
for n in range(N):
	group[(uft_root(uft_pq, n), uft_root(uft_rs, n))] += 1

result = []
for n in range(N):
	result += [group[(uft_root(uft_pq, n), uft_root(uft_rs, n))]]
print(" ".join(map(str, result)))

Buggy submission (verdict: Runtime Error):
N, K, L = list(map(int, input().split()))
PQ = [list(map(int, input().split())) for _ in range(K)]
RS = [list(map(int, input().split())) for _ in range(L)]

def uft_root(g, a):
	if g[a] < 0:
		return a
	g[a] = uft_root(g, g[a])
	return g[a]

def uft_size(g, a):
	return -g[uft_root(g, a)]

def uft_merge(g, a, b):
	a, b = uft_root(g, a), uft_root(g, b)
	if a == b:
		return
	size_a, size_b = uft_size(g, a), uft_size(g, b)
	if size_a < size_b:
		a, b = b, a
		size_a, size_b = size_b, size_a
	g[a] -= size_b
	g[b] = a

g_pq = [[] for _ in range(N)]
for p, q in PQ:
	p, q = p - 1, q - 1
	g_pq[p] += [q]
	g_pq[q] += [p]

g_rs = [[] for _ in range(N)]
for r, s in RS:
	r, s = r - 1, s - 1
	g_rs[r] += [s]
	g_rs[s] += [r]

def dfs(v, g, uft, visited):
	if visited[v]:
		return
	visited[v] = True
	for n in g[v]:
		if visited[n]:
			continue
		uft_merge(uft, v, n)
		dfs(n, g, uft, visited)

visited_pq = [False] * N
visited_rs = [False] * N
uft_pq = [-1] * N
uft_rs = [-1] * N

for n in range(N):
	dfs(n, g_pq, uft_pq, visited_pq)
	dfs(n, g_rs, uft_rs, visited_rs)

group_pq, group_rs = {}, {}
for n in range(N):
	root_pq = uft_root(uft_pq, n)
	if not root_pq in group_pq:
		group_pq[root_pq] = {n}
	else:
		group_pq[root_pq] |= {n}
	root_rs = uft_root(uft_rs, n)
	if not root_rs in group_rs:
		group_rs[root_rs] = {n}
	else:
		group_rs[root_rs] |= {n}

for n in range(N):
	print(len(group_pq[uft_root(uft_pq, n)] & group_rs[uft_root(uft_rs, n)]), "", end="")
print()
Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

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

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))

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

dp = [-1] * N  # dp[i] := i+1 から N までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))
Problem p02716 (python)

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

dp_g = A[1]
dp_k = A[0]
dp = [0, max(dp_g, dp_k)]

for i in range(2, N):
    if i % 2 == 1:
        dp_g = max(dp_k, dp_g) + A[i]
        dp_k += A[i - 1]
        dp.append(max(dp_g, dp_k))
    elif i % 2 == 0:
        dp.append(max(dp[i - 1], dp[i - 2] + A[i]))

print(dp[N - 1])

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

dp_g = A[1]
dp_k = A[0]
dp = [0, max(dp_g, dp_k), max(dp_g, dp_k, A[2])]

for i in range(3, N):
    if i % 2 == 1:
        dp_g = max(dp_k, dp_g) + A[i]
        dp_k += A[i - 1]
        dp.append(max(dp_g, dp_k))
    elif i % 2 == 0:
        dp.append(max(dp[i - 1], dp[i - 2] + A[i]))

print(dp[N - 1])
Problem p02899 (python)

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

result = []

for i in range(N):
    result.append([A[i], i + 1])

result.sort()
li = []

for i in range(N):
    li.append(result[i][1])

print(*li)

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

result = []

for i in range(N):
    result.append([A[i], i + 1])

result.sort()
print(result *)
Problem p02937 (python)

Fixed submission:
s = input()
t = input()

p = 0
roop = 0
dic = [['' for i in range(len(s))] for j in range(26)]

for i in range(len(t)):
    dis = 0
    if dic[ord(t[i])-97][p] == '':
        for j in range(p,len(s)):
            if t[i] == s[j]:
                for k in range(p,j+1):
                    dic[ord(t[i])-97][k] = j
                dis = 1
                break
        if dis == 0:
            for j in range(0,p):
                if t[i] == s[j]:
                    for k in range(p,len(s)):
                        dic[ord(t[i])-97][k] = j
                    for k in range(0,j+1):
                        dic[ord(t[i])-97][k] = j
                    dis = 1
                    break
        if dis == 0:
            dis = 2
            break
    if p > dic[ord(t[i])-97][p]:
        roop += 1
    if dic[ord(t[i])-97][p] == len(s)-1:
        roop += 1        
        p = 0
    else:
        p = dic[ord(t[i])-97][p] + 1

if dis == 2:
    print(-1)
else:
    print(roop*len(s)+p)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

p = 0
roop = 0
dic = [['' for i in range(len(s))] for j in range(26)]

for i in range(len(t)):
    dis = 0
    if dic[ord(t[i])-97][p] == '':
        for j in range(p,len(s)):
            if t[i] == s[j]:
                for k in range(p,j+1):
                    dic[ord(t[i])-97][k] = j
                dis = 1
                break
        if dis == 0:
            for j in range(0,p):
                if t[i] == s[j]:
                    for k in range(p,len(s)):
                        dic[ord(t[i])-97][k] = j
                    for k in range(0,j+1):
                        dic[ord(t[i])-97][k] = j
                    dis = 1
                    break
        if dis == 0:
            dis = 2
            break
    if p > dic[ord(t[i])-97][p]:
        roop += 1
    p = dic[ord(t[i])-97][p] + 1

if dis == 2:
    print(-1)
else:
    print(roop*len(s)+p)

Buggy submission (verdict: Runtime Error):
#N, M = map(int, input().split())
#List_ab = [list(map(int, input().split())) for i in range(N)]
s = input()
t = input()
  
p = 0
roop = 0
dic = [['' for i in range(len(s))] for j in range(26)]

for i in range(len(t)):
    dis = 0
    if dic[ord(t[i])-97][p] == '':
        for j in range(p,len(s)):
            if t[i] == s[j]:
                for k in range(p,j+1):
                    dic[ord(t[i])-97][k] = j
                dis = 1
                break
        if dis == 0:
            for j in range(0,p):
                if t[i] == s[j]:
                    for k in range(p,len(s)):
                        dic[ord(t[i])-97][k] = j
                    for k in range(0,j+1):
                        dic[ord(t[i])-97][k] = j
                    dis = 1
                    break
        if dis == 0:
            dis = 2
            break
    if p > dic[ord(t[i])-97][p]:
        roop += 1
    p = dic[ord(t[i])-97][p] + 1
    
print(roop*len(s)+p)
Problem p02995 (python)

Fixed submission:
import fractions

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

A, B, C, D = map(int, input().split())
total = B - A + 1
CD = lcm(C, D)

C_count = B//C - (A-1)//C
D_count = B//D - (A-1)//D
CD_count = B//CD - (A-1)//CD

result = total - C_count - D_count + CD_count

print(result)

Buggy submission (verdict: Runtime Error):
import math

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

A, B, C, D = map(int, input().split())
total = B - A + 1
CD = lcm(C, D)

C_count = math.floor(B / C) - math.floor(A / C)
if (A % C) == 0:
    C_count += 1
D_count = math.floor(B / D) - math.floor(A / D)
if (A % D) == 0:
    D_count += 1
CD_count = math.floor(B / CD) - math.floor(A / CD)
if (A % CD) == 0:
    CD_count += 1

result = total - C_count - D_count + CD_count

print(result)
Problem p03000 (python)

Fixed submission:
N, X = map(int,input().split()) # 複数の数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

count = 1
point = 0

while point <= X and count <= N:
    point += List[count-1]
    if point <= X:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N, X = map(int,input().split()) # 複数の数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

count = 0
point = 0

while point <= X:
    point += List[count]
    count += 1

print(count)
Problem p03024 (python)

Fixed submission:
s = input()
count = 0

for i in range(len(s)):
    if s[i] == 'x':
        count += 1
if count >= 8:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
s = input()
count = 0

for i in range(len(s)):
    if s[i] = 'x':
        count += 1
if count >= 8:
    print("YES")
else:
    print("NO")
Problem p03029 (python)

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

p = A*3 + P
result = int(p / 2)
print("{}".format(result))

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

List_S.sort(key=lambda x:x[2])

for i in range(Q):
    flag = 0
    for j in range(N):
        if (List_S[j][0]-0.5 < (List_D[i] + List_S[j][2])) and ((List_D[i] + List_S[j][2]) < List_S[j][1]-0.5):
            print("{}".format(List_S[j][2]))
            flag = 1
            break
    if flag == 0:
        print("-1")
Problem p03030 (python)

Fixed submission:
N = int(input())
List = [list(map(str,input().split())) for i in range(N)]

for i in range(N):
    List[i].append(i+1)
    List[i][1] = int(List[i][1])
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))

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

for i in range(N):
    List[i].append(i+1)
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))
Problem p03037 (python)

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

mi = 1
ma = N

for i in range(M):
    if mi < List[i][0]:
        mi = List[i][0]
    if ma > List[i][1]:
        ma = List[i][1]

diff = ma - mi + 1
if diff < 0:
    diff = 0
print("{}".format(diff))

Buggy submission (verdict: Runtime Error):
mi = 1
ma = N

for i in range(M):
    if mi < List[i][0]:
        mi = List[i][0]
    if ma > List[i][1]:
        ma = List[i][1]

diff = ma - mi + 1
if diff < 0:
    diff = 0
print("{}".format(diff))
Problem p02945 (python)

Fixed submission:
x = str(input())
j = x.split()
a = int(j[0])
b = int(j[1])
print(max((a+b),(a-b),(a*b)))

Buggy submission (verdict: Runtime Error):
x = int(input())
j = x.split()
a = j[0]
b = j[1]
print(max((a+b),(a-b),(a*b)))
Problem p03079 (python)

Fixed submission:
A=list(map(int,input().split()))
if A[0]==A[1] and A[1]==A[2] and A[0]>0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A,B,C=int(input().split())
if A==B and B==C:
  print("YES")
else:
  print("NO")