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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(0,n,2):
  if a[i]%2==1:
    count+=1
  else:
    continue
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(0,n+1,2):
  if a[i]%2==1:
    count+=1
  else:
    continue
print(count)
Problem p02612 (python)

Fixed submission:
n = int(input())
x = (n//1000) + 1
if n%1000==0:
  print(0)
else:
  print(x*1000-n)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = (n//1000) + 1
if n%1000=0:
  print(0)
else:
  print(x*1000-n)
Problem p02640 (python)

Fixed submission:
x,y = map(int,input().split())
if y>=2*x and y<=4*x and y%2==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
crain = (4 * x - y) / 2
if y>=2x and y<=4x and y%2==0:
    print("Yes")
else:
    print("No")
Problem p02705 (python)

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

Buggy submission (verdict: Runtime Error):
r = int(input())
print(2*r*pi)
Problem p02760 (python)

Fixed submission:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
mark = [[False, False, False] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:mark[i][j] = True

ans = 'No'
for i in range(3):
    if all(mark[i]):
        ans = 'Yes'
        break      
for j in range(3):
    if mark[0][j] and mark[1][j] and mark[2][j]:
        ans = 'Yes'
        break
if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[0][2] and mark[1][1] and mark[2][0]): ans = 'Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
for _ in range(3):
  A = list(map(int, input().split())) 
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

Buggy submission (verdict: Runtime Error):
for _ in range(3):
  A = list(map(int, input().split())) 
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

Buggy submission (verdict: Runtime Error):
for _ in range(3):
  A = list(map(int, input().split())) 
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')
Problem p02949 (python)

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*
m=csr_matrix
n,_,p,*t=map(int,open(0).read().split())
s=[n+1]*2
r,c,d=t[::3],t[1::3],[p-c for c in t[2::3]]
u=set(csgraph.depth_first_order(m((d,(r,c)),s),1,1,0))
v=set(csgraph.depth_first_order(m((d,(c,r)),s),n,1,0))
u&=v
E=[(r,c,d)for r,c,d in zip(r,c,d)if r in u and c in u]
D=[10**9]*(n+1)
D[1]=0
for _ in'_'*n:
	for a,b,c in E:D[b]=min(D[b],D[a]+c)
ans=D[n]
for a,b,c in E:
	if D[b]>D[a]+c:
		print(-1)
		exit()
print(max(-ans,0))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix, csgraph
dfs = csgraph.depth_first_order
n, m, p, *t = map(int, open(0).read().split())
row = np.int64([a-1 for a in t[::3]])
col = np.int64([b-1 for b in t[1::3]])
data = np.int64([p-c for c in t[2::3]])
graph = csr_matrix((data, (row, col)), (n, n))
rev = csr_matrix((data, (col, row)), (n, n))
use = set(dfs(graph, 0, True, False)) & set(dfs(rev, n-1, True, False))
flag = np.array([ r in use and c in use for r, c in zip(row, col)], '?')
g = csr_matrix((data[flag], (row[flag], col[flag])), (n, n))
try:
    print(max(0, int(-csgraph.bellman_ford(g, True, (0,))[n-1])))
except csgraph._shortest_path.NegativeCycleError:
    print(-1)

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*
N,M,P,*E=map(int,open(0).read().split())
D=csgraph.bellman_ford(csr_matrix(([P-c for c in E[5::3]],(E[3::3],E[4::3])),[N+1]*2),1,1)[N]
print(int([max(-D,0),-1][D>9e9]))
Problem p03039 (python)

Fixed submission:
N,M,K=map(int,input().split())
O,S,T=10**9+7,N+M,6
for i in range(K):S=S*(N*M-i)%O;T=T*-~i%O
print(S*K*~-K*pow(T,O-2,O)%O)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
O=10**9+7
f=lambda n:1if n<1else n*f(n-1)%O;
print(f(N*M-2)*pow(6*f(N*M-K)*f(K-2),O-2,O)*N*M*(N*M-1)*(N+M)%O)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
O=10**9+7
f=lambda n:1if n<1else n*f(n-1)%O;
print(f(N*M-2)*pow(6*f(N*M-K)*f(K-2),O-2,O)*N*M*(N*M-1)*(N+M)%O)
Problem p03040 (python)

Fixed submission:
from heapq import*
L,R=[],[]
B=0
Q,*E=open(0)
for e in E:
    if e[0]>'1':
        w=-L[0]
        print(w,B+w*(len(L)>len(R)))
    else:
        _,a,b=map(int,e.split())
        B+=b
        if len(L)>len(R):
            B-=a
            a=-heappushpop(L,-a)
            B+=a+a
            heappush(R,a)
        else:
            B+=a
            a=heappushpop(R,a)
            B-=a+a
            heappush(L,-a)

Buggy submission (verdict: Runtime Error):
from heapq import*
L,R=[]*2
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t=1-t;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)
Problem p03082 (python)

Fixed submission:
N,X,*S=map(int,open(0).read().split())
e=enumerate
d=range(X+1)
for i,s in e(sorted(S)):d=[(t*i+d[j%s])%(10**9+7)for j,t in e(d)]
print(d[-1])

Buggy submission (verdict: Runtime Error):
N,X,*S=map(int,open(0).read().split())
e=enumerate
d=range(X+1)
for i,s in e(sorted(S)):d=[(t*i+x[j%s])%(10**9+7)for j,t in e(d)]
print(d[-1])
Problem p03088 (python)

Fixed submission:
a=b=c=d=e=f=0;g=1;exec('a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,g*4-b-c-d-a*3;'*input());print g%(10**9+7)

Buggy submission (verdict: Runtime Error):
a=b=c=d=e=f=0;g=1;exec('a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,g*4-b-c-d-a*3;'*input());print g%=10**9+7
Problem p03109 (python)

Fixed submission:
_,b,_=input().split('/')
print("Heisei"if int(b)<5 else"TBD")

Buggy submission (verdict: Runtime Error):
_,b,_=input().split('/')
print("Heisei"if b<5 else"TBD")
Problem p03126 (python)

Fixed submission:
n,m=map(int,input().split())
a=[]
for _ in range(n):
  _,*b=map(int,input().split())
  a+=b
print(sum(n==a.count(i+1)for i in range(m)))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for _ in range(n):
  _,*b=map(int,input().split())
  a+=b
print(sum(n==a.count i+1for i in range(m)))
Problem p03146 (python)

Fixed submission:
s=int(input())
i=2
while s>1:s=[s//2,s*3+1][s%2];i+=1
print(max(i,4))

Buggy submission (verdict: Runtime Error):
s=int(input())
i=4
while s>4or3==s:s=[s//2,s*3+1][s%2];i+=1
print(i)
Problem p03177 (python)

Fixed submission:
from numpy import*
M=10**9+7
m=lambda:map(int,input().split())
n,k=m()
a=matrix([list(m())for i in[0]*n],'O')
b=eye(n,n,0,'O')
while k:b=[b,b*a][k&1];a=a*a%M;k>>=1
print(sum(b)%M)

Buggy submission (verdict: Runtime Error):
from numpy import*
M=10**9+7
f=lambda*s:[*map(int,input().split())]
n,k=f()
a=matrix([*map(f,[0]*n)])
b=eye(n,dtype=int)
while k:
 if k&1:b=b*a%M
 a=a*a%M;k>>=1
print(sum(b)%M)
Problem p03223 (python)

Fixed submission:
N,*a=map(int,open(0))
n=N//2-1
a.sort()
print(2*sum(a[n+2:])-2*sum(a[:n])+a[n+1]-a[n]-N%2*min(a[~n]+a[n],2*a[n+1]))

Buggy submission (verdict: Runtime Error):
N,*a=map(int,open(0))
n=N//2
a.sort()
print(2*sum(a[n+2:])-2*sum(a[:n])+a[n+1]-a[n]-N%2*min(a[~n]+a[n],2*a[n+1]))
Problem p03245 (python)

Fixed submission:
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if(abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2:
    print(-1)
    exit()
D=[]
for i in reversed(range(33)):D.append(1<<i)
D+=[1,1]
if(abs(x[0])+abs(y[0]))%2==0:D.append(1)
print(len(D))
print(*D)
for i in range(n):
  X,Y=x[i],y[i]
  s=''
  for d in D:
    if abs(X)>abs(Y):
      if X>0:
        X-=d
        s+='R'
      else:
        X+=d
        s+='L'
    else:
      if Y>0:
        Y-=d
        s+='U'
      else:
        Y+=d
        s+='D'
  print(s)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if(abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2:
    print(-1)
    exit()
d=[]
for i in reversed(range(33)):d.append(1<<i)
d+=[1,1]
if(abs(x[0])+abs(y[0]))%2==0:d.append(1)
print(len(d))
print(*d)
for i in range(n):
  X,Y=x[i],y[i]
  s=''
  for d in d:
    if abs(X)>abs(Y):
      if X>0:
        X-=d
        s+='R'
      else:
        X+=d
        s+='L'
    else:
      if Y>0:
        Y-=d
        s+='U'
      else:
        Y+=d
        s+='D'
  print(s)
Problem p03285 (python)

Fixed submission:
n=int(input());
f=0;
while n>=0:
  if n%7<1:f+=1;
  n-=4;
print("Yes"if f>0 else"No")

Buggy submission (verdict: Runtime Error):
n=int(input());
f=0;
while n>=0:
  if n%7<1:f+=1;
  n-=4;
print(["No","Yes"][f])
Problem p03292 (python)

Fixed submission:
a=list(map(int,input().split()));print(max(a)-min(a))

Buggy submission (verdict: Runtime Error):
a=map(int,input().split());
print(max(a)-min(a))
Problem p03324 (python)

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

Buggy submission (verdict: Runtime Error):
eval"A,B="+gets.split*?,;p (B+B/100)*100**A
Problem p03337 (python)

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

Buggy submission (verdict: Runtime Error):
a,b=max(int,input().split());print(max(a+b,a-b,a*b))
Problem p03354 (python)

Fixed submission:
n,m=map(int,input().split())
p=list(map(int,input().split()))
pa=list(range(n))
def find(u):
  if u!=pa[u]:pa[u]=find(pa[u])
  return pa[u]
for i in range(m):
  a,b=map(int,input().split())
  a=find(a-1)
  b=find(b-1)
  if a!=b:pa[a]=b
c=0
for i in range(n):
  if find(p[i]-1)==find(i):c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=list(map(int,input().split()))
pa=list(range(n))
def find(u):
  if u!=pa[u]:pa[u]=find(pa[u])
  return pa[u]
for i in range(m):
  a,b=map(int,input().split())
  a=find(a-1)
  b=find(b-1)
  if a!=b:pa[a]=b
c=0
for i in range(n):
  if find(p[i])==find(i):c+=1
print(c)
Problem p03377 (python)

Fixed submission:
a,b,c=map(int,input().split());print(['YES','NO'][a>c or c>a+b])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(['YES','NO'][a>c||c>a+b])
Problem p03385 (python)

Fixed submission:
a=input()
print('Yes'if a[0]!=a[1]and a[0]!=a[2]and a[1]!=a[2]else'No')

Buggy submission (verdict: Runtime Error):
a=input()
print('Yes'if a[0]!=a[1]and a[0]!=a[2]and a[1]!=a[2]else'No)
Problem p03424 (python)

Fixed submission:
input();print("Four"if len(set(input().split()))>3 else"Three")

Buggy submission (verdict: Runtime Error):
input();print("Four"if len(Set(input().split()))>3 else"Three")
Problem p03471 (python)

Fixed submission:
n,y=map(int,input().split())
for a in range(n+1):
  for b in range(9):
    c=n-a-b
    if c>=0 and a*10000+b*5000+c*1000==y:
      print(a,b,c)
      exit()
print(-1,-1,-1)

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
for a in range(n+1):
  for b in range(9):
    c=n-a-b
    if c>=0 and a*10000+b*5000+c*1000=y:
      print(a,b,c)
      exit()
print(-1,-1,-1)
Problem p03473 (python)

Fixed submission:
print(48-int(input()))

Buggy submission (verdict: Runtime Error):
print(48-input())
Problem p03608 (python)

Fixed submission:
import sys,itertools as o,scipy.sparse as s;_,r,*t=[map(int,i.split())for i in sys.stdin];a,b,c=zip(*t);l=s.csgraph.dijkstra(s.csr_matrix((c,(a,b)),[201]*2),0);print(min(sum(int(l[i][j])for i,j in zip(a,a[1:]))for a in o.permutations(r)))

Buggy submission (verdict: Runtime Error):
import sys,itertools as o,scipy.sparse as s;_,r,*t=[map(int,i.split())for i in sys.stdin];a,b,c=zip(*t);l=s.csgraph.dijkstra(s.csr_matrix((c,(a,b)),[201]*2),0);print min(sum(int(l[i][j])for i,j in zip(a,a[1:]))for a in o.permutations(r))
Problem p03624 (python)

Fixed submission:
s=input()
a='None'
for c in 'abcdefghijklmnopqrstuvwxyz':
    f=0
    for t in s:f|=c==t
    if not f:a=c;break
print(a)

Buggy submission (verdict: Runtime Error):
<?php
	$s=fgets(STDIN);
	$a="None";
	for($c='a';$c<='z'&&strlen($c)==1;$c++){
		$f=0;
		for($i=0;$i<strlen($s);$i++)$f|=$s[$i]==$c;
		if(!$f){
			$a=$c;
			break;
		}
	}
	echo $a;
Problem p03662 (python)

Fixed submission:
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());n,=f();a,b=zip(*map(f,[0]*~-n));g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,(a,b)),[n+1]*2),0,[1,n]);print'FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2>=n::2]

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*
f=lambda*z:list(map(int,input().split()))
n,=f()
c=[1]*~-n
print('FSennunkeec'[sum(g>h for g,h in zip(*csgraph.dijkstra(csr_matrix((c,zip(*map(f,c))),[n+1]*2),0,[1,n])))*2>=n::2])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,zip(*map(f,[0]*~-n))),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2>=n::2])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,zip(*map(f,[0]*~-n))),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2/n::2])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();a,b=zip(*map(f,[0]*~-n));g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,(a,b)),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2/n::2])
Problem p03729 (python)

