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

Fixed submission:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for i in range(n)])
ans = [[-1]*3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            ans[i][j] = 0

cnt = 0
for i in range(3):
    if sum(ans[i]) == 0:
        cnt = 1
        break
    elif ans[0][i] + ans[1][i] + ans[2][i] == 0:
        cnt = 1
        break
    elif ans[0][0] + ans[1][1] + ans[2][2] == 0:
        cnt = 1
        break
    elif ans[0][2] + ans[1][1] + ans[2][0] == 0:
        cnt = 1
        break

if cnt == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for i in range(n)])
ans = [[-1]*3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            ans[i][j] = 0

for i in range(3):
    if sum(ans[i]) == 0:
        cnt = 1
        break
    elif ans[0][i] + ans[1][i] + ans[2][i] == 0:
        cnt = 1
        break
    elif ans[0][0] + ans[1][1] + ans[2][2] == 0:
        cnt = 1
        break
    elif ans[0][2] + ans[1][1] + ans[2][0] == 0:
        cnt = 1
        break

if cnt == 1:
    print('Yes')
else:
    print('No')

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


a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for i in range(n)])
ans = [[-1]*3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            ans[i][j] = 0

for i in range(3):
    if sum(ans[i]) == 0:
        cnt = 1
        break
    elif ans[0][i] + ans[1][i] + ans[2][i] == 0:
        cnt = 1
        break

if ans[0][0] + ans[1][1] + ans[2][2] == 0:
    cnt = 1
elif ans[0][2] + ans[1][1] + ans[2][0] == 0:
    cnt = 1


if cnt == 1:
    print('Yes')
else:
    print('No')
Problem p02761 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1] * n
for i in sc:
    s, c = i
    if (ans[s-1] == c) | (ans[s-1] == -1):
        ans[s-1] = c
    else:
        print(-1)
        sys.exit()

for i in range(n):
    if ans[i] == -1:
        if (i == 0) & (n != 1):
            ans[i] = 1
        else:
            ans[i] = 0

if n != 1:
    if ans[0] == 0:
        print(-1)
        sys.exit()

print(*ans, sep='')

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1] * n
for i in sc:
    s,c=sc[i]
    if (ans[s-1] == c) | (ans[s-1] == -1):
        ans[s-1] = c
    else:
        print(-1)
        sys.exit()

for i in range(n):
    if ans[i] == -1:
        if i == 0:
            ans[i] = 1
        else:
            ans[i] = 0

if n != 1:
    if ans[0] == 0:
        print(-1)
        sys.exit()

print(*ans, sep='')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

cnt = [-1] * n
ans = -1
cnt_sc = [-1] * n
for i in sc:
    cnt_sc[i[0] - 1] = 1

for i in range(n):
    if cnt_sc[i] == -1:
        if i == 0:
            sc.append([i+1, 1])
        else:
            sc.append([i+1, 0])

for i in range(1000):
    if sum(cnt) == 0:
        break
    lst = []
    tmp = i
    while i > 0:
        lst.append(i % 10)
        i //= 10
    lst.reverse()

    cnt = [-1]*m
    if len(lst) != n:
        continue
    for j in sc:
        if lst[j[0] - 1] == j[1]:
            cnt[j[0] - 1] = 0
    ans = tmp

print(ans)
Problem p02768 (python)

Fixed submission:

def bigcmb(N, R, MOD):  # nCr(mod p) #n>=10**7 #前処理不要
    if (R < 0) or (N < R):
        return 0
    R = min(R, N - R)
    fact, inv = 1, 1
    for i in range(1, R + 1):
        fact = (fact * (N - i + 1)) % MOD
        inv = (inv * i) % MOD
    return fact * pow(inv, MOD - 2, MOD) % MOD


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

exc = bigcmb(n, a, mod) + bigcmb(n, b, mod)
print((pow(2, n, mod) - exc - 1) % mod)

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

cnt=1
for i in range(1,n + 1):
    cnt*=i
    if i == a:
        af = cnt
    elif i == n-a:
        anf = cnt
    elif i == b:
        bf = cnt
    elif i == n-b:
        bnf = cnt
    elif i == n:
        nf=cnt
        break

