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

Fixed submission:
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
maxf = a + b + 10

if (not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0)) or (a < 0 or b < 0):
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)

Buggy submission (verdict: Runtime Error):
    MOD = 10 ** 9 + 7
     
    X, Y = map(int, input().split())
     
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
     
    if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
        print(0)
        exit()
     
    maxf = a + b + 1
    f = [1 for _ in range(maxf)]
    invf = [1 for _ in range(maxf)]
     
    for i in range(1, maxf):
        f[i] = (i * f[i - 1]) % MOD
    invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
     
    for i in range(maxf - 1, 0, -1):
        invf[i - 1] = (i * invf[i]) % MOD
     
     
    def comb(a, b):
        return (f[a + b] * invf[a] * invf[b]) % MOD
     
     
    print(comb(a, b))

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

MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
# maxf = 2 * 10 ** 6 + 100
maxf = a + b + 10

if 2 * a + b != X or a + 2 * b != Y:
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)
Problem p02990 (python)

Fixed submission:
def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10 ** 9 + 7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

blue, red = K, N - K

p = 1 
d = 0

for i in range(1, blue + 1):
    print(int((comb(red + 1, p, mod) * comb(blue - 1, d, mod) % mod)))
    p += 1
    d += 1

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

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

MOD = 10 ** 9 + 7

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

blue, red = K, N - K

p = 1 
d = 0

for i in range(1, blue + 1):
    print(int((comb(red + 1, p) % MOD) * (comb(blue - 1, d) % MOD) % MOD))
    p += 1
    d += 1

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

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

MOD = 10 ** 9 + 7

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

blue, red = K, N - K

p = 1 
d = 0

for i in range(1, blue + 1):
    print(int((comb(red + 1, p) * comb(blue - 1, d)) % MOD))
    p += 1
    d += 1
Problem p03075 (python)

Fixed submission:
A = [int(input()) for _ in range(5)]
A.sort()

k = int(input())

if A[-1] - A[0] > k:
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.append(-maxn)
B.append(-maxn)
C.append(-maxn)

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(10 ** 7, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[k])
Problem p03209 (python)

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

a, p = [None] * (N + 1), [None] * (N + 1)
a[0], p[0] = 1, 1
for i in range(1, N + 1):
    a[i], p[i] = 2 * a[i - 1] + 3, 2 * p[i - 1] + 1


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N - 1] + 1:
        return f(N - 1, X - 1)
    else:
        return p[N - 1] + 1 + f(N - 1, X - a[N - 1] - 2)

print(f(N, X))

Buggy submission (verdict: Runtime Error):
import re

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

burger = [None] * 51
burger[0] = "P"

for i in range(1, N + 1):
    burger[i] = "B" + burger[i - 1] + "P" + burger[i - 1] + "B"
    print(burger[i])

burger_x = burger[N][:X]
ans = len(re.findall("P", burger_x))
print(ans)
Problem p03252 (python)

Fixed submission:
import string

alphabet = string.ascii_lowercase

S = str(input())
T = str(input())
start = [-1 for i in range(len(alphabet))]
goal = [-1 for i in range(len(alphabet))]
tf = True

for i in range(len(S)):
    a = alphabet.index(S[i])
    b = alphabet.index(T[i])

    if (start[a] != -1 or goal[b] != -1):
        if (start[a] != b or goal[b] != a):
            tf = False
            break
    else:
        start[a] = b
        goal[b] = a

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

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())

for i in range(int(len(S) / 2)):
    if S[i] == T[i]:
        continue
    else:
        s_before = S[i]
        S = S.replace(T[i], ',')
        S = S.replace(S[i], T[i])
        S = S.replace(',', s_before)
    if S[len(S) - i] == T[len(S) - i]:
        continue
    else:
        s_before = S[len(S) - i]
        S = S.replace(T[len(S) - i], ',')
        S = S.replace(S[len(S) - i], T[len(S) - i])
        S = S.replace(',', s_before)

if (S == T):
    print("Yes")
else:
    print("No")
Problem p03291 (python)

Fixed submission:
MOD = 1000000007

S = input()

a, ab, abc, all_s = 0, 0, 0, 1

for s in S:
    if s == "A":
        a = (a + all_s) % MOD
    elif s == "B":
        ab = (ab + a) % MOD
    elif s == "C":
        abc = (abc + ab) % MOD
    elif s == "?":
        abc = (abc * 3 + ab) % MOD
        ab = (ab * 3 + a) % MOD
        a = (a * 3 + all_s) % MOD
        all_s = (all_s * 3) % MOD

