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

Fixed submission:
def same_count(str_list):
    standard_str = min(str_list, key=lambda x: len(x))
    return [all([c in str_ for str_ in str_list]) for c in set(standard_str)].count(True)

n = int(input())
s = input()

print(max([same_count([s[:i+1], s[i+1:]]) for i in range(n)]+[0]))

Buggy submission (verdict: Runtime Error):
def same_count(str_list):
    standard_str = min(str_list, key=lambda x: len(x))
    return [all([c in str_ for str_ in str_list]) for c in set(standard_str)].count(True)

n = int(input())
s = input()

print(max([same_count([s[:i], s[i:]]) for i in range(1,n-1)]))

Buggy submission (verdict: Runtime Error):
def same_count(str_list):
    standard_str = min(str_list, key=lambda x: len(x))
    return [all([c in str_ for str_ in str_list]) for c in standard_str].count(True)

n = int(input())
s = input()

print(max([same_count([s[:i], s[i:]]) for i in range(1,n-1)]))
Problem p03339 (python)

Fixed submission:
n = int(input())
s = input()

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        e_east -= 1
    else:
        w_west += 1
    tmp = w_west + e_east - bool(s_i == "W")
    if tmp < min_num:
        min_num = tmp
print(min_num)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

min_num = 
for i in range(n):
    min_num = min(s[:i].count("W") + s[i+1:].count("E"), min_num)
print(min_num)
Problem p03379 (python)

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

