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

Fixed submission:
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        fi = [pow(f[-1], mod - 2, mod)]
        for idx in range(max_fact, 0, -1):
            fi += [fi[-1] * idx % mod]
        fi = fi[::-1]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 5 * 10**5
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation

N, M = [int(_) for _ in input().split()]
ans = 0
for p in range(N + 1):
    ans += (-1)**p * comb(N, p) * perm(M - p, N - p)
    ans %= mod
ans *= perm(M, N)
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
max_fact = 5 * 10**5
mod = 10**9 + 7

f = [1] * (max_fact + 1)
for idx in range(2, max_fact + 1):
    f[idx] = f[idx - 1] * idx
    f[idx] %= mod
fi = [pow(f[-1], mod - 2, mod)]
for idx in range(max_fact, 0, -1):
    fi += [fi[-1] * idx % mod]
fi = fi[::-1]

def factorial(self, n):
    return f[n]

def factorial_inverse(self, n):
    return fi[n]

def combination(self, n, r):
    return f[n] * fi[r] * fi[n - r] % mod

def permutation(self, n, r):
    return f[n] * fi[n - r] % mod

def homogeneous_product(self, n, r):
    return f[n + r - 1] * fi[r] * fi[n - 1] % mod


comb = combination
perm = permutation

N, M = [int(_) for _ in input().split()]
ans = 0
for p in range(N + 1):
    ans += (-1)**p * comb(N, p) * perm(M - p, N - p)
    ans %= mod
ans *= perm(M, N)
ans %= mod
print(ans)
Problem p02695 (python)

Fixed submission:
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(N - 1):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(M):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(M):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)
print(cand)

Buggy submission (verdict: Runtime Error):
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(M):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b] - l[a] == c:
            x += d
    ans = max([ans, x])
print(ans)
Problem p02771 (python)

Fixed submission:
A, B, C = [int(_) for _ in input().split()]
if A == B == C:
    ans = 'No'
elif A == B or B == C or C == A:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
#import numpy as np
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
#A = np.array([int(_) for _ in input().split()],dtype=int)
#A.sort()
A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget

def check(target):
    cnt=0
    for i, a in enumerate(A):
        if a < 0:
            il = bisect.bisect_left(A,  target / a)
            #il = np.searchsorted(A,target/a,side='left')
            #ilからiまで、ただしilがiを超えたら0
            d = max(i - il, 0)
        elif a > 0:
            ir = bisect.bisect_right(A, target / a)
            #ir = np.searchsorted(A,target/a,side='right')
            #0からirまで、ただしirがiを超えたらi
            d = min(ir, i)
        else:
            d = i if target >= 0 else 0
        #print(target,a,d)
        cnt+=d
    return cnt>=K

lb = -10**18-1
rb = 10 ** 18 + 1
# Min x for check(x) == True
while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(mid):
        rb = mid
    else:
        lb = mid
print(rb)
Problem p02863 (python)

Fixed submission:
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(zip(A, B)):
    dp_new = dp[:]
    for k in range(T):
        if dp[k] == -1:
            continue
        dp_new[k + a] = max(dp[k + a], dp[k] + b)
    dp = dp_new
print(max(dp))

Buggy submission (verdict: Runtime Error):
I = [int(_) for _ in open(0).read().split()]
N, T = I[:2]
A, B = I[2::2], I[3::2]
dp = [-1] * 6001
dp[0] = 0
for a, b in zip(A, B):
    dp_new = dp.copy()
    for k in range(T):
        if dp[k] == -1:
            continue
        dp_new[k + a] = max(dp[k + a], dp[k] + b)
    dp = dp_new
print(max(dp))
Problem p02925 (python)

Fixed submission:
import itertools
#0-indexed
N = int(input())
A = [[int(_) - 1 for _ in input().split()][::-1] for _ in range(N)]
ans = 0
cand = range(N)
left = 1
while True:
    cand_ = set()
    for i in cand:
        v = A[i]
        if not len(v):
            continue
        if A[v[-1]][-1] == i:
            f = 0
            cand_.add(i)
            cand_.add(v[-1])
    if not cand_:
        break
    cand = cand_
    left = 0
    for i in cand:
        A[i].pop()
        left |= len(A[i]) > 0
    ans += 1