ans = 2 ** n - (nf//af//anf) - (nf//bf//bnf)-1
print(int(ans % (10**9+7)))

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

cnt=1
for i in range(n + 1):
    cnt*=i
    if i == a:
        af = cnt
    elif i == n-a:
        anf = cnt
    elif i == b:
        bf = cnt
    elif i == n-b:
        bnf = cnt
    elif i == n:
        nf=cnt
        break

ans = 2 ** n - (nf//af//anf) - (nf//bf//bnf)-1
print(int(ans % (10**9+7)))
Problem p02788 (python)

Fixed submission:
from math import ceil

def binary(N,LIST,num):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if LIST[(l + r) // 2] > num:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r + 1


n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [i for i, j in xh]
h = [j for i, j in xh]

bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i, xi in enumerate(x):
    j = binary(n, x, xi + 2 * d) - 1
    bsum[i] += bsum[i - 1] + bomb[i]
    bnum = max(ceil(h[i] / a - bsum[i]), 0)
    bomb[i] += bnum
    bomb[j] -= bnum
    bsum[i] += bnum
    ans += bnum
print(ans)

Buggy submission (verdict: Runtime Error):
def binary(N, LIST, num):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if LIST[(l + r) // 2] > num:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r + 1


n, d, a = map(int, input().split())
xh = sorted(map(int, input().split()) for _ in range(n))
x = [i for i, j in xh]
h = [(j + a - 1) // a for i, j in xh]

bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i in range(n):
    j = binary(n, x, x[i] + 2 * d) - 1
    bnum = max(h[i] - (bsum[i - 1] + bomb[i]), 0)
    bomb[i] += bnum
    bomb[j] -= bnum
    bsum[i] += bsum[i - 1] + bomb[i]
    ans += bnum
print(ans)
Problem p02796 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
xl2 = sorted([[x + l, x - l] for x, l in xl])

ans = 0
mr = xl2[0][1]
for r, l in xl2:
    if l >= mr:
        ans += 1
        mr = r
print(ans)

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

n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]

xl.sort(key=lambda x:x[1])

cnt = [None]*(10**9)
ans = [0 for _ in range(n)]

for i in range(n):
    for j in range(xl[i][0] - xl[i][1] + 1, xl[i][0] + xl[i][1]):
        if cnt[j] == None:
            cnt[j] = 1
        else:
            break
        if j == xl[i][0] + xl[i][1]-1:
            ans[i] = 1

print(sum(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]

xl.sort(key=lambda x:x[1])

cnt = [0 for _ in range(10**7)]
ans = [0 for _ in range(n)]

for i in range(n):
    for j in range(xl[i][0] - xl[i][1] + 1, xl[i][0] + xl[i][1]):
        if cnt[j] == 0:
            cnt[j] = 1
        else:
            break
        if j == xl[i][0] + xl[i][1]-1:
            ans[i] = 1

print(sum(ans))
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
if k * 500 >= x:
    print('Yes')
else:
    print('No')

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

a.sort(reverse=True)
ans = [i for i in range(max(a)//2,(m + 1)//2)]

for j in a:
    if a % 2 == 1:
        break
    n_ans = []
    for i in ans:
        if ((i / j - 0.5) % 1 == 0):
            n_ans.append(i)
    ans = n_ans[:]

print(len(ans))

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

a.sort(reverse=True)
ans = [i for i in range(max(a)//2, m + 1)]

for j in a:
    n_ans = []
    for i in ans:
        if ((i / j - 0.5) % 1 == 0):
            n_ans.append(i)
    ans = n_ans[:]

print(len(ans))
Problem p02812 (python)

Fixed submission:
n = int(input())
s = list(str(input()))
ans=0
for i in range(len(s) - 2):
    if s[i] == 'A':
        if s[i + 1] == 'B':
            if s[i + 2] == 'C':
                ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(str(input()))
ans=0
for i in range(len(s) - 3):
    if list[i] = 'A':
        if list[i + 1] = 'B':
            if list[i + 2] = 'C':
                ans+=1
print(ans)
Problem p02814 (python)

Fixed submission:
from fractions import gcd
import sys

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]

cnt = 1
min_a = min(a)
while min_a % 2 == 0:
    cnt *= 2
    min_a = min_a // 2

ans = 1
for i in a:
    if (i // cnt) % 2 == 0:
        print(0)
        sys.exit()
    ans = (ans * i) // gcd(ans, i)

print((m//ans+1)//2)

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

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]

cnt = 1
min_a = min(a)
while min_a % 2 == 0:
    cnt *= 2
    min_a = min_a // 2

ans = 1
for i in a:
    if (i // cnt) % 2 == 0:
        print(0)
        sys.exit()
    ans = (ans * i) // gcd(ans, i)

print((m//ans+1)//2)

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

a.sort(reverse=True)
ans = [i for i in range(max(a)//2,(m + 1)//2)]

for j in a:
    if a % 2 == 1:
        break
    n_ans = []
    for i in ans:
        if ((i / j - 0.5) % 1 == 0):
            n_ans.append(i)
    ans = n_ans[:]

print(len(ans))
Problem p02882 (python)

Fixed submission:
import math

a, b, x = map(int, input().split())
if a * a * b / 2 <= x:
    tan = 2 * (a * a * b - x) / a ** 3
    print(math.degrees(math.atan(tan)))
else:
    tan = a * b * b / 2 / x
    print(math.degrees(math.atan(tan)))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())

lim = math.degrees(math.atan(b/a))
tan = a ** 3 / 2 / (a * a * b - x)
ans = 90-math.degrees(math.atan(tan))
if ans <= lim:
    print(ans)
else:
    tan = a * b * b / 2 / x
    print(math.degrees(math.atan(tan)))
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    x[a[i]-1]=i+1
print(*x)
Problem p02934 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
for i in range(0,N):
	a[i]=1/a[i]
print(1/sum(a))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(1/int,input().split()))
print(1/sum(a))

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

print(1/sum(a))
Problem p02946 (python)

Fixed submission:
a,b= map(int,input().split())
for i in range(-a+1,a):
    print(b+i, end=" ")
print()

Buggy submission (verdict: Runtime Error):
a,b= map(int,input().split())
for i in range(-a+1,a);
    print(b+a)
Problem p02947 (python)

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
dict={}
for i in s:
    if i in dict:
        ans+=dict[i]
        dict[i]+=1
    else:
        dict[i]=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
dict={}
for i in s:
    if i in dict:
        ans+=dict[s]
        dict[s]+=1
    else:
        dict[s]=1
print(ans)
Problem p02952 (python)

Fixed submission:
n=int(input())
ans=min(n,9)
if n>99: ans=min(n-90,909)
if n>9999: ans=n-9000-90
if n>99999: ans=90909
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
odd=[i for i in range(1,n+1) if len(str(i))%==1]
print(len(odd))

Buggy submission (verdict: Runtime Error):
n=str(input())
ans=0
ans+=n%10
ans+=n%1000+1
ans+=n%100000+1
print(ans)

Buggy submission (verdict: Runtime Error):
n=str(input())
ans=0
ans+=n%10
ans+=n%1000+1
ans+=n%100000+1
Problem p02972 (python)

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

b = [-1] * n
for i in range(n, 0, -1):
    cnt = sum(b[j - 1] for j in range(i + i, n + 1, i))
    b[i - 1] = int(a[i - 1] != cnt % 2)

print(sum(b))
if sum(b) > 0:
    print(*[i + 1 for i in range(n) if b[i] == 1])

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

with open('testcase_12.in') as f:
    n = int(f.readline())
    a = list(map(int, f.readline().split()))

b = [-1] * n
for i in range(n, 0, -1):
    cnt = sum(b[j - 1] for j in range(i + i, n + 1, i))
    b[i - 1] = int(a[i - 1] != cnt % 2)

print(sum(b))
if sum(b) > 0:
    print(*[i + 1 for i in range(n) if b[i] == 1])
Problem p02973 (python)

Fixed submission:
from bisect import bisect

n = int(input())
ma = [-int(input()) for _ in range(n)]

ans = [ma[0]]
for ai in ma[1:]:
    tmp = bisect(ans, ai)
    if tmp == len(ans):
        ans.append(ai)
    elif tmp < len(ans):
        ans[tmp] = ai
print(len(ans))

Buggy submission (verdict: Runtime Error):
from bisect import bisect

n = int(input())
ma = [-int(input()) for _ in range(n)]

ans = [ma[0]]
for ai in ma[1:]:
    tmp = bisect(ans, ai)
    if tmp == len(ans):
        ans.append(ai)
    elif tmp < len(ans):
        ans[tmp] = ai
    print(ans)
print(len(ans))
Problem p02982 (python)

Fixed submission:
import numpy

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i + 1, n):
        a = numpy.array(x[i])
        b = numpy.array(x[j])
        num=numpy.linalg.norm(a-b)
        if num.is_integer() == True:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i + 1, n):
        a = numpy.array(x[i])
        b = numpy.array(x[j])
        num=numpy.linalg.norm(a-b)
        if num.is_integer() == True:
            cnt += 1
print(cnt)
Problem p02995 (python)

Fixed submission:
import fractions


def lcm(x, y):  # 最小公倍数
    return (x * y) // fractions.gcd(x, y)


a, b, c, d = map(int, input().split())
all = b - (b // c + b // d - b // lcm(c, d))
part = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d))


print(all - part)

Buggy submission (verdict: Runtime Error):
import math


def lcm(x, y):  # 最小公倍数
    return (x * y) // math.gcd(x, y)


a, b, c, d = map(int, input().split())
all = b - (b // c + b // d - b // lcm(c, d))
part = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d))


print(all - part)
Problem p03006 (python)

Fixed submission:
from collections import defaultdict

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
for xi, yi in xy:
    for xj, yj in xy:
        cnt[(xi - xj, yi - yj)] += 1
cnt[(0, 0)] = 0
ans = n - max(cnt.values())
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
for i, (xi, yi) in enumerate(xy):
    for xj, yj in xy[i + 1:]:
        cnt[(xi - xj, yi - yj)] += 1
ans = n - max(cnt.values())
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
for xi,yi in xy:
    for xj, yj in xy:
        cnt[(xi - xj, yi - yj)] += 1
cnt.pop((0, 0))
ans = n - max(cnt.values())
print(ans)
Problem p03031 (python)

Fixed submission:
from itertools import product

n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

cnt = 0
for pat in product([0, 1], repeat=n):
    for i in range(m):
        if sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0])) % 2 != p[i]:
            break
    else:
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

cnt = 0
for pat in product([0, 1], repeat=n):
    for ksi, pi in zip(ks, pi):
        tmp = sum(pat[ksij - 1] for ksij in ksi[1:])
        if  tmp % 2 != pi:
            break
    else:
        cnt += 1
print(cnt)
Problem p03050 (python)

Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n ** 0.5) + 1):
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)

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

ans = 0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0 and n // (i - 1) == n % (i - 1):
        ans += i - 1
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)

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

ans = 0
for i in range(1, int(n ** 0.5) + 1):
    m = n // i - 1
    if n % i == 0 and n // m == n % m:
        ans += m
print(ans)
Problem p03147 (python)

Fixed submission:
#import cython

n = int(input())
h = list(map(int, input().split())) + [0]

ans,cnt = 0, sum(h)
while cnt > 0:
    l, r = -1, n
    for num, i in enumerate(h):
        if (l == -1) and (i > 0):
            l = num
        if (l > -1) and (i == 0):
            r = num
            ans += 1
            cnt -= r - l
            for i in range(l, r):
                h[i] -= 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import cython

n = int(input())
h = list(map(int, input().split())) + [0]

ans,cnt = 0, sum(h)
while cnt > 0:
    l, r = -1, n
    for num, i in enumerate(h):
        if (l == -1) and (i > 0):
            l = num
        if (l > -1) and (i == 0):
            r = num
            ans += 1
            cnt -= r - l
            for i in range(l, r):
                h[i] -= 1
            break
print(ans)
Problem p03161 (python)

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

cnt = [0]*n
for i in range(1, n):
    j = max(0,i-k)
    cnt[i] = min(abs(h[m]-h[i])+cnt[m] for m in range(j,i))
print(cnt[n-1])

Buggy submission (verdict: Runtime Error):
@pypy
n,k = map(int,input().split())
h = list(map(int, input().split()))

cnt = [0]*n
for i in range(1, n):
    cnt[i] = min(abs(h[m]-h[i])+cnt[m] for m in range(max(0, i-k), i))
print(cnt[n-1])
Problem p03166 (python)

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


def longdist(p, dp_l, out_l):
    if len(out_l[p]) == 0:
        return 0
    for q in out_l[p]:
        if dp_l[q] == -1:
            dp_l[q] = longdist(q, dp_l, out_l)
        dp_l[p] = max(dp_l[p], dp_l[q]+1)
    return dp_l[p]


n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

input, output = [[] for _ in range(n)], [[] for _ in range(n)]
for x, y in xy:
    input[y - 1].append(x - 1)
    output[x - 1].append(y - 1)

dp = [-1] * n
for i in range(n):
    if dp[i] == -1:
        dp[i] = longdist(i, dp, output)

print(max(dp))

Buggy submission (verdict: Runtime Error):
def longdist(p, dp_l, out_l):
    if len(out_l[p]) == 0:
        return 0
    for q in out_l[p]:
        if dp_l[q] == -1:
            dp_l[q] = longdist(q, dp_l, out_l)
        dp_l[p] = max(dp_l[p], dp_l[q]+1)
    return dp_l[p]

n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

input, output = [[] for _ in range(n)], [[] for _ in range(n)]
for x, y in xy:
    input[y - 1].append(x - 1)
    output[x - 1].append(y - 1)

dp = [-1] * n
for i in range(n):
    if dp[i] == -1:
        dp[i] = longdist(i, dp, output)

print(max(dp))

Buggy submission (verdict: Runtime Error):
def longdist(p, dp_l, out_l):
    if len(out_l[p]) == 0:
        return 0
    for q in out_l[p]:
        if dp_l[q] == -1:
            dp_l[q] = longdist(q, dp_l, out_l)
        dp_l[p] = max(dp_l[p], dp_l[q]+1)
    return dp_l[p]

n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

input, output = [[] for _ in range(n)], [[] for _ in range(n)]
for x, y in xy:
    input[y - 1].append(x - 1)
    output[x - 1].append(y - 1)

dp = [-1] * n
for i in range(n):
    if dp[i] == -1:
        dp[i] = longdist(i, dp, output)

print(max(dp))
Problem p03172 (python)

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

cs_a, cnt = [0] * n, 0
for i in range(n):
    cnt += a[i]
    cs_a[i] = cnt
dp = [[0] * (k + 1) for i in range(n + 1)]

for i in range(n + 1):
    for j in range(k + 1):
        if j == 0:
            dp[i][j] = 1
        elif (i == 0) or (j > cs_a[i - 1]):
            dp[i][j] = 0
        elif j == 1:
            dp[i][j] = dp[i - 1][j] + min(a[i - 1], 1)
        elif j - a[i - 1] - 1 < 0:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
        else:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - a[i - 1] - 1]
        dp[i][j] %= 10 ** 9 + 7

print(dp[n][k])

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

n, k = map(int, input().split())
a = list(map(int, input().split()))
cs_a = list(np.cumsum(a)) #累積和

dp = [[0] * (n + 1) for i in range(k + 1)]

for i in range(k + 1):
    for j in range(1, n + 1):
        if i > cs_a[j - 1]:
            dp[i][j] = 0
        elif i == 0:
            dp[i][j] = 1
        elif i == 1:
            dp[i][j] = dp[i][j - 1] + min(1, a[j - 1])
        else:
            dp[i][j] = sum(dp[i - x][j - 1] for x in range(a[j - 1] + 1))
            
print(dp[k][n] % (10 ** 9 + 7))
Problem p03174 (python)

Fixed submission:
mod = 10**9+7
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
dp = [0]*(1 << n)
dp[0] = 1
for i in range(1, 1 << n):
    k = bin(i).count("1")
    for j in range(n):
        if i >> j & 1 and a[k-1][j]:
            dp[i] += dp[i ^ (1 << j)]
    dp[i] %= mod
print(dp[(1 << n)-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

bitcount = [0]
for _ in range(n):
    bitcount += [i+1 for i in bitcount]

# 配るDP
for bit in range((1 << n) - 1):
    i = bitcount(bit)
    for j in range(n):
        if a[i][j] and ((bit >> j) & 1 ^ 1):
            newbit = bit | (1 << j)
            dp[newbit] += dp[bit]
            dp[newbit] %= mod
print(dp[(1 << n) - 1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

for bit in range((1 << n) - 1):
    i = bin(bit).count('1')
    for j in range(n):
        if a[i][j] and (bit >> j) & 1:
            newbit = bit | (1 << j)
            dp[newbit] += dp[bit]
    		dp[newbit] %= mod
print(dp[(1 << n) - 1])