Fixed submission:
a,b,c=input().split()
print("YES" if a[-1]==b[0] and b[-1]==c[0] else "NO")

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
print("YES" if a[-1]==b[0]&&b[-1]==c[0] else "NO")
Problem p03814 (python)

Fixed submission:
s=input()
a=-1
z=0
for i in range(len(s)):
  if a<0 and s[i]=='A':a=i
  if s[i]=='Z':z=i
print(z-a+1)

Buggy submission (verdict: Runtime Error):
s=input()
a=-1
z=0
for i in range(s.len()):
  if a<0 and s[i]=='A':a=i
  if s[i]=='Z':z=i
print(z-a+1)
Problem p03853 (python)

Fixed submission:
a,b=input().split();
for _ in[0]*int(a):print((input()+"\n")*2)

Buggy submission (verdict: Runtime Error):
a,b=input().split();for _ in[0]*int(a):print(input()*2)
Problem p03963 (python)

Fixed submission:
n,k=map(int,input().split());print(k*(k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
<?php fscanf(STDIN,"%d%d",$n,$k);echo $k*($k-1)**~-$n;
Problem p04002 (python)

Fixed submission:
f=lambda:map(int,input().split())
h,w,n=f()
c=[0]*10
c[0]=(h-2)*(w-2)
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=x+i%3>2<y+i//3<=w:d[a]=d.get(a,0)+1;c[d[a]-1]-=1;c[d[a]]+=1
print(*c)

Buggy submission (verdict: Runtime Error):
f=lambda:map(int,input().split())
h,w,n=f()
c=[(h-2)*(w-2),*[0]*9]
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=x+i%3>2<y+i//3<=w:d[a]=d.get(a,0)+1;c[d[a]-1]-=1;c[d[a]]+=1
print(*c)
Problem p04012 (python)

Fixed submission:
s=input();c=[0]*26;f=0
for i in s:c[ord(i)-97]+=1
for i in c:f+=i%2
print("YNeos"[(f>0)::2])

Buggy submission (verdict: Runtime Error):
s=input();c=[f=0]*26
for i in s:c[ord(i)-97]+=1
for i in c:f+=i%2
print("YNeos"[(f>0)::2])

Buggy submission (verdict: Runtime Error):
s=input();c=[f=0]*26
for i in s:c[ord(i)-97]+=1
for i in c:f+=i%2
print("YNeos"[!!f::2])
Problem p02534 (python)

Fixed submission:
k=int(input())
print("ACL" * k)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
A = [i for i in range(a, b + 1)]
B = [i for i in range(c, d + 1)]
for i in A:
    if i in B:
        a = True
        break
if a == True:
    print("Yes")
else:
    print("No")
Problem p02586 (python)

Fixed submission:
import sys

R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            here = dp[k][i][j]
            if i + 1 <= R:
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
            if j + 1 <= C:
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)

Buggy submission (verdict: Runtime Error):
r,c,k = map(int,input().split())
dp = [[[0 for _ in range(4)] for _ in range(c+1)] for _ in range(r+1)]
g = [[0]*(c+1) for _ in range(r+1)]
for _ in range(k):
    a,b,v = map(int,input().split())
    g[a][b] = v

for i in range(r+1):
    for j in range(c+1):
        for m in range(4):
            here = dp[i][j][k]
            if i + 1 <= r:
                dp[i + 1][j][0] = max(dp[i + 1][j][0], here)
                dp[i + 1][j][1] = max(dp[i + 1][j][1], here + g[i + 1][j])
            if j + 1 <= c:
                dp[i][j + 1][k] = max(dp[i][j + 1][k], here)
                if k < 3:
                    dp[i][j + 1][k+1] = max(dp[i][j + 1][k+1], here + g[i][j + 1])
# ans = 0
            # tmp  =dp[i][j][m]
            # if i+1<=r:
            #     dp[i+1][j][0] = max(tmp,dp[i+1][j][0])
            #     dp[i+1][j][1] = max(dp[i+1][j][1],tmp + g[i+1][j])
            # if j+1<=c:
            #     dp[i][j+1][m] = max(dp[i][j+1][m],tmp)
            #     if m<3:
            #         dp[i][j+1][m+1] = max(dp[i][j+1][m+1],tmp + g[i][j+1]) 
print(max(dp[-1][-1]))

Buggy submission (verdict: Runtime Error):
r,c,k = map(int,input().split())
dp = [[[0 for _ in range(4)] for _ in range(c+1)] for _ in range(r+1)]
g = [[0]*(c+1) for _ in range(r+1)]
for _ in range(k):
    a,b,v = map(int,input().split())
    g[a][b] = v

for i in range(r+1):
    for j in range(c+1):
        for m in range(4):
            here = dp[k][i][j]
            if i + 1 <= r:
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + g[i + 1][j])
            if j + 1 <= c:
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + g[i][j + 1])
# ans = 0
            # tmp  =dp[i][j][m]
            # if i+1<=r:
            #     dp[i+1][j][0] = max(tmp,dp[i+1][j][0])
            #     dp[i+1][j][1] = max(dp[i+1][j][1],tmp + g[i+1][j])
            # if j+1<=c:
            #     dp[i][j+1][m] = max(dp[i][j+1][m],tmp)
            #     if m<3:
            #         dp[i][j+1][m+1] = max(dp[i][j+1][m+1],tmp + g[i][j+1]) 