if left:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
import sys
import numpy as np
#0-indexed
N = int(input())
A = np.array(sys.stdin.buffer.read().split(), dtype=int).reshape((N, N - 1))
A -= 1
R = np.arange(N)
ans = 0
while True:
    I = (A[A[:, 0]][:, 0] == R) * (A[:, 0] != -1)
    if not I.any():
        break
    ans += 1
    A[I, :-1] = A[I, 1:]
    A[I, -1] = -1
if (A == -1).all():
    print(ans)
else:
    print(-1)
Problem p02984 (python)

Fixed submission:
N=int(input())
A=[int(_) for _ in input().split()]
ans=[0]*N
ans[0]=sum(A)//2-sum(A[1::2])
for i in range(N-1):
    ans[i+1]=A[i]-ans[i]
print(' '.join(str(2*a) for a in ans))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(_) for _ in input().split()]
ans=[0]*N
ans[0]=sum(A)//2-sum(A[1::2])
for i in range(N-１):
    ans[i+1]=A[i]-ans[i]
print(' '.join(str(2*a) for a in ans))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(_) for _ in input().split()]
ans=[0]*N
ans[0]=sum(A)//2-sum(A[1::2])
for i in range(N-):
    ans[i+1]=A[i]-ans[i]
print(' '.join(str(2*a) for a in ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=[int(_) for _ in input().split()]
X=np.eye(N)
for i in range(N-1):
    X[i+1][i]=1
X[0][N-1]=1
ans=np.dot(A,np.linalg.inv(X))*2
print(*ans.astype(int))
Problem p03003 (python)

Fixed submission:
import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
    dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
    if S[n] == T[m]:
        dp[n + 1][m + 1] += dp[n][m]
    dp[n + 1][m + 1] %= mod
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (N + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
    dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
    if S[n] == T[m]:
        dp[n + 1][m + 1] += dp[n][m]
    dp[n + 1][m + 1] %= mod
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (N + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
    dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
    if S[n] == T[m]:
        dp[n + 1][m + 1] += dp[n][m]
    dp[n + 1][m + 1] %= mod
print(dp[-1][-1])
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N, M = [int(_) for _ in input().split()]
XYZ = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y, z in XYZ:
    unite(x, y)
s = set()
for i in range(1, N + 1):
    s.add(find(i))
print(len(set(s)))

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

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y, z in XYZ:
    unite(x, y)
s = set()
for i in range(1, N + 1):
    s.add(find(i))
print(len(set(s)))

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

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y, z in XYZ:
    unite(x, y)
for i in range(1, N + 1):
    find(i)
print(len(set(UF[1:])))

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

UF = list(range(N))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y, z in XYZ:
    unite(x - 1, y - 1)
for i in range(N):
    find(i)
print(len(set(UF)))
Problem p03053 (python)

Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy submission (verdict: Runtime Error):
import itertools

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
D = []
S = []
for x, y in itertools.product(range(H), range(W)):
    if A[x][y] == '.':
        D += [[x, y]]
    else:
        S += [[x, y]]

print(max(min([abs(X - x) + abs(Y - y) for x, y in S]) for X, Y in D))
Problem p03222 (python)

Fixed submission:
H, W, K = [int(_) for _ in input().split()]
fib = [1, 1, 2, 3, 5 ,8, 13, 21]
dp = [[1] + [0] * (W - 1)]
if W == 1:
    print(1)
else:
    for j in range(1, H + 1):
        dp.append([0] * W)
        for i in range(W):
            if i == 0:
                dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i + 1] * fib[i] * fib[W - i - 2]) % 1000000007
            elif i == W - 1:
                dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i - 1] * fib[i - 1] * fib[W - i - 1]) % 1000000007
            else:
                dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i + 1] * fib[i] * fib[W - i - 2] + dp[j - 1][i - 1] * fib[i - 1] * fib[W - i - 1]) % 1000000007
    print(dp[H][K - 1])

Buggy submission (verdict: Runtime Error):
H, W, K = [int(_) for _ in input().split()]
fib = [1, 1, 2, 3, 5 ,8, 13, 21]
dp = [[1] + [0] * (W - 1)]
for j in range(1, H + 1):
    dp.append([0] * W)
    for i in range(W):
        if i == 0:
            dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i + 1] * fib[i] * fib[W - i - 2]) % 1000000007
        elif i == W - 1:
            dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i - 1] * fib[i - 1] * fib[W - i - 1]) % 1000000007
        else:
            dp[j][i] = (dp[j - 1][i] * fib[i] * fib[W - i - 1] + dp[j - 1][i + 1] * fib[i] * fib[W - i - 2] + dp[j - 1][i - 1] * fib[i - 1] * fib[W - i - 1]) % 1000000007
