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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1

print(max(ary))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]
​
for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1
​
print(max(ary))
Problem p03612 (python)

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

cnt = 0
for i in range(n):
    if p[i] == i + 1:
        if i == 0:
            p[i], p[i + 1] = p[i + 1], p[i]
        elif i == n-1:
            p[i], p[i - 1] = p[i - 1], p[i]
        else:
            if p[i - 1] == i + 1:
                p[i], p[i - 1] = p[i - 1], p[i]
            else:
                p[i], p[i + 1] = p[i + 1], p[i]
        cnt += 1

print(cnt)

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

cnt = 0
for i in range(n):
    if p[i] == i + 1:
        if p[i - 1] == i + 1:
            p[i], p[i - 1] = p[i - 1], p[i]
        else:
            p[i], p[i + 1] = p[i + 1], p[i]
        cnt += 1

print(cnt)
Problem p02639 (python)

Fixed submission:
[ print(i+1) for i,x in enumerate(map(int, input().split())) if x == 0]

Buggy submission (verdict: Runtime Error):
_,*p=map(int,open(0).read().split())
i=0
p.sort()
while(len(p)!=0):
  t=p[0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:p=[i for i in p if i!=0]
  else:i+=1
print(i)
Problem p02641 (python)

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Buggy submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = [0]
p.extend( sorted(map(abs,l)))
for i in range(n//2+1):
  if not ( p[2*i+1] == i ):
    if i in l:
      print(x-i)
    else:
      print(x+i)
    break

Buggy submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = [0]
p.extend( sorted(map(abs,l)))
for i in range(n//2+1):
  if not ( p[2*i] == p[2*i+1] == i ):
    if i in l:
      print(x+i)
    else:
      print(x-i)
    break

Buggy submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range(n//2+1):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)

Buggy submission (verdict: Runtime Error):
import functools as ft
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range((n//2)+1):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)

Buggy submission (verdict: Runtime Error):
import functools as ft
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range(n/2):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)
Problem p02642 (python)

Fixed submission:
M=10**6+1
_,*l=map(int,open(0).read().split())
a=[0]*M
for i in sorted(l):
  a[i]+=1
  if a[i]==1:
    for j in range(2*i,M,i): a[j]+=2
print(a.count(1))

Buggy submission (verdict: Runtime Error):
_,*p=map(int,open(0).read().split())
i=0
p.sort()
while(len(p)!=0):
  t=p[0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:
    p=[i for i in p if i!=0]
  else:i+=1
print(len(q))
Problem p02657 (python)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
a,b=map(input().split())
print(a*b)
Problem p02640 (python)

Fixed submission:
import sys

if __name__ == "__main__":
    for line in sys.stdin:
        anis, legs = map(int, line.split(' '))
        if legs % 2 == 1 or legs > anis * 4 or legs < anis * 2:
            print("No")
        else:
            print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

if __name__ == "__main__":
  for line in sys.stdin:
    anis, legs = line.split(' ')
    if legs % 2 == 1 or legs > anis * 4 or legs < anis * 2:
      print("No")
    else:
      print("Yes")
Problem p02658 (python)

Fixed submission:
def solve():
    e = 10 ** 18
    n = int(input())
    arr = [int(i) for i in input().split()]
    ans, flag = [1,1]
    if 0 in arr:
      	return 0
    for i in arr:
        ans = ans * i
        if ans > e:
            return -1
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
e = 10 ** 18
n = int(input())
arr = [int(i) for i in input().split()]
ans, flag = [1,1]
if 0 in arr:
  print('0')
else:
  for i in arr:
  	ans = ans * i
  	if ans > e:
    	print('-1')
    	flag = 0
    	break
if flag == 1:
  print(ans)
Problem p02657 (python)

Fixed submission:
a, b = map(int, input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
int A=input()
int B=input()

print(A*B)
Problem p02658 (python)

Fixed submission:
import sys
N = int(input())
a = list(map(int, input().split()))

if 0 in a:
    print(0)
    sys.exit()

b=1
for i in range(0,N):
    b *= a[i]
    if b > 1000000000000000000:
        print(-1)
        sys.exit()

print(b)

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

if 0 in a:
    print(0)
    sys.exit()

b=1
for i in range(0,N):
    b *= a[i]
    if b > 1000000000000000000:
        print(-1)
        sys.exit

print(b)
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [float("inf")] * (100000+1)

dp[1] = 0
for i in range(1, 100000+1):
    for j in range(1, 3):
        if i + j > n:
            break
        elif dp[i+j] > dp[i] + abs(h[i-1] - h[i+j-1]):
            dp[i+j] = dp[i] + abs(h[i-1] - h[i+j-1])

print(dp[n])

Buggy submission (verdict: Runtime Error):
import sequtils, strutils


if isMainModule:
  var
    n = stdin.readLine.parseInt
    h = stdin.readLine.split.map(parseInt)
    dp: array[1..100000, int]

  for i in 1..n:
    for j in 1..2:
      if i + j > n:
        break
      elif dp[i+j] > min(dp[i] + abs(h[i-1] - h[i+j-1])) or dp[i+j] == 0:
        dp[i+j] = min(dp[i] + abs(h[i-1] - h[i+j-1]))

  echo dp[n]
Problem p03212 (python)

Fixed submission:
N = int(input())

base = ["3", "5", "7"]
nums = ["3", "5", "7"]
temp = []
x = 0

while 1:
    for num in nums[(3**x)-1:]:
        for b in base:
            temp.append(b + num)
    nums.extend(temp)
    
    x += 1
    if int(temp[-1]) > 10**9:
        break
    temp = []

target = []
for n in set(nums):
    if "7" in n and "5" in n and "3" in n:
        target.append(int(n))

count = 0
for n in target:
    if n <= N:
        count += 1

print(count)

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

base = ["3", "5", "7"]
nums = ["3", "5", "7"]
temp = []
x = 0

while 1:
    for num in nums[(3**x)-1:]:
        for b in base:
            temp.append(b + num)
    nums.extend(temp)
    
    x += 1
    if int(temp[-1]) > 10**9:
        break
    temp = []

target = []
for n in set(nums):
    if "7" in n and "5" in n and "3" in n:
        target.append(int(n))

count = 0
target.sort()
for n in target.:
    if int(n) < N:
        count += 1

print(count)
Problem p03241 (python)

Fixed submission:
import sys
import math
Input = sys.stdin.readline
 
N, M = map(int, Input().split())
D = []
 
for i in range(int(math.sqrt(M)), 0, -1):
    if M % i == 0:
      D.append(i)
      D.append(M // i)

D.sort(reverse=True)
for d in D:
    if M >= N*d:
        print(d)
        break

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())

for i in range(int(math.sqrt(M))+1, 1, -1):
    if M % i == 0:
        if M >= N*i:
            print(i)
            sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
Input = sys.stdin.readline

N, M = map(int, Input().split())

for i in range(int(math.sqrt(M))+1, 1, -1):
    if M % i == 0:
        if M >= N*i:
            print(i)
            sys.exit()
Problem p03251 (python)

Fixed submission:
N, M, X, Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
accept = False

x_max = max(x)
y_min = min(y)
if X < Y:
    z = [i for i in range(X+1, Y+1)]
    
    for i in z:
        if x_max < i and i <= y_min:
            accept = True
            break
if accept:
    print("No War")
else:
    print("War")

Buggy submission (verdict: Runtime Error):
5 3 6 8
-10 3 1 5 -100
100 6 14
Problem p03262 (python)

Fixed submission:
#import math
from functools import reduce

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

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

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(gcd, x)
    print(D)

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

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    print(x)
    x = [n - x[0] for n in x]
    print(x)
    D = reduce(math.gcd, x)
    print(D)

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

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

if N == 1:
    print(x[0] - X)
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(math.gcd, x)
    print(D)
Problem p03289 (python)

Fixed submission:
S = input()
accept = False

if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        accept = True

if accept:
    print("AC")

else:
    print("WA")

Buggy submission (verdict: Runtime Error):
if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        print("AC")
    else:
        print("WA")
else:
        print("WA")
Problem p03309 (python)

Fixed submission:
import statistics

N = int(input())
A = [int(c) for c in input().split()]
A = [n - (i+1) for i, n in enumerate(A)]

b = int(statistics.median(A))
print(sum([abs(n - b) for n in A]))

Buggy submission (verdict: Runtime Error):
import statistics

N = int(input())
A = [int(c) for c in input().split()]
A = [abs(n - (b+i+1)) for i, n in enumerate(A)]

b = int(statistics.median(A))
print(sum([abs(n - b) for n in A]))
Problem p03361 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

H, W = list(map(int, input().split()))
s = [[c for c in input()] for _ in range(H)]
accept = True

def dfs(x, y, count):
    if  x < 0 or W <= x or y < 0 or H <= y:
        return count - 1
    elif s[y][x] != "#":
        return count - 1
    else:
        s[y][x] = "."
        return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1))

for y in range(H):
    for x in range(W):
        if s[y][x] != "#":
            continue
        elif dfs(x, y, 0) == 0:
            accept = False

if accept:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
s = [[c for c in input()] for _ in range(H)]
accept = True

def dfs(x, y, count):
    if  x < 0 or W <= x or y < 0 or H <= y:
        return count - 1
    elif s[y][x] != "#":
        return count - 1
    else:
        s[y][x] = "."
        return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1))

for y in range(H):
    for x in range(W):
        if s[y][x] != "#":
            continue
        elif dfs(x, y, 0) == 0:
            accept = False

if accept:
    print("Yes")
else:
    print("No")
Problem p03363 (python)

Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
        count += sum([i for i in range(1, v)])

print(count)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
    if v > 1:
        count += factorial(v-1)

print(count)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
    if v-1 != 0:
        count += factorial(v-1)

print(count)
Problem p03417 (python)

Fixed submission:
N, M = [int(c) for c in input().split()]

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(M+N - 3)
else:
    print((M-2) * (N-2))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2), dtype="int8")
C = F.copy()
c = np.ones((N, M), dtype="int8")
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Buggy submission (verdict: Runtime Error):
N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))
Problem p03854 (python)