print(max(dp[-1][-1]))
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
original_pop_count = x.count('1')
one_pop_count = original_pop_count-1
zero_pop_count = original_pop_count+1

one_mod = 0
zero_mod= 0
for b in x:
    if one_pop_count!=0:
        one_mod=(one_mod*2+int(b))%one_pop_count
    zero_mod=(zero_mod*2+int(b))%zero_pop_count
#予めf[i]を計算する
f = [0]*220000
pop_count = [0]*220000
for i in range(1,220000):
    pop_count[i]= pop_count[i//2] + i%2
    f[i] = f[i%pop_count[i]]+1
one_pow2 = [1]*220000
zero_pow2 = [1]*220000
for i in range(1,220000):
    if one_pop_count!=0:
        one_pow2[i] = one_pow2[i-1]*2%one_pop_count
    zero_pow2[i] = zero_pow2[i-1]*2%zero_pop_count


for i in range(n-1,-1,-1):
    if x[n-1-i]=='1':
        if one_pop_count!=0:
            nxt = one_mod
            nxt-=one_pow2[i]
            nxt%=one_pop_count
            print(f[nxt]+1)
        else:
            print(0)
    if x[n-1-i]=='0':
        nxt = zero_mod
        nxt+=zero_pow2[i]
        nxt%=zero_pop_count
        print(f[nxt]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
original_pop_count = x.count('1')
one_pop_count = original_pop_count-1
zero_pop_count = original_pop_count+1

one_mod = 0
zero_mod= 0
for b in x:
    one_mod=(one_mod*2+int(b))%one_pop_count
    zero_mod=(zero_mod*2+int(b))%zero_pop_count
#予めf[i]を計算する
f = [0]*220000
pop_count = [0]*220000
for i in range(1,220000):
    pop_count[i]= pop_count[i//2] + i%2
    f[i] = f[i%pop_count[i]]+1
one_pow2 = [1]*220000
zero_pow2 = [1]*220000
for i in range(1,220000):
    one_pow2[i] = one_pow2[i-1]*2%one_pop_count
    zero_pow2[i] = zero_pow2[i-1]*2%zero_pop_count


for i in range(n-1,-1,-1):
    if x[n-1-i]=='1':
        nxt = one_mod
        nxt-=one_pow2[i]
        nxt%=one_pop_count
        print(f[nxt]+1)
    if x[n-1-i]=='0':
        nxt = zero_mod
        nxt+=zero_pow2[i]
        nxt%=zero_pop_count
        print(f[nxt]+1)
Problem p02683 (python)

Fixed submission:
N,M,X = map(int,input().split())
A = []
cost = []
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a[1:])
    cost.append(a[0])
ans = float('inf')
for i in range(2**N):
    I = bin(i)[2:]
    I = I.zfill(N)
    tmp = [0]*M
    buy = 0
    for j in range(len(I)):
        if I[j]=='1':
            for k in range(len(A[j])):
                tmp[k] += A[j][k]
            buy += cost[j]
    if all(tmp[i]>=X for i in range(len(tmp))):
        ans = min(ans,buy)
ans = -1 if ans ==float('inf') else ans
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,X = map(int,input().split())
A = []
cost = []
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a[1:])
    cost.append(a[0])
ans = float('inf')
for i in range(2**N):
    I = bin(i)[2:]
    I = I.zfill(M)
    tmp = [0]*M
    buy = 0
    for j in range(len(I)):
        if I[j]=='1':
            for k in range(len(A[j])):
                tmp[k] += A[j][k]
            buy += cost[j]
    if all(tmp[i]>=X for i in range(len(tmp))):
        ans = min(ans,buy)
ans = -1 if ans ==float('inf') else ans
print(ans)