print(dp[H][K - 1])
Problem p03822 (python)

Fixed submission:
import collections
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

s1 = [1]
s2 = []
while s1:
    a = s1.pop()
    s2 += [a]
    for b in win_lose[a]:
        s1 += [b]
memo = [0] * (N + 1)
for x in s2[::-1]:
    if win_lose[x] == set():
        memo[x] = 0
    else:
        memo[x] = max(a + b for a, b in zip(
            sorted(memo[y] for y in win_lose[x])[::-1], range(1, N + 1)))
print(memo[1])

Buggy submission (verdict: Runtime Error):
import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(a + b for a, b in zip(
                sorted(rec(y) for y in win_lose[x])[::-1], range(1, N + 1)))
    return memo[x]


print(rec(1))

Buggy submission (verdict: Runtime Error):
import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(a + b for a, b in zip(
                sorted(rec(y) for y in win_lose[x])[::-1], range(1, N + 1)))
    return memo[x]


print(rec(1))
print(memo)

Buggy submission (verdict: Runtime Error):
import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(rec(y) for y in win_lose[x]) + len(win_lose[x])
    return memo[x]


print(
    max(a + b for a, b in zip(
        sorted(rec(x) for x in win_lose[1])[::-1], range(1, N + 1))))

Buggy submission (verdict: Runtime Error):
import collections
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(rec(y) for y in win_lose[x]) + len(win_lose[x])
    return memo[x]


for x in win_lose[1]:
    rec(x)
print(1 + max(memo[2:]))
Problem p02577 (python)

Fixed submission:
n = int(input())
if n%9==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = input()
if n%9==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = input()
if n%==0:
  print('Yes')
else:
  print('No')
Problem p02629 (python)