Fixed submission:
S = input()[::-1]
i = 0
ls = len(S)
accept = True

while ls > i:
    if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
        i += 5
    elif S[i: i+6] == "resare":
        i += 6
    elif S[i: i+7] == "remaerd":
        i += 7
    else:
        accept = False
        break

if accept:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S = input()
ls = len(S)

def dfs(i):
    if i == ls:
        return True
    elif S[i: i+5] == "dream" or S[i: i+5] == "erase" or S[i: i+6] == "eraser" or S[i: i+7] == "dreamer":
        return dfs(i+5) or dfs(i+6) or dfs(i+7)

    return False

if dfs(0):
    print("YES")
else:
    print("NO")
Problem p02705 (python)

Fixed submission:
from math import pi
r=int(input())
print(2*pi*r)

Buggy submission (verdict: Runtime Error):
from math import PI
r=int(input())
print(2*PI*r)
Problem p02639 (python)

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

for i in range(1, 6):
    if x[i-1] == 0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int, input().split())))
memo = {}
ans = 0

for a in A:
    if not a in memo:
        flag = True
        for div in memo:
            if a % div == 0:
                flag = False
                break
        if flag:
            ans += 1
            memo[a] = 1
    else:
        if memo[a] == 1:
            ans -= 1
            memo[a] += 1
        else:
            continue