print(abc)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <string>
#define ll long long
using namespace std;

const int MOD = 1000000007;

int main() {
  string S;
  cin >> S;

  int len = S.size();
  ll a = 0, ab = 0, abc = 0, all_s = 1;

  for (int i = 0; i < len; i++) {
    if (S[i] == 'A')
      a = (a + all_s) % MOD;
    else if (S[i] == 'B')
      ab = (ab + a) % MOD;
    else if (S[i] == 'C')
      abc = (abc + ab) % MOD;
    else if (S[i] == '?') {
      abc   = (abc * 3 + ab) % MOD;
      ab    = (ab * 3 + a) % MOD;
      a     = (a * 3 + all_s) % MOD;
      all_s = (all_s * 3) % MOD;
    }
  }
  cout << abc << endl;
}
Problem p03329 (python)

Fixed submission:
def calc(x, base):
    res = 0
    while x:
        x, m = divmod(x, base)
        res += m
    return res


def main():
    N = int(input())
    ans = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
def calc(x, base):
    res = 0
    while x:
        x, m = divmod(x, base)
        res += m
    return res

ans = min(calc(i, 6) + calc(N - i, 9) for i in range(N + 1))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

MAXN = 100001
memo = [-1] * MAXN


def rec_bank(n):
    ret = n
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]

    pow6 = 1
    while(pow6 <= n):
        ret = min(ret, rec_bank(n - pow6) + 1)
        pow6 *= 6
    pow9 = 1
    while(pow9 <= n):
        ret = min(ret, rec_bank(n - pow9) + 1)
        pow9 *= 9
    memo[n] = ret
    return ret


def main():
    N = int(input())
    print(rec_bank(N))

main()
Problem p02624 (python)

Fixed submission:
n=int(input());a=0;
for i in range(n): i+=1;y=n//i;a+=y*(y+1)//2*i
print(a)

Buggy submission (verdict: Runtime Error):
n=int(open(0));print(sum(n//i*(n//i+1)*i//2for i in range(1,n+1)))
Problem p02790 (python)

Fixed submission:
a, b = map(str, input().split())
if int(a) < int(b):
    print("{}".format(a)*int(b))
else:
    print("{}".format(b)*int(a))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a < b:
    print(f"{a}"*b)
elif a >= b:
    print(f"{b}"*a)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())
if (A == 1and B == 2) or  (A == 2 and B == 1):
    print(3)
elif (A == 1 and B == 3) or (A == 3 and B == 1):
     print(2)
elif (A == 2 and B == 3) or (A == 3 and B == 2):
    print(1)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if (A == 1and B == 2) or  (A == 2 and B == 1):
    print(3)
elif (A == 1 and B == 3) or (A == 3 and B == 1):
     print(2)
elif (A == 2 and B == 3) or (A == 1 and B == 3)
    print(3)
Problem p02831 (python)

Fixed submission:
import fractions

a, b = map(int, input().split())
print(a * b // fractions.gcd(a, b))

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
print(a * b // math.gcd(a, b))

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
print(int(a * b / math.gcd(a, b)))
Problem p02862 (python)

Fixed submission:
import math
import numpy as np

def cmb(n, r, mod):
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

  A = np.array([[1, 2],[2, 1]])
  b = np.array([x, y])
  N = np.linalg.solve(A, b)
  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))
  else:
      print(0)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))

Buggy submission (verdict: Runtime Error):
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

x, y = map(int, input().split())
m  = 10**9+7
if (x+y)%3 == 0:
    left, right = [[2,1],[1,2]], [x,y]
    nl = solve(left, right)
    a, b = nl[0], nl[1]
    print(int(cmb(a+b, a))%m)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from numpy.linalg import solve
import math