Fixed submission:
list = [0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
num_list =[0]
for i in range(1,15):
    num_list.append(26**i+num_list[i-1])

n = int(input())
i = 0
while True:
    if num_list[i] >= n:
        break
    else:
        i +=1


word = []
for j in range(i,0,-1):
    x = n//26**(j-1)
    if x==27:
        word.append(26)
        n = n -26**(j-1)*(n//26**(j-1))+26**(j-1)
    else:
        word.append(x)
        n = n -26**(j-1)*(n//26**(j-1))
while True:
    if 0 in word:
        p = word.index(0)
        word[p-1] = word[p-1]-1
        word[p] = 26
    else:
        break
h =''
for k in range(len(word)):
    h+=str(list[word[k]])
print(h)

Buggy submission (verdict: Runtime Error):
n = int(input())
list=[0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
word = []
i = 12
while i>=0:
  x = n//(26**i)
  word.append(x)
  n = n-x*26**i
  i -= 1

while True:
  word = int(''.join(word)).split()
  if 0 in word:
    p = word.index(0)
    word[p-1] = word[p-1]-1 
    word[p] = 26
  else:
    break

h=''
for i in range(len(word)):
  h += list[word[i]]
print(h)

Buggy submission (verdict: Runtime Error):
n = int(input())
list=[0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
word = []
i = 12
while i>=0:
  x = n//(26**i)
  word.append(x)
  n = n-x*26**i
  i -= 1

while True:
  word = int(''.join(word)).split()
  if 0 in word:
    p = word.index(0)
    word[p-1] = word[p-1]-1 
    word[p] = 26
  else:
    break

h=''
for i in range(len(word)):
  h += list[word[i]]
print(h)

Buggy submission (verdict: Runtime Error):
list = [0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
num_list =[0]
for i in range(1,15):
    num_list.append(26**i+num_list[i-1])

n = int(input())
i = 0
while True:
    if num_list[i] >= n:
        break
    else:
        i +=1


word = []
for j in range(i,0,-1):
    x = n//26**(j-1)
    elif x==27:
        word.append(26)
        n = n -26**(j-1)*(n//26**(j-1))+26**(j-1)
    else:
        word.append(x)
        n = n -26**(j-1)*(n//26**(j-1))
while 0 in word:
    p = word.index(0)
    word[p-1] = word[p-1]-1
    word[p] = 26
h =''
for k in range(len(word)):
    h+=str(list[word[k]])
print(h)
Problem p02659 (python)

Fixed submission:
a,b = input().split()
a = int(a)
b = int(b.replace('.',''))
print(a*b//100)

Buggy submission (verdict: Runtime Error):
import math
a,b =input().split()
a = int(a)
b = float((int(int(b)*100))/100)
c = math.floor(a*b)
print(c)

Buggy submission (verdict: Runtime Error):
import math
a,b =input().split()
a = int(a)
b = float((int(b*100))/100)
c = math.floor(a*b)
print(c)
Problem p02693 (python)

Fixed submission:
k = int(input())
a,b = map(int,input().split())
c =0
for i in range(1,int(b/k)+1):
    if a <= i*k <= b:
        c = 1
        break
if c ==1:
    print('OK')
else:
    print('NG')

Buggy submission (verdict: Runtime Error):
import itertools
n,m,q = map(int,input().split())
group = []
for i in range(q):
  w,x,y,z = map(int,input().split())
  v = (w,x,y,z)
  group.append(v)
#groupに(a,b,c,d)がタプルで入っている
max_value = max(group[i][3] for i in range(len(group)))

#Aの配列を試す

l = [i for i in range(1,m+1)]
h = itertools.combinations_with_replacement(l,n)
array =[]

for v in h:
    array.append(v)
#arrayが全ての配列になった


for j in range(len(array)):
  total = 0
  for i in range(q):
    if array[j][group[i][1]-1] - array[j][group[i][0]-1] == group[i][2]:
      total += group[i][3]
  if total >= max_value:
    max_value = total  

print(max_value)
Problem p02699 (python)

Fixed submission:
s,w = input().split()
if int(w) >= int(s):
  print('unsafe')
else:
  print('safe')

Buggy submission (verdict: Runtime Error):
# -*- encode utf-8 -*-
#羊の数と狼の数を入力
S,W = int(input())
狼の数が羊の数以上のとき、羊は狼に襲われてしまいます。
if 2W >= S:
	print(unsafe)
else:
	print(safe)
Problem p03634 (python)

Fixed submission:
import sys

sys.setrecursionlimit(200000)

n = int(input())
# 値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    adjacent_list[a].append([b, c])
    adjacent_list[b].append([a, c])
# ノード番号、そこまでの距離,検索済みの要素を受け取る。


def dfs(node_n, distance, finished):
    # 検索済みに追加
    finished.add(node_n)
    # そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    # 対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            # 検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1], finished)


q, k = list(map(int, input().split()))
dfs(k, 0, set())
# 各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])

Buggy submission (verdict: Runtime Error):
n = int(input())
# 値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    adjacent_list[a].append([b, c])
    adjacent_list[b].append([a, c])
# ノード番号、そこまでの距離,検索済みの要素を受け取る。


def dfs(node_n, distance, finished):
    # 検索済みに追加
    finished.add(node_n)
    # そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    # 対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            # 検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1], finished)


q, k = list(map(int, input().split()))
dfs(k, 0, set())
# 各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    if path[s] is not None and path[g] is not None:
        print(path[s] + path[g])

Buggy submission (verdict: Runtime Error):
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    is path[s] is not None and path[g] is not None:
        print(path[s] + path[g])
Problem p02736 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from functools import reduce
from itertools import starmap
from operator import xor, mul
N = int(input())
A = list(map(int ,input().strip()))

A = [abs(x-y) for x,y in zip(A,A[1:])]
n = len(A)
# Lucas
coef = [((n-1)&k)==k for k in range(n)]
if 1 in A:
    B = [x % 2 for x in A]
    ans = reduce(xor, starmap(mul, zip(B,coef)))
else:
    B = [x // 2 for x in A]
    ans = reduce(xor, starmap(mul, zip(B,coef)))*2

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from functools import reduce
from itertools import starmap
from operator import xor, mul
N = int(input())
A = list(map(int ,input().strip()))

def solve(A):
    A = [abs(x-y) for x,y in zip(A,A[1:])]
    n = len(A)
    coef = 1
    for i in range(n-1):
        coef = coef ^ (coef << 1)
    coef = map(int, bin(coef)[2:])
    if 1 in A:
        B = [x % 2 for x in A]
        ans = reduce(xor, starmap(mul, zip(B,coef)))
    else:
        B = [x // 2 for x in A]
        coef = [nCr(n-1,i) for i in range(n)]
        ans *= 2
    return ans 

print(solve(A))