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

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
e=[(int(input().split()[0]),list(map(int,input().split())))for _ in range(m)]
INF=10**18
dp=[INF]*2**n
dp[0]=0
for i in range(2**n):
    if dp[i]>=INF:continue
    for a,c in e:
        bit=i
        for j in c:
            bit|=2**(n-j)
        dp[bit]=min(dp[bit],dp[i]+a)
a=dp[-1]
if a>=INF:
    print(-1)
else:
    print(dp[-1])

Buggy submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()));n,m=I();d=[0]+[9**9]*2**n
while m:
 m-=1;a=I()[0];s=sum(2<<c-1for c in I())
 for j in range(2**n):d[s|j]=min(d[s|j],d[j]+a)
print(d[-2]%9**9or-1)

Buggy submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()))
n,m=I()
e=[(I()[0],[2**(n-i)for i in I()])for _ in'_'m]
I=9**9
dp=[I]*2**n
dp[0]=0
for i,d in enumerate(dp):
    if d==I:continue
    for a,c in e:
        b,x=i,d+a
        for j in c:b|=j
        if dp[b]>x:dp[b]=x
print(-(dp[-1]==I)or dp[-1])
Problem p02902 (python)

Fixed submission:
from collections import*
n,m=map(int,input().split())
outs=defaultdict(list)
ins=defaultdict(int)
for _ in range(m):
    a,b=map(int,input().split())
    outs[a-1]+=b-1,
    ins[b-1]+=1
q=deque(i for i in range(n)if ins[i]==0)
res=[]
while q:
    v=q.popleft()
    res+=v,
    for w in outs[v]:
        ins[w]-=1
        if ins[w]==0:
            q.append(w)
print(-(len(res)==n))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
if not m:
    print(-1)
    exit()