x_sorted = sorted(x)
for x_i in x:
	print((x_sorted[n//2-1], x_sorted[n//2])[x_i < x_sorted[n//2]])

Buggy submission (verdict: Runtime Error):
n = int(input())
x = tuple(map(int, input().split(" ")))

for x_i in range(len(x)):
	x_dummy = :
	print(sorted(x_dummy.remove(x_i))[len(x)//2])
Problem p03385 (python)

Fixed submission:
print("YNeos"[len(set(input()))!=3::2])

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

print("Yes" if len(set(input()))==3 else "No")
Problem p03387 (python)

Fixed submission:
abc = list(map(int, input().split(" ")))

count = 0
while True:
	abc.sort()

	if abc[0] == abc[1] == abc[2]:
		break
	elif abc[0] == abc[1]:
		abc[0] += 1
		abc[1] += 1	
		count += 1
	else:
		abc[0] += 2
		count += 1

print(count)

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

only_num = get_only(abc, key=lambda x: x%2)
if only_num:
	abc.remove(only_num)
	abc = [only_num] + [abc_i+1 for abc_i in abc]
max_num = max(abc)
abc.remove(max_num)

print((max_num-abc[0] + max_num-abc[1])//2+bool(only_num))
Problem p03399 (python)

Fixed submission:
a,b,c,d=[int(input())for i in range(4)];print([a,b][a>b]+[c,d][c>d])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split());print("YNeos"[a+b<c::2])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split());print("YNeos"[a+b<c::2])
Problem p03409 (python)

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

CD.sort()
AB.sort(key=lambda x: (x[1], x[0]), reverse=True)

count = 0
for c, d in CD:
    for j, (a, b) in enumerate(AB):
        if a < c and b < d:
            count += 1
            AB.pop(j)
            break

print(count)

Buggy submission (verdict: Runtime Error):
pair_count = 0
for cd_i in cd:
	can_ball_count = 0
	for ab_i in ab:
		if ab_i[0] < cd_i[0] and ab_i[1] < cd_i[1]:
			can_ball_count += 1
		else:
			break
	if 1 <= can_ball_count-pair_count:
		pair_count += 1

print(pair_count)
Problem p03434 (python)

Fixed submission:
n = int(input())
a = [int(n) for n in input().split(" ")]

a.sort()

print(sum(a[::-2]) - sum(a[-2::-2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(n) for n in input().split(" ")]

a.sort()

print(a[::-2] - a[-2::-2])
Problem p03436 (python)

Fixed submission:
from collections import deque
from itertools import chain
ads = [(0, 1), (1, 0), (0, -1), (-1, 0)]

h, w = map(int, input().split(" "))
s = [list(input()) for _ in range(h)]

def find_shortest(m):
	q = deque([(0, 0)])
	i = 0
	while q:
		for j in range(len(q)):
			this_x, this_y = q.popleft()
			# this_square = m[this_y][this_x]
			if (this_x, this_y) == (w-1, h-1):
				return i
			m[this_y][this_x] = i

			for ad_x, ad_y in ads:
				x, y = this_x+ad_x, this_y+ad_y
				if not (0 <= x < w and 0 <= y < h):
					continue
				
				square = m[y][x]
				if square == "#" or type(square) == int:
					continue
					
				q.append((x, y))
				m[y][x] = "#"
		i += 1
	return None


white_num = "".join(chain(*s)).count(".")
shortest_lenght = find_shortest(s)
if shortest_lenght:
	print(white_num - 1 - shortest_lenght)
else:
	print(-1)
# しろます - 1 - 最短ルートの長さ

Buggy submission (verdict: Runtime Error):
from collections import deque
from itertools import chain

ADS = [(0, 1), (1, 0), (-1, 0), (0, -1)]

h, w = map(int, input().split(" "))
s = [list(input()) for _ in range(h)]

l = [[None for _ in range(w)] for _ in range(h)]
l[0][0] = 0

q = deque([(0, 0)])
while q:
	this_x, this_y = q.popleft()
	this_num = l[this_y][this_x]
	if (this_x, this_y) == (w-1, h-1):
		break

	for ad_x, ad_y in ADS:
		x, y = this_x+ad_x, this_y+ad_y
		if not (0 <= x < w and 0 <= y < h):
			continue
		
		square = s[y][x]
		if square == "#":
			continue

		num = l[y][x]
		if num != None:
			continue
		l[y][x] = this_num + 1

		q.append((x, y))

print(sum(s_i.count(".") for s_i in s) - l[h-1][w-1] - 1)

Buggy submission (verdict: Runtime Error):
from collections import deque
from itertools import chain

ADS = [(0, 1), (1, 0), (-1, 0), (0, -1)]

h, w = map(int, input().split(" "))
s = [list(input()) for _ in range(h)]

l = [[None for _ in range(w)] for _ in range(h)]
l[0][0] = 0

q = deque([(0, 0)])
while q:
	this_x, this_y = q.popleft()
	this_num = l[this_y][this_x]
	if (this_x, this_y) == (w, h):
		break

	for ad_x, ad_y in ADS:
		x, y = this_x+ad_x, this_y+ad_y
		if not (0 <= x < w and 0 <= y < h):
			continue
		
		square = s[y][x]
		if square == "#":
			continue

		num = l[y][x]
		if num != None:
			continue
		l[y][x] = this_num + 1

		q.append((x, y))

print(sum(s_i.count(".") for s_i in s) - l[h-1][w-1] - 1)
Problem p03449 (python)

Fixed submission:
n = int(input())
a = [tuple(map(int, input().split(" "))) for i in range(2)]

up_line, down_line = a

max_num = 0
for i in range(n):
	num = sum(up_line[:i+1]) + sum(down_line[i:])
	if max_num < num:
		max_num = num
print(max_num)

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

can_count = 0

for i in range(a+1):
	coins_price_500 = i * 500
	for j in range(b+1):
		coins_price_100 = j * 100
		for k in range(c+1):
			coins_price_50 = k * 50
			if x == coins_price_500 * coins_price_100 * coins_price_50:
				can_count += 1

print(can_count)
Problem p03455 (python)

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

if a % 2 == b % 2 == 1:
	print("Odd")
else:
	print("Even")

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

if a % 2 == b % 2 == 1:
	print("Odd")
else:
	print("Even")
Problem p03457 (python)

Fixed submission:
# Relative rela
import sys

n = int(input())
txy_list = [[int(n) for n in input().split()] for i in range(n)]
times_list = [txy_list[0][0]] + [txy_list[i+1][0] - txy_list[i][0] for i in range(n-1)]

before_x, before_y = 0, 0
for i, txy in enumerate(txy_list):
	t, x, y = txy
	rela_x, rela_y = x - before_x, y - before_y
	remaining = times_list[i] - (abs(rela_x) + abs(rela_y))
	if 0 <= remaining and remaining % 2 == 0:
		before_x, before_y = x, y
	else:
		print("No")
		sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
# Relative rela
import sys

n = int(input())
txy_list = [[int(n) for n in input().split()] for i in range(n)]
times_list = [txy_list[i][0] - txy_list[i+1][0] for i in range(n-1)]

before_x, before_y = 0, 0
for i, txy in enumerate(txy_list):
	t, x, y = txy
	rela_x, rela_y = x - before_x, y - before_y
	remaining = times_list[i] - (abs(rela_x) + abs(rela_y))
	if 0 <= remaining and remaining % 2 == 0:
		before_x, before_y = x, y
	else:
		print("No")
		sys.exit()
print("Yes")
Problem p03478 (python)

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

some_sum = 0
for i in range(1, n+1):
	digit_sum = sum([int(m) for m in str(i)])
	if a <= digit_sum and digit_sum <= b:
		some_sum += i

print(some_sum)

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

some_sum = 0
for i in range(1, n):
	if a <= sum([int(m) for m in str(i)]) <= b:
		some_sum += i

print(some_sum)
Problem p03479 (python)

Fixed submission:
x, y = map(int, input().split(" "))

n = x
count = 0
while n <= y:
	n *= 2
	count += 1
print(count)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split(" "))

print(int(math.log(y/x, 2)) + 1)
Problem p03485 (python)

Fixed submission:

ab=map(int,input().split());print((sum(ab)-1)//2+1)

Buggy submission (verdict: Runtime Error):
ab=map(int,input()[::1]);print(~-sum(ab)//2+1)
Problem p03501 (python)

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

print(min(a*n, b))

Buggy submission (verdict: Runtime Error):
s=input();print("No"if int(s)%sum(map(int,s))else"Yes")
Problem p03502 (python)

Fixed submission:
n=int(input());print("Yes"if n%sum([int(m)for m in str(n)])==0 else"No")

Buggy submission (verdict: Runtime Error):
n=int(input());print("No"if n%sum(map(int,str(s))) else"Yes")
Problem p03607 (python)

Fixed submission:
import sys

n = int(input())
# a = map(int, sys.stdin.read().split("\n"))
a = map(int, [input() for i in range(n)])

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] = (d[a_i]+1) % 2

print(sum(d.values()))

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
a = map(int, sys.stdin.read().split("\n"))
# a = map(int, [input() for i in range(n)])

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] = (d[a_i]+1) % 2

print(sum(d.values()))

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
a = map(int, sys.stdin.read().split("\n"))

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] = (d[a_i]+1) % 2

print(sum(d.values))
Problem p03625 (python)

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

a.sort()
maxs = []
for i in range(2):
	max_1 = a.pop()
	while True:
		max_2 = a.pop()
		if max_1 == max_2:
			maxs.append(max_1)	
			break
		max_1 = max_2
		if len(a) == 0:
			print(0)
			exit()
print(maxs[0]*maxs[1])

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

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] += 1
d = sum([[d_i[0] for i in range(d_i[1]//2)] for d_i in d.items()], [])

d.sort(reverse=True)
print(d[0] * d[1])

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

for a_i in set(a):
	a.remove(a_i)
max_2 = sorted(a, reverse=True)[:2]
print(max_2[0]*max_2[1])
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

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

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)

Buggy submission (verdict: Runtime Error):
import fraction

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

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

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

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

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

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

t += [1, 1]
a = t.pop()
while t:
	b = t.pop()
	a = lcm(a, b)
print(a)

Buggy submission (verdict: Runtime Error):
import math

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

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

t += [1, 1]
a = t.pop()
while t:
	b = t.pop()
	a = lcm(a, b)
print(a)

Buggy submission (verdict: Runtime Error):
import math

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

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

t += [1]
a = t.pop()
while t:
	b = t.pop()
	a = lcm(a, b)
print(a)
Problem p03645 (python)

Fixed submission:
n, m = map(int, input().split(" "))
ab = [tuple(map(int, input().split(" "))) for i in range(m)]

from_one, to_n = set(), set()
for ab_i in ab:
	if ab_i[0] == 1:
		from_one.add(ab_i[1])
	elif ab_i[1] == n:
		to_n.add(ab_i[0])
	
print("POSSIBLE" if from_one & to_n else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())
ab = [tuple(map(int, input().split(" "))) for i in range(m)]

from_one, to_n = set(), set()
for ab_i in ab:
	if ab_i[0] == 1:
		from_one.add(ab_i[1])
	elif ab_i[0] == n:
		from_one.add(ab_i[1])
	
print("POSSIBLE" if from_one | to_n else "IMPOSSIBLE")
Problem p03673 (python)

Fixed submission:
n = int(input())
a = input().split(" ")

print(" ".join((a[1::2][::-1] + a[::2])[::1 if len(a)%2==0 else -1]))

Buggy submission (verdict: Runtime Error):
print(" ".join((a[1::2][::-1] + a[::2])[::1 if len(a)%2==0 else -1]))
Problem p03679 (python)

Fixed submission:
x, a, b = map(int, input().split(" "))

if 0 <= a - b:
    print("delicious")
elif b - a <= x:
    print("safe")
else:
    print("dangerous")

Buggy submission (verdict: Runtime Error):
nums = [1, 1]
def step_div(n):
	i = len(nums)
	while i <= n:
		nums.append(nums[i-1] * i)
		i += 1
	return nums[n]

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print((step_div(n) * step_div(m) * 2) % (10**9+7))
else:
	print(0)
Problem p03681 (python)

Fixed submission:
import math

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print((math.factorial(n) * math.factorial(m) * (2 if remain==0 else 1)) % (10**9+7))
else:
	print(0)

Buggy submission (verdict: Runtime Error):
import math

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print((math.factorial(n) * math.factorial(m) * (2 if remain==0 else 1)) % (10**9+7)))
else:
	print(0)

Buggy submission (verdict: Runtime Error):
import math

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print(math.factorial(n) * math.factorial(m) * (2 if remain==0 else 1)) % (10**9+7))
else:
	print(0)
Problem p03695 (python)

Fixed submission:
n = int(input())
a = map(int, input().split(" "))

color_types = [False]*8
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = 1
	else:
		pro_count += 1
print(max(1, sum(color_types)), sum(color_types)+pro_count)

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

color_types = [False]*8
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = True
	else:
		pro_count += 1
print(max(1,　sum(color_types)), min(8, sum(color_types)+pro_count))

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

color_types = [False]*8
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = True
	else:
		pro_count += 1
print(color_types)
print(sum(max(1,　color_types)), min(8, sum(color_types)+pro_count))

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

color_types = [False]*7
pro_count = 0
for a_i in a:
	if a_i < 3200:
		color_types[a_i//400] = True
	else:
		pro_count += 1
print(sum(color_types), min(8, sum(color_types)+pro_count))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = tuple(map(int, input().split(" ")))

color_types = [False]*7
pro_count = 0
if a < 3200:
	color_types[a//400] = True
else:
	pro_count += 1
print(min(8, sum(color_types)+pro_count))
Problem p03697 (python)

Fixed submission:
z=eval(input().replace(" ","+"));print(z//10*"error"or z)

Buggy submission (verdict: Runtime Error):
x=input();z=eval(x[0]+"+"x[2]);print(z//10*"error"or z)
Problem p03699 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

sum_a = sum(a)

if sum_a % 10 == 0:
	can_nums = filter(lambda x: x%10 != 0, set(a))
	if len(list(can_nums)) == 0:
		print(0)
	else:
		print(sum_a - min(can_nums))
else:
	print(sum_a)

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

sum_a = sum(a)

if sum_a % 10 == 0:
	can_nums = filter(lambda x: x%10 != 0, set(a))
	if len(list(can_nums)) == 0:
		print(0)
	else:
		print(sum_a - min(can_nums))
else:
	print(sum_a)
Problem p03721 (python)

Fixed submission:
n, k = map(int, input().split(" "))
ab = [tuple(map(int, input().split(" "))) for i in range(n)]

count = 0
for ab_num, ab_count in sorted(ab):
	count += ab_count
	if k <= count:
		print(ab_num)
		exit()

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split(" "))
ab = [tuple(map(int, input().split(" "))) for i in range(n)]

d = dict()
for ab_i in ab:
	a, b = ab_i
	if a not in d:
		d[a] = 0
	d[a] += b

print(sum([[d_a] * d_b for d_a, d_b in sorted(d.items())], [])[k-1])
Problem p03813 (python)

Fixed submission:
x = int(input())

print("ABC" if x < 1200 else "ARC")

Buggy submission (verdict: Runtime Error):
print(f"A{RB[input()<"1200"]}C")
Problem p03944 (python)

Fixed submission:
W,H,N=map(int,input().split())
x=y=0
for i in range(N):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    W=min(W,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    H=min(H,yi)
    
print(0 if x>=W or y>=H else (W-x)*(H-y))

Buggy submission (verdict: Runtime Error):
w, h, n = map(int, input().split(" "))
x_y_a = [tuple(map(int, input().split(" "))) for i in range(n)]

min_x, max_x, min_y, max_y = 0, w, 0, h
for x_y_a_i in x_y_a:
    x, y, a = x_y_a_i
    if a == 1:
        min_x = x
    elif a == 2:
        max_x = x
    elif a == 3:
        min_y = y
    elif a == 4:
        max_y = y

print(min(0, max_x-min_x) * min(0, max_y-min_y)))
Problem p03998 (python)

Fixed submission:
s_abc = [input() for c in "abc"]

player = 0
while len(s_abc[player]) != 0:
	next_player = "abc".find(s_abc[player][0])
	s_abc[player] = s_abc[player][1:]
	player = next_player
print("ABC"[player])

Buggy submission (verdict: Runtime Error):
s_abc = [input().split for i in range(3)]

player = 0
while True:
	next_player = "abc".find(s_abc[player][0])
	s_abc[player] = s_abc[player][1:]
	if 0 <= s_abc.index(""):
		print("ABC"[s_abc.index("")])
		break
	player = next_player
Problem p04019 (python)

Fixed submission:
S = input()

S = set(S)
if 1 not in [len(S&set(t)) for t in ["NS", "WE"]]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=set;print("YNeos"[s(input())in map(s,"NS","EW","NSEW")::2])
Problem p04043 (python)

Fixed submission:
abc = list(map(int, input().split(" ")))

print("YES" if sorted(abc) == [5, 5, 7] else "NO")

Buggy submission (verdict: Runtime Error):
abc = list(map(int, input()))

print("Yes" if sorted(abc) == [5, 5, 7] else "No")
Problem p04045 (python)

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

while set(str(n)) & set(d):
	n += 1
print(n)

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

for i in range(len(str(n))+1):
	if str(n)[~i] not in d:
		continue
	while str(n)[~i] in d:
		n += 10**i
print(n)

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

for i in range(len(str(n))+1):
	if str(n)[~i] not in d:
		break
	while str(n)[~i] in d:
		n += 10**i
print(n)

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

for i in range(len(str(n))+1):
	while str(n)[~i] in d:
		n += 10**i
print(n)
Problem p02584 (python)

Fixed submission:
X,K,D = map(int,input().split())
X = abs(X)

if X - (D*K) >= 0:
  print(X-D*K)
else:
  k = K - (X//D)
  if k % 2 == 0:
    print(X%D)
  else:
    print(min(abs(X%D+D), abs(X%D-D)))

Buggy submission (verdict: Runtime Error):
X,K,D = map(int,input().split())

m = X//D
if K >= m:
  if m%2 == K%2:
    print(abs(X%D))
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
else:
  print( min( abs(X-D*K) , abs(X+D*K)
Problem p02585 (python)

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

N,K = map(int,input().split())
P = [ i-1 for i in list(map(int,input().split())) ]
C = list(map(int,input().split()))
ans = -float('inf')

for i in range(N):
  cycle = []
  tot = 0
  nex = i
  while True:
    nex = P[nex]
    cycle.append(C[nex])
    tot += C[nex]
    if nex == i: break

  l = len(cycle)
  t = 0
  for j in range(l):
    t += cycle[j]
    if j+1 > K: break
    now = t
    if tot > 0:
      now += tot*((K-(j+1))//l)
    ans = max(ans, now)

print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
P = [ i-1 for i in list(map(int,input().split())) ]
C = list(map(int,input().split()))

g = [ [] for _ in range(N) ]
for i in range(N):
  g[i].append(P[i])

def dfs(i):
  global cycle
  nei = g[i][0]
  if nei in cycle: return
  cycle.append(nei)
  dfs(nei)

cycles = []

for i in range(N):
  cycle = []
  dfs(i)
  c = [ C[j] for j in cycle ]
  cycles.append(c) 

ans = -float('inf')
for i in range(N):
  c = cycles[i]
  cum = c[::]
  for j in range(1,len(c)):
    cum[j] = cum[j-1] + cum[j]

  if cum[-1] < 0:
    ans = max(ans, max(cum[0:K]))
  else:
    t = K//len(c)
    r = K - t*len(c)
    cum = [0]+cum[::]
    ans = max(ans, cum[-1]*t+max(cum[:r+1]))

print(ans)
Problem p02607 (python)

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

res = 0
for i,a in enumerate(A):
  idx = i+1
  if idx%2==1 and a%2==1:
    res += 1

print(res)

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

res = 0
for i,a in enumerate(A):
  idx = i+1
  if idx%2==1 and a%2==1:
    res += 1

print(res