print(ans)
Problem p02642 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
memo = [0]*(10**6+1)

for a in A:
    memo[a] += 1
    if memo[a] < 2:
        for i in range(2*a, 10**6+1, a):
            memo[i] += 1

ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1

print(ans)

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

N = int(input())
A = sorted(list(map(int, input().split())))
memo = {A[0]:None}
ans = 0

gcd_check = A[0]

for a in A[1:]:
    gcd_result = gcd(gcd_check, a)
    if gcd_result == 1:
        ans += 1
        memo[a] = None
        gcd_check *= a
    elif not gcd_result in memo:
        if gcd_result != a:
            ans += 1
            memo[a] = None
            gcd_check *= a
        else:
            memo[a] = None
    else:
        continue

if A[0] != A[1]:
    ans += 1

print(ans)
Problem p02660 (python)

Fixed submission:
N = int(input())

ans = 0

# if N % 2 == 0:
#     i = 1
#     while N % 2**i == 0:
#         N //= 2**i
#         ans += 1
#         i += 1

# if N % 3 == 0:
#     i = 1
#     while N % 3**i == 0:
#         N //= 3**i
#         ans += 1
#         i += 1

# if N % 5 == 0:
#     i = 1
#     while N % 5**i == 0:
#         N //= 5**i
#         ans += 1
#         i += 1

# if N % 7 == 0:
#     i = 1
#     while N % 7**i == 0:
#         N //= 7**i
#         ans += 1
#         i += 1

# if N % 11 == 0:
#     i = 1
#     while N % 11**i == 0:
#         N //= 11**i
#         ans += 1
#         i += 1

# if N % 13 == 0:
#     i = 1
#     while N % 13**i == 0:
#         N //= 13**i
#         ans += 1
#         i += 1

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)

prime_list = prime_factorize(N)

if prime_list:
    for prime_num in prime_list:
        if N % prime_num == 0:
            for j in range(1, 100):
                if N < prime_num**j:
                    break
                if N % prime_num**j == 0:
                    # print(prime_num, j)
                    N //= prime_num**j
                    ans += 1
# print(N)
# print(prime_list)
print(ans)

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

def factorize(x):
    factor = {}
    for num in range(2, int(x**0.5)+1):
        while x % num == 0:
            x = x // num
            try:
                factor[num] += 1
            except:
                factor[num] = 1
        if x != 1:
            factor[x] = 1
        return factor

prime_factor_list = factorize(N)
# print(prime_factor_list)
ans = 0

for key in prime_factor_list.keys():
    key_num = prime_factor_list[key] #{2:6}なら6
    nokori = key_num
    for i in range(1, key_num+1): #1~6まで
        if nokori < i:
            break#次の素数へ
        nokori -= i
        if N % key**i == 0:
            N //= key**i
            ans += 1
        else:
            break
print(ans)
Problem p02677 (python)