e=[[]for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    e[a-1]+=b-1,
f=[None]*n
f[0]=-1
s=[0]
while s:
    v=s.pop()
    for w in e[v]:
        if f[w]!=None:
            ans=[]
            while v!=w:
                ans+=v+1,
                if len(ans)>n:
                    print(-1)
                    exit()
                v=f[v]
            ans+=w+1,
            print(len(ans))
            print(*ans[::-1],sep='\n')
            exit()
        else:
            f[w]=v
            s+=w,
print(-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
e=[[]for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    e[a-1]+=b-1,
f=[None]*n
f[0]=-1
s=[0]
while s:
    v=s.pop()
    for w in e[v]:
        if f[w]!=None:
            ans=[]
            while v!=w:
                ans+=v+1,
                if len(ans)>n:
                    print(-1)
                    exit()
                v=f[v]
            ans+=w+1,
            print(len(ans))
            print(*ans[::-1],sep='\n')
            exit()
        else:
            f[w]=v
            s+=w,
print(-1)
Problem p02913 (python)

Fixed submission:
from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include<iostream>
using namespace std;
main(){
  int n;
  string s;
  cin>>n>>s;
  int a=0;
  for(int i=0;i<n;++i){
    int t=0;
    for(int j=0;j<n-i;++j){
      t=(t+1)*(s[j]==s[j+i]);
      a=max(a,min(t,i));
    }
  }
  cout<<a;
}""")
call(('g++','e.cpp'))
call('./a.out')

Buggy submission (verdict: Runtime Error):
class RollingHash():
    def __init__(self,s):
        self.n=n=len(s)
        self.b=b=129
        self.M=M=2**61-1
        x,y=1,0
        self.f=f=[x]*(n+1)
        self.h=h=[y]*(n+1)
        for i,c in enumerate(s.encode()):
            f[i+1]=x=x*b%M
            h[i+1]=y=(y*b+c)%M
    def get(self,l,r):
        return(self.h[r]-self.h[l]*self.f[r-l])%self.M
def check(x):
    d={}
    for i in range(0,n-x+1):
        k=s.get(i,i+x)
        if k in d:
            if d[k]+x<=i:
                return True
        else:
            d[k]=j
    return False
n=int(input())
s=RollingHash(input())
ok,ng=0,n
while ng-ok>1:
    mid=ok+ng>>1
    if check(mid):
        ok=mid
    else:
        ng=mid
print(ok)

Buggy submission (verdict: Runtime Error):
n,s=open(0);a=i=j=0
while j<int(n):
 if s[l:j]in s[j:]:a=max(a,j-i);j+=1
 else:i+=1
print(a)
Problem p02917 (python)

Fixed submission:
_,b=open(0);*b,=map(int,b.split());print(b[0]+sum(min(t)for t in zip(b,b[1:]))+b[-1])

Buggy submission (verdict: Runtime Error):
_,b=open(0);a,*b,c=map(int,b.split());print(a+sum(map(min,zip([a]+b,b+[c])))+c)
Problem p02960 (python)

Fixed submission:
d=[1]+[0]*12
for i,c in enumerate(input()):
 p=[0]*13
 for j in range(13):
  for k in range(10):p[(j*10+k)%13]+=d[j]*(c>'9'or k==int(c))
 d=[t%(10**9+7)for t in p]
print(d[5])

Buggy submission (verdict: Runtime Error):
d=[1]+[0]*12
for c in input():
	e=[0]*13
	for k in([c],range(10))[c>'9']:
		for j in range(13):t=(j*10+k)%13;e[t]+=d[j];e[t]%=10**9+7
	d=e
print(d[5])
Problem p02972 (python)

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in range(n,0,-1):
    t=0
    for j in range(i,n+1,i):
        t+=b[j]
    b[i]=(t+a[i-1])%2
c=[i for i,b in enumerate(b)if b]
print(len(c),*c)

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
for i in range(n,0,-1):a[i-1]=sum(a[i-1::i])%2
print(sum(a),*[i for i in range(n+1)if a[i]])
Problem p02975 (python)

Fixed submission:
_,a=open(0);a,*b=map(int,a.split())
for b in b:a^=b
print('YNeos'[a>0::2])

Buggy submission (verdict: Runtime Error):
_,a=open(0);print('YNeos'[eval(a.replace(' ','^'))>0::2])
Problem p02982 (python)

Fixed submission:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print((sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0])//2)

Buggy submission (verdict: Runtime Error):
from numpy import*
x=loadtxt(open(0),skiprows=1)
print(sum(triu([linalg.norm(i-x,2,1)%1==0for i in x],1)))
Problem p02983 (python)

Fixed submission:
l,r=map(int,input().split());s=range(l,r+1);print(+(r-l<2019)and min(i*j%2019for i in s for j in s if i<j))

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split());print(+(r-l<2019)and min(i*j%2019for i in range(l,r)for j in range(i+1,r)))
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(v,c):
  for i,w in enumerate(e[v]):
    e[w].discard(v)
    c=c*dfs(w,k-i+~(v>0))%(10**9+7)
  return c
n,k,*t=map(int,open(0).read().split())
e=eval('set(),'*n)
for a,b in zip(t[::2],t[1::2]):
  e[a-1].add(b-1)
  e[b-1].add(a-1)
print(dfs(0,k))

Buggy submission (verdict: Runtime Error):
def dfs(v,c):
  for i,w in enumerate(e[v]):
    e[w]-={v}
    c=c*dfs(w,k-i+~(v>0))%(10**9+7)
  return c
n,k,*t=map(int,open(0).read().split())
e=[set()for _ in[0]*n]
for a,b in zip(t[::2],t[1::2]):
  e[a-1]|={b-1}
  e[b-1]|={a-1}
print(dfs(0,k))
Problem p03025 (python)

Fixed submission:
N, A, B, C = map(int, input().split())

MOD = 10**9 + 7
M = 2*N

fact = [1]*(M+1)
rfact = [1]*(M+1)
r = 1
for i in range(1, M+1):
  fact[i] = r = r * i % MOD
rfact[M] = r = pow(fact[M], MOD-2, MOD)
for i in range(M, 0, -1):
  rfact[i-1] = r = r * i % MOD

rev = pow(A+B, MOD-2, MOD)

p = 0
b = B * rev % MOD
e = 1
for k in range(N):
    v = fact[N+k-1] * rfact[N-1] * rfact[k] % MOD
    v = v * e * (N + k) % MOD
    e = e * b % MOD
    p += v
p *= pow(A * rev % MOD, N, MOD) * 100 * rev % MOD

q = 0
b = A * rev % MOD
e = 1
for k in range(N):
    v = fact[N+k-1] * rfact[N-1] * rfact[k] % MOD
    v = v * e * (N + k) % MOD
    e = e * b % MOD
    q += v
q *= pow(B * rev % MOD, N, MOD) * 100 * rev % MOD

print((p + q) % MOD)

Buggy submission (verdict: Runtime Error):
n,a,b,c=map(int,input().split())
M=10**9+7
m=2*n
fact=[1]*(M+1)
ifact=[1]*(M+1)
r=1
for i in range(1,m+1):fact[i]=r=r*i%M
ifact[m]=r=pow(fact[m],M-2,M)
for i in range(m,0,-1):ifact[i-1]=r=r*i%M
r=pow(a+b,M-2,M) 
p=0
d=b*r%M
e=1
for k in range(n):
    v=fact[n+k-1]*ifact[n-1]*ifact[k]%M*e*(n+k)%M
    e=e*d%M
    p+=v
p*=pow(a*r%M,n,M)*100*r%M
q=0
d=a*r%M
e=1
for k in range(n):
    v=fact[n+k-1]*ifact[n-1]*ifact[k]%M*e*(n+k)%M
    e=e*d%M
    q+=v
q*=pow(b*r%M,n,M)*100*r%M
print((p+q)%M)
Problem p03030 (python)

Fixed submission:
for *_,a in sorted([input().split()+[i]for i in range(int(input()))],key=lambda x:(x[0],-int(x[1]))):print(a+1)

Buggy submission (verdict: Runtime Error):
for*_,i in sorted((t[:5],-int(t[-4:]),i)for i,t in enumerate(open(0)))[1:]:print(i)

Buggy submission (verdict: Runtime Error):
for i in sorted(range(int(input())),key=lambda:[(s,-int(p))for s,p in[input().split()]]):print(i+1)
Problem p03032 (python)

Fixed submission:
n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k-i+1,n-i+1)):
  t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j
  while t and c and t[-1]<0:t.pop();c-=1
  m=max(m,sum(t))
print(m)

Buggy submission (verdict: Runtime Error):
n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k,n)-i+1):
  t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j
  while c*t[-1]<0:t.pop();c-=1
  m=max(m,sum(t))
print(m)
Problem p03044 (python)

Fixed submission:
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)

Buggy submission (verdict: Runtime Error):
(n,),*t=[map(int,t.split())for t in open(0)]
n+=1
*e,=eval('[],'*n)
q=[n]
f=[-1]*n
for v,w,c in t:e[v]+=w*n+c,;e[w]+=v*n+c,
for v in q:
 f[v//n]=v%n&1
 for w in e[v//n]:q+=[w+v%n]*(f[w//n]<0)
print(*f[1:])

Buggy submission (verdict: Runtime Error):
(n,),*t=[map(int,t,split())for t in open(0)]
*e,=eval('[],'*-~n)
q=[(1,0)]
f=[-1]*n
for v,w,c in t=:e[v]+=(w,c),;e[w]+=(v,c),
for v,c in q:
 f[v-1]=c%2
 for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0)
print(*f)

Buggy submission (verdict: Runtime Error):
n=int(input());e=[[]for _ in[0]*-~n];q=[(1,0)];f=[-1]*n
while n>1:v,w,c=map(int,input().split());e[v]+=(w,c),;e[w]+=(v,c),;n-=1
while q:
 v,c=q.pop();f[v-1]=c%2
 for w,d in e[v]:q+=(w,c+d),*(f[w-1]<0)
print(*f)
Problem p03050 (python)

Fixed submission:
n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)
Problem p03060 (python)

Fixed submission:
n,*t=map(int,open(0).read().split());print(sum((x-y)*(x>y)for x,y in zip(t[:n],t[n:])))

Buggy submission (verdict: Runtime Error):
from numpy import*;v,c=loadtxt(open(0),'i',skiprows=1);i=v>c;print(sum(v[i]-c[i]))

Buggy submission (verdict: Runtime Error):
from numpy import*;v,c=loadtxt(open(0),skiprows=1);i=v>c;print(sum(v[i]-c[i]))
Problem p03074 (python)

Fixed submission:
n,k=map(int,input().split())
*s,=input()
g=[]
t=1
for i in range(1,n):
    if s[i]==s[i-1]:
        t+=1
    else:
        g.append(t)
        t=1
g.append(t)
for i in range(1,len(g)):
    g[i]+=g[i-1]
g=[0]+g+[g[-1]]
a=0
for i in range(s[0]=='1',len(g),2):
    a=max(a,g[i]-g[max(0,i-2*k-1)])
print(a)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
*s,=input()
g=[]
t=1
for i in range(1,n):
 if s[i]==s[i-1]:t+=1
 else:g.append(t);t=1
g.append(t)
for i in range(1,len(g)):g[i]+=g[i-1]
g=[0]+g+[g[-1]]
print(max(g[i]-g[max(0,i-2*k-1)]for i in range(s[0]=='1',len(g),2))
Problem p03081 (python)

Fixed submission:
def solve(mid,g):
    for t,d in zip(z[::2],z[1::2]):
        if s[mid]==t:
            mid-=(d<'R')or-1
    return mid==g
n,q,s,*z=open(0).read().split()
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,0):
        ok=mid
    else:
        ng=mid
a=ok
ok=n+1
ng=0
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,n+1):
        ok=mid
    else:
        ng=mid
print(max(0,ok-a-1))

Buggy submission (verdict: Runtime Error):
I=input;n,q=map(int,I().split());s=' %s '%I();l,r=0,n+1
for t,_,d in eval('I(),'*q)[::-1]:L,R=d<'R',d>'L';l+=t==s[l+1]*L-(t==s[l])*R;r+=t==s[r]*L-(t==s[r-1])*R
print(max(0,r-l-1))
Problem p03085 (python)

Fixed submission:
print({'A':'T','T':'A','C':'G','G':'C'}[input()])

Buggy submission (verdict: Runtime Error):
print('TCGA'[id('')%5])
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]*n
for i in range(n):
    if i:
        a[i]=a[i-1]+(s[i-1:i+1]=='AC')
for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy submission (verdict: Runtime Error):
I=input
n,q=map(int,I())
s=I()
a=[0]
for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]
for _ in[0]*q:l,r=map(int,I());print(a[r]-a[l])
Problem p03088 (python)

Fixed submission:
n=int(input())
A,C,G,T,M=0,1,2,3,10**9+7
r=range
dp=[[[[0]*4for k in r(4)]for j in r(4)]for i in r(n+1)]
dp[0][T][T][T]=1
for i in r(1,n+1):
  for j in r(4):
    for k in r(4):
      for l in r(4):
        for m in r(4):
          if any(t==(k,l,m)for t in((A,G,C),(A,C,G),(G,A,C)))or(j,l,m)==(A,G,C)or(j,k,m)==(A,G,C):continue
          dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(dp[n][i][j][k]for i in r(4)for j in r(4)for k in r(4))%M)

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))%(10**9+7);'*int(input()));print(g)
Problem p03096 (python)

Fixed submission:
n,*c=map(int,open(0).readlines())
l=[-1]*2**18
b=[]
for i in range(n):
  b.append(l[c[i]])
  l[c[i]]=i
dp=[1]+[0]*n
for i in range(1,n):
  dp[i]=dp[i-1]
  if c[i]!=c[i-1]and b[i]>-1:
    dp[i]=(dp[i]+dp[b[i]])%(10**9+7)
print(dp[-2])

Buggy submission (verdict: Runtime Error):
n,*c=map(int,open(0).readlines())
l=[-1]*n
b=[]
for i in range(n):
  b.append(l[c[i]])
  l[c[i]]=i
dp=[1]+[0]*n
for i in range(1,n):
  dp[i]=dp[i-1]
  if c[i]!=c[i-1]and b[i]>-1:
    dp[i]=(dp[i]+dp[b[i]])%(10**9+7)
print(dp[-2])
Problem p03112 (python)

Fixed submission:
from bisect import*
A,B=abs,bisect
a,b,q,*l=map(int,open(0).read().split())
f=2**60
s,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]
for x in l[a+b:]:
  m=f
  i,j=B(s,x),B(t,x)
  for v in s[i-1:i+1]:
    for w in t[j-1:j+1]:
      m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))
  print(m)

Buggy submission (verdict: Runtime Error):
from bisect import*
A,B=abs,bisect
a,b,q,*l=map(int,open(0).read().split())
f=2**60
s,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]
for x in l[a+b:]:
  m=f
  i,j=B(s,x),B(t,x)
  for v in s[i-1,i+1]:
    for w in t[j-1,j+1]:
      m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))
  print(m)
Problem p03128 (python)

Fixed submission:
n,m,*a=map(int,open(0).read().split())
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j)
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])

Buggy submission (verdict: Runtime Error):
n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])
Problem p03136 (python)

Fixed submission:
input();*s,=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])

Buggy submission (verdict: Runtime Error):
input();s=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])
Problem p03145 (python)

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

Buggy submission (verdict: Runtime Error):
s=input();print(eval(s[:2]+'*'+s[2:-2])//2)
Problem p03148 (python)

Fixed submission:
import heapq
n,k=map(int,input().split())
z=[0,1]
for i in range(1,n):
    z.append(z[i]+2)
s=sorted([list(map(int,input().split()))for _ in range(n)],key=lambda x:-x[1])
q=[]
v=0
ans=0
l=[0]*-~n
for a in s[:k]:
    if not l[a[0]]:
        v+=1
        ans+=z[v]
    else:
        heapq.heappush(q,a[1])
    l[a[0]]=1
    ans+=a[1]
tem=ans
for a in s[k:]:
    if not q:break
    if l[a[0]]:continue
    l[a[0]]=1
    v+=1
    t=heapq.heappop(q)
    tem=tem-t+a[1]+z[v]
    ans=max(ans,tem)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as h;I=lambda:list(map(int,input().split()));n,k=I();z=[i*2+1for i in range(n)];s=sorted([I()for _ in[0]*n],key=lambda x:-x[1]);q=[];v=T=0;l=[0]*-~n
for a in s[:k]:
 if l[a[0]]:h.heappush(q,a[1])
 else:A+=z[v];v+=1
 l[a[0]]=1;A+=a[1]
T=A
for a in s[k:]:
 if not q:break
 if l[a[0]]^1:l[a[0]]=1;t=h.heappop(q);T=T-t+a[1]+z[v];v+=1;A=max(A,T)
print(A)
Problem p03164 (python)

Fixed submission:
I=lambda:list(map(int,input().split()))
n,W=I()
g=[0]+[I()for _ in range(n)]
vm=n*1000+1
dp=[[0]+[10**18]*vm]+[[0]*vm for _ in range(n)]
for i in range(1,n+1):
    w,v=g[i]
    for j in range(vm):
        k=j-v
        if k<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i-1][k]+w)
for j in range(vm)[::-1]:
    if dp[n][j]<=W:
        print(j)
        break

Buggy submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()))
n,W=I()
g=[0]+[I()for _ in range(n)]
dp=[[0]*-~W for _ in range(n+1)]
for i in range(1,n+1):
    t=g[i]
    for j in range(W+1):
        if j-t[0]>=0:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-t[0]]+t[1])
        else:
            dp[i][j]=dp[i-1][j]
print(max(dp[-1]))
Problem p03166 (python)

Fixed submission:
from collections import defaultdict,deque
v,n=map(int,input().split())
es=[[int(x)for x in input().split()]for _ in range(n)]
outs=defaultdict(list)
ins=defaultdict(int)
for v1,v2 in es:
    outs[v1].append(v2)
    ins[v2]+=1
q=deque(v1 for v1 in range(v+1)if ins[v1]==0)
res=[]
p=[0]*-~v
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2]-=1
        if ins[v2]==0:
            q.append(v2)
            p[v2]=v1
dp=[0]*-~v
for i in res[1:]:
  dp[i]=dp[p[i]]+1
print(max(dp)-1)

Buggy submission (verdict: Runtime Error):
import networkx as nx
def main():
    G=setup_graph()
    print_longest_path(G)
def setup_graph():
    G=nx.DiGraph()
    G.add_edges_from(tuple(tuple(list(map(int,input().split())))for _ in range(int(input().split()[1]))))
    return G
def print_longest_path(G):
    print(len(nx.dag_longest_path(G))-1)
if __name__=='__main__':
    main()
Problem p03173 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy submission (verdict: Runtime Error):
from functools import*
@lru_cache(None)
def s(l,r):
  if r-l<2:return 0
  return min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
n,*a=map(int,open(0).read().split())
for i in range(n-1):a[i+1]+=a[i]
a+=[0]
print(s(0,n))

Buggy submission (verdict: Runtime Error):
from functools import*
@lru_cache(None)
def s(a,d):
  n=len(a)
  if n==1:return a[0]*d
  return min(s(a[:i],d+1)+s(a[i:],d+1)for i in range(1,n))
n,*a=map(int,open(0).read().split())
print(s(tuple(a),0))
Problem p03174 (python)

Fixed submission:
def main():
  M=10**9+7
  n,*a=open(0)
  n=int(n)
  a=[list(map(int,t[::2]))for t in a]
  dp=[1]+[0]*(2**n-1)
  for i in range(2**n-1):
    j=bin(i).count('1')
    for k in range(n):
      to=i|1<<k
      if to==i or not a[j][k]:continue
      dp[to]+=dp[i]
      dp[to]%=M
  print(dp[-1])
main()

Buggy submission (verdict: Runtime Error):
from numpy import*
def main():
  M=10**9+7
  a=loadtxt(open(0),'?',skiprows=1)
  n=len(a)
  dp=zeros(2**n,'i8')
  dp[0]=1
  for i in range(2**n-1):
    to=i|1<<arange(n)[a[bin(i).count('1')]]
    dp[to]+=dp[i]
    dp[to]%=M
  print(dp[-1])
main()
Problem p03215 (python)

Fixed submission:
n,k,*a=map(int,open(0).read().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
for i in range(40,-1,-1):
    j=2**i
    t=[]
    for x in l:
        if x&j:
            t.append(x)
    if len(t)>=k:
        l=t
a,*b=l
for t in b:
    a&=t
print(a)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
*a,=map(int,input().split())
l=[]
for i in range(n):
    for j in range(i+1,n+1):
        l.append(sum(a[i:j]))
l=sorted(l)[-k:][::-1]
c=l[0]
for t in l[1:]:
    c&=t
print(t)
Problem p03216 (python)

Fixed submission:
from numpy import*
_,s,_,k=open(0)
s=array(list('='+s[:-1]))
d,m,c=[s==t for t in'DMC']
x,y=map(cumsum,(d,m))
for k in int32(k.split()):
  t=copy(x)
  t[k:]-=x[:-k]
  t*=m
  t[k+1:]-=d[1:-k]*(y[k:-1]-y[:~k])
  print(sum(cumsum(t)*c))

Buggy submission (verdict: Runtime Error):
e=enumerate
n,s,q,*k=open(0).read().split()
m,c,x=eval('[0]*-~int(n),'*3)
for i,t in e(s,1):
  m[i]=m[i-1]+(t=='M')
  f=t=='C'
  c[i]=c[i-1]+f
  x[i]=x[i-1]+f*m[i]
for k in map(int,k):
  a=0
  for i,t in e(s):
    j=min(n,i+k)
    if t=='D':a+=x[j]-x[i]-(c[j]-c[i])*m[i]
  print(a)
Problem p03219 (python)

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

Buggy submission (verdict: Runtime Error):
s=input();print(int(s[:2])+int(s[2:])//2)

Buggy submission (verdict: Runtime Error):
print(eval(input().replace(' ','+0.5*'))
Problem p03220 (python)

Fixed submission:
n,t,a,*h=map(int,open(0).read().split())
d,i=10**18,0
for j in range(n):
  if abs(a-t+h[j]*0.006)<d:
    d=abs(a-t+h[j]*0.006)
    i=j
print(i+1)

Buggy submission (verdict: Runtime Error):
input();I=map(int,input().split());t,a=I();d,i=9**9,0
for j,v in enumerate(I()):
 w=abs(a-t+v*0.006)
 if w<d:d=w;i=j
print(i+1)

Buggy submission (verdict: Runtime Error):
n,t,a,*h=map(int,open(0).read().spilt())
d,i=10**18,0
for j in range(n):
  if abs(a-t+h[j]*0.006)<d:
    d=abs(a-t+h[j]*0.006)
    i=j
print(i+1)

Buggy submission (verdict: Runtime Error):
n,t,a,*h=map(int,open(0).read().spilt())
d,i=10**18,0
for j in range(n):
  if abs(a-t+h*0.006)<d:
    d=abs(a-t+h*0.006)
    i=j
print(i+1)
Problem p03231 (python)

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
a=n//g
b=m//g
for i in range(g):
  if s[a*i]!=t[b*i]:
    print(-1)
    break
else:
  print(n*m//g)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
l=n*m//gcd(n,m)
x=['.']*l
for i in range(n):
  x[i*(l//n)]=s[i]
for i in range(m):
  if x[i*(l//m)]!='.'and x[i*(l//m)]!=t[i]:
    print(-1)
    break
else:
  print(l)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
def swap(a,b):
  c=a
  a=b
  b=c
  return(a,b)
n,m=map(int,input().split())
s=input()
t=input()
o=n*m//gcd(n,m)
if m>n:
  s,t=swap(s,t)
  n,m=swap(n,m)
if not n%m:
  for i in range(m):
    if s[n//m*i]!=t[i]:
      print(-1)
      break
  else:
    print(n)
  exit()
for i in range(1,10**7):
  g=o*i
  x=['.']*g
  for j in range(n):
    x[j*(g//n)]=s[j]
  for j in range(m):
    if x[j*(g//m)]!='.'and x[j*(g//m)]!=t[j]:break
  else:
    print(len(x))
    break
else:print(-1)

Buggy submission (verdict: Runtime Error):
from fraction import gcd
def swap(a,b):
  c=a
  a=b
  b=c
  return(a,b)
n,m=map(int,input().split())
s=input()
t=input()
o=n*m//gcd(n,m)
if m>n:
  s,t=swap(s,t)
  n,m=swap(n,m)
if not n%m:
  for i in range(m):
    if s[n//m*i]!=t[i]:
      print(-1)
      break
  else:
    print(n)
  exit()
for i in range(1,10**7):
  g=o*i
  x=['.']*g
  for j in range(n):
    x[j*(g//n)]=s[j]
  for j in range(m):
    if x[j*(g//m)]!='.'and x[j*(g//m)]!=t[j]:break
  else:
    print(len(x))
    break
else:print(-1)
Problem p03238 (python)

Fixed submission:
print input()+input()if input()-1 else'Hello World'

Buggy submission (verdict: Runtime Error):
print input()+input()if input()-1else'Hello World'
Problem p03239 (python)

Fixed submission:
i=lambda:map(int,input().split())
N,T=i()
a=9999
for _ in[0]*N:
  c,t=i()
  a=[min(a,c),a][t>T]
print('TLE'*(a>1000)or a)

Buggy submission (verdict: Runtime Error):
i=lambda:map(int,input().split());N,T=i();print(min([c for c,t in[i()for _ in[0]*N]if t<=T],default='TLE'))