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

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split())

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)
Problem p02866 (python)

Fixed submission:
N = int(input())
D = list(map(int,input().split()))
BIGNUM = 998244353

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

if distance_dict[0] != 1:
    print(0)
    exit()

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict: # 一つでもとんでったらアウト。距離がない。連結できない
        ans = 0
        print(0)
        exit()

    elif i != 0:
        ans *= (distance_dict[i-1]**distance_dict[i]) # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)

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

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict:
        ans = 0
    else:
        ans *= distance_dict[i-1]**distance_dict[i] # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)
Problem p02936 (python)

Fixed submission:
n,q=map(int,input().split())
ab=[]
for i in range(n-1):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
ans=[0]*n
cnt=[0]*n
for i in range(q):
	x,y=map(int,input().split())
	ans[x-1]+=y
for i in range(n-1):
	ans[ab[i][1]-1]+=ans[ab[i][0]-1]
print(*ans)

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

tree = [[0]*N for _ in range(N)]

for i in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    tree[y].append(x)
    tree[x].append(y)
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y
    

def dfs(cur,par):
    for chl in tree[cur]:
        if chl == par: #これで木の流れの逆行を防ぐ
            continue
        ans[chl] += ans[cur]
        dfs(chl,cur)
    
dfs(0,-111111)
print(*ans)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
ab = []
for i in range(n-1):
    x,y = map(int,input().split())
    ab.append([x,y])
ab.sort()
ans = [0]*N
for i in range(Q):
    x,y = map(int,input().split())
    ans[x-1] += y
for i in range(N-1):
    ans[ab[i][1]-1] += ans[ab[i][1] - 1]
print(*ans)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
adjacent_list = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    adjacent_list[a].append(b)
cnt = [0]*(N+1)
def dfs(v,x):
    cnt[v] += x
    for nv in adjacent_list[v]:
        dfs(nv,x)

for q in range(Q):
    p,x = map(int,input().split())
    dfs(p,x)
print(*cnt[1:])
Problem p02949 (python)

Fixed submission:
# 両方から到達出来ないものに関する辺を無視してベルマンフォード
import sys
sys.setrecursionlimit(10**6)
n, m, p = map(int, input().split())
edges = []
to = [[] for _ in range(n)]
ot = [[] for _ in range(n)]
reachable_from_1 = [False] * n
reachable_to_n = [False] * n
ok = [False] * n
INF = float('inf')


def dfs(v):
    if reachable_from_1[v]:
        return
    reachable_from_1[v] = True
    for nv in to[v]:
        dfs(nv)


def rdfs(v):
    if reachable_to_n[v]:
        return
    reachable_to_n[v] = True
    for nv in ot[v]:
        rdfs(nv)


for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c -= p
    c = -c
    edges.append((a, b, c))
    to[a].append(b)
    ot[b].append(a)
dfs(0)
rdfs(n - 1)
for i in range(n):
    ok[i] = reachable_from_1[i] and reachable_to_n[i]
d = [INF] * n
d[0] = 0
upd = True
step = 0
while upd:
    upd = False
    for e in edges:
        frm, to, cost = e
        if not ok[frm]:
            continue
        if not ok[to]:
            continue
        nd = d[frm] + cost
        if nd < d[to]:
            d[to] = nd
            upd = True
    step += 1
    if step > n:
        print(-1)
        exit()