Fixed submission:
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * (360 / (60 * 12))
deg_b = m * (360 / 60)
deg = abs(deg_a - deg_b)
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)

Buggy submission (verdict: Runtime Error):
import math
 
def dcos(x):
    return math.cos(math.radians(x))
 
A, B, H, M = map(int, input().split())
 
one_H = 360 / 12
one_M = 360 / 60
one_H_M = one_H / 60
 
#短針の動きのみ考える。
kakudo_H = one_H * H
#分針の動きを加える。
kakudo_H = kakudo_H + one_H_M*M
 
if kakudo_H > 180:
    kakudo_H = 360 - kakudo_H
 
kakudo_M = one_M * M
if kakudo_M > 180:
    kakudo_M = 360 - kakudo_M
 
kakudo = abs(kakudo_M - kakudo_H)
 
ans = A**2 + B**2 + (-2)*A*B*dcos(kakudo)

assert dcos(kakudo) > 0
 
print(ans**0.5)

Buggy submission (verdict: Runtime Error):
import math
 
def dcos(x):
    return math.cos(math.radians(x))
 
A, B, H, M = map(int, input().split())
 
one_H = 360 / 12
one_M = 360 / 60
one_H_M = one_H / 60
 
#短針の動きのみ考える。
kakudo_H = one_H * H
#分針の動きを加える。
kakudo_H = kakudo_H + one_H_M*M
 
if kakudo_H > 180:
    kakudo_H = 360 - kakudo_H
 
kakudo_M = one_M * M
if kakudo_M > 180:
    kakudo_M = 360 - kakudo_M
 
kakudo = abs(kakudo_M - kakudo_H)
 
ans = A**2 + B**2 + (-2)*A*B*dcos(kakudo)

assert kakudo > 0
 
print(ans**0.5)
Problem p02678 (python)

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

memo =  [[] for _ in range(N+1)]

for _ in range(M):
    Ai, Bi = map(int, input().split())
    memo[Ai].append(Bi)
    memo[Bi].append(Ai)

# print(memo)

visited = [False] * (N+1)
visited[1] = True
ans = [0]*(N+1)

queue = [1]

while queue:
    room = queue.pop(0)
    for connected_room in memo[room]:
        # print(connected_room)
        if visited[connected_room] == True:
            continue
        ans[connected_room] = room
        visited[connected_room] = True
        queue.append(connected_room)
print("Yes")
for a in ans[2:]:
    print(a)

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

memo =  [[] for _ in range(M+1)]

for _ in range(M):
    Ai, Bi = map(int, input().split())
    memo[Ai].append(Bi)
    memo[Bi].append(Ai)

# print(memo)

visited = [False] * (N+1)
visited[1] = True
ans = [0]*(N+1)

queue = [1]

while queue:
    room = queue.pop(0)
    for connected_room in memo[room]:
        # print(connected_room)
        if visited[connected_room] == True:
            continue
        ans[connected_room] = room
        visited[connected_room] = True
        queue.append(connected_room)
print("Yes")
for a in ans[2:]:
    print(a)
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
memo = [-1] * (N+1)
checked_num = {1:None}
memo[0] = 1

teleporter = A[0]
memo[1] = teleporter
checked_num[memo[1]] = None
repeat_point = -1
flag = False

for i in range(2, N+1):
    # print(i, checked_num)
    memo[i] = A[teleporter-1]
    teleporter = A[teleporter-1]
    if memo[i] in checked_num and flag == False:
        repeat_point = i
        flag = True
    checked_num[memo[i]] = None

# print(memo)

start_point = memo.index(memo[repeat_point])
repeat = repeat_point - start_point
# print(memo, start_point, repeat_point)

if K <= N:
    print(memo[K])
else:
    mod = (K-start_point) % repeat
    # print(memo, start_point, repeat_point, mod)
    print(memo[mod+start_point])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
memo = [-1] * N
checked_num = {}

teleporter = A[0]
memo[0] = teleporter
repeat_point = -1
flag = False

for i in range(1, N):
    memo[i] = A[teleporter-1]
    teleporter = A[teleporter-1]
    checked_num[memo[i]] = None
    if memo[i] in checked_num and flag == False:
        repeat_point = i
        flag = True

start_point = memo.index(memo[repeat_point])
repeat = repeat_point - start_point
# print(memo, start_point, repeat_point)

if K <= N:
    print(memo[K-1])
else:
    mod = K % repeat
    print(memo[mod-1])
Problem p02702 (python)

Fixed submission:
import math

# def comb_count(n, r):
#     return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = (int(S[i]) * tmp + current) % 2019
    mod = current % 2019
    ans += mods[mod]
    mods[mod] += 1
    tmp = tmp * 10 % 2019

# for mod in mods:
#     if mod > 1:
#         ans += comb_count(mod, 2)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def comb_count(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(int(ans))