x, y = map(int, input().split())
m  = 10**9+7
if (x+y)%3 == 0:
    left, right = [[2,1],[1,2]], [x,y]
    nl = solve(left, right)
    nl.sort()
    print((math.factorial(sum(nl))//(math.factorial(sum(nl)-nl[0]) * math.factorial(nl[0])))%m)
else:
    print(0)
Problem p02879 (python)

Fixed submission:
a, b = map(int, input().split())
n = a*b
if a > 9 or b > 9:
  print(-1)
else:
  print(n)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
for i in range(int(n**0.5), 0, -1):
    if n%i==0:
        j=n//i
        print(i+j-2)
        sys.exit()
Problem p02948 (python)

Fixed submission:
import heapq
n, m = map(int, input().split())
ab = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    if m >= a:
        ab[a-1].append(-b)
heap = []
ans = 0
for i in range(m):
    for j in ab[i]:
        heapq.heappush(heap, j)
    if heap:
        res = heapq.heappop(heap)
        ans += -res
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n, m = map(int, input().split())
ab = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    ab[a-1].append(-b)
heap = []
ans = 0
for i in range(m):
    for j in ab[i]:
        heapq.heappush(heap, j)
    if heap:
        res = heapq.heappop(heap)
        ans += -res
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n, m = map(int, input().split())
ab = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    ab[a-1].append(-b)
heap = []
ans = 0
for i in range(m):
    for j in ab[i]:
        heapq.heappush(heap, j)
    if heap:
        res = heapq.heappop(heap)
        ans += -res
print(ans)
Problem p02990 (python)

Fixed submission:
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

n, k = map(int, input().split())
mod = 10**9+7
for i in range(1, k+1): print(nCr(n-k+1, i, mod)*nCr(k-1, i-1, mod)%mod)

Buggy submission (verdict: Runtime Error):
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

n, k = map(int, input().split())
for i in range(1, k+1): print(nCr(n-k+1, i, mod)*nCr(k-1, i-1, mod))
Problem p03075 (python)

Fixed submission:
a = [int(input()) for _ in range(6)]
for i in range(4):
    for j in range(i+1, 5):
        if abs(a[i]-a[j]) > a[5]:
            print(":(")
            exit()
print("Yay!")

Buggy submission (verdict: Runtime Error):
a = [int(input()) for _ in range(6)]
for i in range(4):
    for j in range(i+1, 5):
        if abs(i-j) > k:
            print(":(")
            exit()
print("Yay!")
Problem p02629 (python)

Fixed submission:
n=int(input())
k=[]
def a(i):
    if i==0:
        return 26
    else:
        return i
while n>26:
    k+=[chr(96+a(n%26))]
    if n%26==0:
        n=n//26-1
    else:
        n//=26
k+=[chr(96+a(n))]
print("".join(k[::-1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
k=[]
def a(i):
    if i==0:
        return 26
    else:
        return i
while n>26:
    k+=[chr(96+a(n%26))]
    if n%26==0:
        n=n//26-1
    else:
        n//=26
k+=[chr(96+a(n))]
print(z+1,"".join(k[::-1]))
Problem p02754 (python)

Fixed submission:
n,a,b=map(int,input().split())
print(((n//(a+b))*a)+min([n%(a+b),a]))

Buggy submission (verdict: Runtime Error):
b=map(int,input().split())
print((n//(a+b))*a+min([n%(a+b),a]))
Problem p02831 (python)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
a,b=[int(i)for i in input().split()]
print(a*b//gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b=[int(i)for i in input().split()]
print(int(a*b/math.gcd(a,b)))
Problem p03208 (python)

Fixed submission:
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i+k-1])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)

Buggy submission (verdict: Runtime Error):
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i+k])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)
Problem p02759 (python)

Fixed submission:
import sys
input = sys.stdin.readline
print(-(-int(input()) // 2))

Buggy submission (verdict: Runtime Error):
-(-int(input())) // 2import sys
input = sys.stdin.readline
print(-(-int(input()) // 2))
Problem p02793 (python)

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = 1
res = 0
for x in a:
  l = x * l // gcd(x, l)
l %= mod
for x in a:
  res += l * pow(x, mod - 2, mod)
  res %= mod
print(res)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
class sieve:
  def __init__(self, n):
    self.n = n
    self.sv = [1] * (n + 1)
    self.sv[0] = 0
    self.sv[1] = 0
    for i in range(2, n + 1):
      if self.sv[i]:
        for j in range(i * 2, n + 1, i):
          self.sv[j] = 0
  def isprime(self, x):
    if x > self.n:
      return False
    return self.sv[x] == 1
  def factorize(self, x):
    res = []
    for i in range(2, self.n + 1):
      if self.sv[i]:
        while x % i == 0:
          x //= i
          res.append(i)
    if x != 1:
      res.append(x)
    return res
  def modgcd(self, a, mod):
    res = [float("inf")] * (self.n + 1)
    vis = set()
    f = self.factorize(a[0])
    for j in f:
      res[j] = f.count(j)
      vis.add(j)
    for i in range(1, len(a)):
      f = self.factorize(a[i])
      for j in vis:
        res[j] = min(f.count(j), res[j])
        vis.add(j)
    rres = 1
    for i in range(self.n + 1):
      if res[i] != float("inf"):
        rres *= pow(i, res[i], mod)
        rres %= mod
    return rres
  def modlcm(self, a, mod):
    res = [0] * (self.n + 1)
    for i in range(len(a)):
      f = self.factorize(a[i])
      for j in f:
        res[j] = max(f.count(j), res[j])
    rres = 1
    for i in range(self.n + 1):
      if res[i] != 0:
        rres *= pow(i, res[i], mod)
        rres %= mod
    return rres
sv = sieve(10 ** 3)
lcm = sv.modlcm(a, 10 ** 9 + 7)
res = 0
for x in a:
  res += lcm * pow(x, 10 ** 9 + 5, 10 ** 9 + 7)
  res %= 10 ** 9 + 7
print(res)
Problem p02834 (python)

Fixed submission:
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
N, u, v = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  e[a].append((b, 1))
  e[b].append((a, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
d = dijkstra(N, e)
p = d.path(v, 0)
pp = d.path(u, 0)
#print(p)
#print(pp)
res = 0
for i in range(1, N + 1):
  if p[i] > pp[i]: res = max(p[i], res)
print(res - 1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
N, u, v = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  e[a].append((b, 1))
  e[b].append((a, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
d = dijkstra(N, e)
p = d.path(v, 0)
pp = d.path(u, 0)
#print(p)
#print(pp)
res = 0
vis = [0] * (N + 1)
def dfs(x):
  global vis
  r = 0
  if p[x] >= pp[x]: r = p[x] - ((p[x] - pp[x]) % 2)
  if p[x] <= pp[x]: return r
  for y in e[x]:
    if vis[y[0]] == 1: continue
    vis[y[0]] = 1
    r = max(r, dfs(y[0]))
  #print(r, x)
  return r
res = dfs(u)
for x in e[u]:
  if p[x[0]] > pp[x[0]]: 
    print(res)
    exit(0)
print(1)
Problem p02862 (python)

Fixed submission:
import sys
input = sys.stdin.readline
X, Y = map(int, input().split())
mod = 10 ** 9 + 7
for t in range(X + Y + 1):
  if t == X + Y:
    print(0)
    exit(0)
  if X + Y - 2 * t == t:
    X -= t
    Y -= t
    break
if X < 0 or (Y < 0):
  print(0)
  exit(0)
class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(X + Y, mod)
#print(X, Y)
print(f.combi(X + Y, X))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
X, Y = map(int, input().split())
mod = 10 ** 9 + 7
for t in range(X + Y + 1):
  if t == X + Y:
    print(0)
    exit(0)
  if X + Y - 2 * t == t:
    X -= t
    Y -= t
    break
class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(X + Y, mod)
#print(X, Y)
print(f.combi(X + Y, X))
Problem p02897 (python)

Fixed submission:
N = int(input())
print((N - N // 2) / N)

Buggy submission (verdict: Runtime Error):
from collections import deque as dq
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
ab = []
c = []
inf = 10 ** 10
for i in range(M):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split())))
dp = [[inf] * M for _ in range(2 ** 12)]
cc = []
for i in range(M):
  temp = 0
  for k in range(ab[i][1]):
    t = 2 ** (c[i][k] - 1)
    temp = temp | t
  cc.append(temp)
def less(a, b):
  if a > b:
    return b
  else:
    return a
#print(ab, c)
Q = dq([])
Q.append((0, 0))
vis = set()
while len(Q):
  q = Q.popleft()
  i, j = q[0], q[1]
  if j >= M:
    continue
  if q in vis:
    continue
  vis.add(q)
  temp = i ^ 0
  temp2 = cc[j]
  if j > 0:
    #print(temp | temp2, j, ab[j][0])
    dp[temp | temp2][j] = less(dp[temp][j - 1] + ab[j][0], dp[temp | temp2][j])
    dp[temp][j] = less(dp[temp][j], dp[temp][j - 1])
    dp[temp2][j] = less(ab[j][0], dp[temp2][j])
    Q.append((temp | temp2, j + 1))
    Q.append((temp, j + 1))
    Q.append((temp2, j + 1))
  else:
    #print(temp | temp2, j, ab[j][0])
    dp[temp | temp2][j] = less(ab[j][0], dp[temp | temp2][j])
    Q.append((temp | temp2, j + 1))
if dp[2 ** N - 1][-1] == inf:
  print(-1)
else:
  print(dp[2 ** N - 1][-1])