ans = -d[n - 1]
ans = max(0, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
# 両方から到達出来ないものに関する辺を無視してベルマンフォード
n, m, p = map(int, input().split())
edges = []
to = [[] for _ in range(n)]
ot = [[] for _ in range(n)]
reachable_from_1 = [False] * n
reachable_to_n = [False] * n
ok = [False] * n
INF = float('inf')


def dfs(v):
    if reachable_from_1[v]:
        return
    reachable_from_1[v] = True
    for nv in to[v]:
        dfs(nv)


def rdfs(v):
    if reachable_to_n[v]:
        return
    reachable_to_n[v] = True
    for nv in ot[v]:
        rdfs(nv)


for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c -= p
    c = -c
    edges.append((a, b, c))
    to[a].append(b)
    ot[b].append(a)
dfs(0)
rdfs(n - 1)
for i in range(n):
    ok[i] = reachable_from_1[i] and reachable_to_n[i]
d = [INF] * n
d[0] = 0
upd = True
step = 0
while upd:
    upd = False
    for e in edges:
        frm, to, cost = e
        if not ok[frm]:
            continue
        if not ok[to]:
            continue
        nd = d[frm] + cost
        if nd < d[to]:
            d[to] = nd
            upd = True
    step += 1
    if step > n:
        print(-1)
        exit()
ans = -d[n - 1]
ans = max(0, ans)
print(ans)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7
N,K = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

ans = 1
def dfs(now, par,num):
    global ans
    ans = ans*num%MOD
    num = K-1
    if par != -1:
        num -= 1
    for ch in edge[now]:
        if ch != par:
            dfs(ch,now,num)
            num -= 1

dfs(0,-1,K)
print(ans)
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

lcm = c*d // fractions.gcd(c,d)


b_num = b - (b//c + b//d - b//lcm)
a_num = a-1 - (a-1)// c - (a-1)//d + (a-1) // lcm

ans = b_num - a_num
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int,input().split())
lcm = C*D/math.gcd(C,D)
def c_in_a2b(c):
    return (math.ceil(B//c) - math.floor(A//c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))
Problem p03014 (python)

Fixed submission:
import numpy as np
h, w = map(int, input().split())
table = np.array([list(input())for _ in range(h)]) == '.'
 
d = np.zeros((h, w), dtype = int)
u = np.zeros((h, w), dtype = int)
r = np.zeros((h, w), dtype = int)
l = np.zeros((h, w), dtype = int)

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]

for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
# dir: 0 -> start
# dir: 1 -> right
# dir: 2 -> down
# dir: 3 -> left
# dir: 4 -> up

grid = [list(input()) for _ in range(H)]


def dfs(grid,y,x,dir):
    global num_l
    if not (0 <= x < W and 0 <= y < H):
        return
    if grid[y][x] == '#':
        return
    num_l += 1
    if dir == 0:
        dfs(grid, y, x+1, 1)
        dfs(grid, y+1, x, 2)
        dfs(grid, y, x-1, 3)
        dfs(grid, y-1, x, 4)
    elif dir == 1:
        dfs(grid, y, x + 1, 1)
    elif dir == 2:
        dfs(grid, y+1, x, 2)
    elif dir == 3:
        dfs(grid, y, x-1, 3)
    elif dir == 4:
        dfs(grid, y-1, x, 4)

ans = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == '.':
            num_l = 0
            dfs(grid, h, w, 0)
            ans = max(ans,num_l)
print(ans)
Problem p03031 (python)

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

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

ans = 0
for i in range(2**N):
    light_cnt = 0
    for condition_idx in range(M):


        switch_num = 0
        for j in range(N):
            if i >> j & 1 and j+1 in conditions[condition_idx][1:]: # つながっているスイッチの押してあるものを数える
                switch_num += 1
        if switch_num%2 == p[condition_idx]:
            light_cnt += 1
    if light_cnt == M:
        ans += 1
print(ans)

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

ans_cnt = 0
for i in range(2**N):
    condition_cnt = 0
    for j in range(M):

        cnt=0
        for k in connections[j][1:]:
            if (i >> k) & 1:
                cnt += 1
        if (cnt +conditions[j])%2 == 0:
            condition_cnt += 1
    if condition_cnt == M:
        ans_cnt += 1

print(ans_cnt)

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

ans_cnt = 0
for i in range(2**N):
    condition_cnt = 0
    for j in range(M):

        cnt=0
        for k in connections[j][1:]:
            if (i >> k) & 1):
                cnt += 1
        if (cnt +conditions[j])%2 == 0:
            condition_cnt += 1
    if condition_cnt == M:
        ans_cnt += 1

print(ans_cnt)
Problem p03035 (python)

Fixed submission:
a,b=map(int,input().split())
if a >= 13:
    print(b)
elif 6<=a<=12:
    print(int(b/2))
else:
    print("0")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A= list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in M]
A.sort()
BC.sort(key=lambda x:-x[1])
i = 0
for B,C in BC:
    for j in range(i,min(N,i+B)):
        if A[j]<C:A[j]=C
    i = i+B
print(sum(A))
Problem p03043 (python)

Fixed submission:
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
from math import ceil, log2
m_list = [ceil(log2(K/(n+1))) if n+1<K else 0 for n in range(N)]
#print(m_list) #各nに対し勝つのに必要な表の数

#
# m_list = []
# for n in range(N):
#     if n+1 >=

def calc_prob(x):
    return (1/2)**x

#prob_list = list(map(calc_prob,m_list))

# Kより大きいインデックスのところは1に書き換え
#print(prob_list)
print(sum(prob_list)/N)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
adjacent_list = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u -= 1
    v -= 1
    adjacent_list[u].append([v, w])
    adjacent_list[v].append([u, w])


colors = [-1]*N


def dfs(v, color):
    if colors[v] != -1:
        return
    colors[v] = color
    for adjacent_v in adjacent_list[v]:
        if adjacent_v[1] % 2 == 0:
            dfs(adjacent_v[0], color)
        else:
            dfs(adjacent_v[0], 1-color)

dfs(0,0)

#print(*colors)
for i in range(N):
    print(colors[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
adjacent_list = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u -= 1
    v -= 1
    adjacent_list[u].append([v, w])
    adjacent_list[v].append([u, w])


colors = [-1]*N


def dfs(v, color):
    if colors[v] != -1:
        return
    colors[v] = color
    for adjacent_v in adjacent_list[v]:
        if adjacent_v[1] % 2 == 0:
            dfs(adjacent_v[0], color)
        else:
            dfs(adjacent_v[0], 1-color)

dfs(0,0)

#print(*colors)
for i in range(N):
    print(colors[i])
Problem p03050 (python)

Fixed submission:
N = int(input())
divisors = []
for i in range(1,int(N**0.5)+1):
    #print(i)
    if N%i == 0:
        divisors.append(i)
        divisors.append(N//i)
divisors.remove(1)
ds = set(divisors)
ans = 0
for div in ds:
    if div == 1:
        continue

    if N//(div-1) == N%(div-1):
        ans += div-1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
divisors = []
for i in range(1,int(N**0.5)+1):
    #print(i)
    if N%i == 0:
        divisors.append(i)
        divisors.append(N//i)
divisors.remove(1)
#print(divisors)
ds = set(divisors)
ans = 0
for div in ds:

    if N//(div-1) == N%(div-1):
        ans += div-1
print(ans)
Problem p03061 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
lgcd = [0]*N
rgcd = [0]*N
from fractions import gcd
#def gcd(a,b):
#    if b == 0:return a
#    else:return gcd(b, a%b)

temp_lgcd = A[0]
for i in range(N):
    temp_lgcd = gcd(temp_lgcd,A[i])
    lgcd[i] = temp_lgcd

temp_rgcd = A[-1]
for i in range(N-1,-1,-1):
    temp_rgcd = gcd(temp_rgcd,A[i])
    rgcd[i] = temp_rgcd

ans = 0
for i in range(N):
    if i == 0:
        calc_gcd = rgcd[1]
    elif i == N-1:
        calc_gcd = lgcd[-2]
    else:
        calc_gcd = gcd(lgcd[i-1],rgcd[i+1])
    ans = max(ans,calc_gcd)
print(ans)

Buggy submission (verdict: Runtime Error):
import sympy as sp
import copy

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

def calc_gcd(list):
    ans = list[0]
    for i in range(1,n-1):
        ans = sp.gcd(ans,list[i])
    return ans

#a = [1,2,3,4,5,6,7]

for j in range(n):
    b= copy.copy(a)
    b.pop(j)
    nlist.append(calc_gcd(b))

#print(nlist)
print(max(nlist))
Problem p03076 (python)

Fixed submission:
nlist = [int(input()) for i in range(5)]
#print(nlist)
total_time=0
tail=[]
for number in nlist:
    if number % 10 == 0:
        total_time += number
    else:
        total_time += (number+10-(number%10))
        tail.append(number%10)
if tail:
    total_time -= (10-min(tail))
print(total_time)

Buggy submission (verdict: Runtime Error):
nlist = [int(input()) for i in range(5)]
#print(nlist)
total_time=0
tail=[]
for number in nlist:
    if number % 10 == 0:
        total_time += number
    else:
        total_time += (number+10-(number%10))
        tail.append(number%10)

total_time -= (10-min(tail))
print(total_time)
Problem p03086 (python)

Fixed submission:
wlist = list(input())
wlength = 0
tmp = 0
for w in wlist:
    if not w in ["A","T","G","C"]:
        tmp = 0
        continue

    else:
        tmp += 1
        if tmp >= wlength:
            wlength = tmp
print(wlength)

Buggy submission (verdict: Runtime Error):
wlist = list(input())
wlength = 0

for w in wlist:
    if not w in ["A","T","G","C"]:
        tmp = 0
        continue

    else:
        tmp += 1
        if tmp >= wlength:
            wlength = tmp
print(wlength)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = (0, 0, 1, -1)
dy = (1, -1, 0, 0)
seen = [[False] * w for _ in range(h)]

numb = 0
numw = 0


def dfs(x, y):
    global numb, numw
    seen[x][y] = True
    if s[x][y] == '#':
        numb += 1
    else:
        numw += 1
    for di in range(4):
        nx = x + dx[di]
        ny = y + dy[di]
        if (nx < 0 or nx >= h or ny < 0 or ny >= w):
            continue
        if s[x][y] == s[nx][ny]:
            continue
        if seen[nx][ny]:
            continue
        dfs(nx, ny)


ans = 0
for x in range(h):
    for y in range(w):
        if seen[x][y]:
            continue
        if s[x][y] == '.':
            continue
        numb = 0
        numw = 0
        dfs(x, y)
        ans += numb * numw
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = (0, 0, 1, -1)
dy = (1, -1, 0, 0)
seen = [[False] * w for _ in range(h)]

numb = 0
numw = 0


def dfs(x, y):
    global numb, numw
    seen[x][y] = True
    if s[x][y] == '#':
        numb += 1
    else:
        numw += 1
    for di in range(4):
        nx = x + dx[di]
        ny = y + dy[di]
        if (nx < 0 or nx >= h or ny < 0 or ny >= w):
            continue
        if s[x][y] == s[nx][ny]:
            continue
        if seen[nx][ny]:
            continue
        dfs(nx, ny)


ans = 0
for x in range(h):
    for y in range(w):
        if seen[x][y]:
            continue
        if s[x][y] == '.':
            continue
        numb = 0
        numw = 0
        dfs(x, y)
        ans += numb * numw
print(ans)
Problem p03160 (python)

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [0]*(N+1)
# dp[i+1]はindexでiの足場までのコストの最小値
# dp[N]は求める値
dp[2] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i+1] = min(dp[i] + abs(h[i]-h[i-1]),dp[i-1] + abs(h[i]-h[i-2]))
print(dp[N])

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
grid = [list(input()) for _ in range(H)]
#print(grid)
MOD = 10**9+7
dp = [[0]*W for i in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if i+1 < H and grid[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= MOD
        if j+1 < W and grid[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
            dp[i][j+1] %= MOD
print(dp[H-1][W-1])
Problem p03175 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def main():
  MOD = 10**9+7
  N = int(input())
  edge = [[] for _ in range(N+1)]
  dp = [[0]*2 for i in range(100005)]
  # dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
  # 葉が決まると順々に求まっていく
  for i in range(N-1):
      x,y = map(int,input().split())
      edge[x].append(y)
      edge[y].append(x)

  # 0:white,1:black
  def dfs(v,last=-1):
      dp[v][0] = 1
      dp[v][1] = 1
      for nv in edge[v]:
          if nv == last:
              continue
          dfs(nv, v)
          dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
          dp[v][1] = dp[v][1] * dp[nv][0] % MOD


  dfs(1)
  print((dp[1][0] + dp[1][1])%MOD)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def main():
  MOD = 10**9+7
  N = int(input())
  edge = [[] for _ in range(N+1)]
  dp = [[0]*2 for i in range(100005)]
  # dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
  # 葉が決まると順々に求まっていく
  for i in range(N-1):
      x,y = map(int,input().split())
      edge[x].append(y)
      edge[y].append(x)

  # 0:white,1:black
  def dfs(v,last=-1):
      dp[v][0] = 1
      dp[v][1] = 1
      for nv in edge[v]:
          if nv == last:
              continue
          dfs(nv, v)
          dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
          dp[v][1] = dp[v][1] * dp[nv][0] % MOD


  dfs(1)
  print((dp[1][0] + dp[1][1])%MOD)
if __name__ == ''__main__:
  main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
MOD = 10**9+7
N = int(input())
edge = [[] for _ in range(N+1)]
dp = [[0]*2 for i in range(100005)]
# dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
# 葉が決まると順々に求まっていく
for i in range(N-1):
    x,y = map(int,input().split())
    edge[x].append(y)
    edge[y].append(x)

# 0:white,1:black
def dfs(v,last=-1):
    dp[v][0] = 1
    dp[v][1] = 1
    for nv in edge[v]:
        if nv == last:
            continue
        dfs(nv, v)
        dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
        dp[v][1] = dp[v][1] * dp[nv][0] % MOD


dfs(1)
print(dp[1][0] + dp[1][1])MOD = 10**9+7
N = int(input())
edge = [[] for _ in range(N+1)]
dp = [[0]*2 for i in range(100005)]
# dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
# 葉が決まると順々に求まっていく
for i in range(N-1):
    x,y = map(int,input().split())
    edge[x].append(y)
    edge[y].append(x)

# 0:white,1:black
def dfs(v,last=-1):
    dp[v][0] = 1
    dp[v][1] = 1
    for nv in edge[v]:
        if nv == last:
            continue
        dfs(nv, v)
        dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
        dp[v][1] = dp[v][1] * dp[nv][0] % MOD


dfs(1)
print(dp[1][0] + dp[1][1])
Problem p03197 (python)

Fixed submission:
N = int(input())
a = list(int(input()) for _ in range(N))
print('second' if all(a[i] % 2 == 0 for i in range(N)) else 'first')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int(input()) for _ in range(N)))
print('second' if all(a[i] % 2 == 0 for i in range(N)) else 'first')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
print('second' if all(a[i] % 2 == 0 for i in range(N)) else 'first')
Problem p03227 (python)

Fixed submission:
a = input()
if len(a) == 2:
  print(a)
else:
  print(a[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(len(row),*row)
Problem p03230 (python)

Fixed submission:
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(len(row),*row)

Buggy submission (verdict: Runtime Error):
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(len(row)+ *row))