Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
d=[[] for _ in range(n)]
e=[1]*m
for i in range(n):
  a,b=map(int,input().split())
  d[i]=(b,a)
d=sorted(d)[::-1]
ans=0
for i,j in d:
  for k in range(j-1,m):
    if e[k]:
      e[k]=0
      break
  else:continue 
  ans+=i
print(ans)

Fixed submission:
from heapq import*
n,m=map(int,input().split())
x=[[]for _ in range(m)]
for _ in range(n):
  a,b=map(int,input().split())
  if a<=m:x[a-1]+=[-b]
q=[]
ans=0
for i in range(m):
  for j in x[i]:heappush(q,j)
  if q:ans-=heappop(q)
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import*
def fact_p(n):
  m=n
  i=2
  while n>1:
    if i>m**.5:
      a=n
      break
    while n%i==0:
      n//=i
      a=i
    i+=1  
  return a
n=int(input())
x2=y1=ceil(n**.5+.5) if ceil(n**.5+.5)<=10**9 else 10**9
x1=fact_p(x2*y1-n)
y2=(x2*y1-n)//x1
print(0,0,x1,y1,x2,y2)

Fixed submission:
from math import*
def fact_p(n):
  m=n
  i=2
  a=0
  while n>1:
    if i>m**.5:
      a=n
      break
    while n%i==0:
      n//=i
      a=i
    i+=1  
  return a
n=int(input())
x2=y1=ceil(n**.5+.5) if ceil(n**.5+.5)<=10**9 else 10**9
x1=fact_p(x2*y1-n)
y2=(x2*y1-n)//x1 if x1 else 0
print(0,0,x1,y1,x2,y2)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import queue
INF=10**18
n=int(input())
a=queue.Queue()
for _ in range(n):
  a.put(int(input()))
cnt=0
while a.qsize():
  dp=[]
  for i in range(a.qsize()):
    i=a.get()
    if bisect.bisect_left(dp,i)==len(dp):
      dp.append(i)
    else:
      a.put(bisect.bisect_left(dp,i))
      dp[bisect.bisect_left(dp,i)]=i
  cnt+=1
print(cnt)

Fixed submission:
import bisect
n=int(input())
a=[int(input()) for _ in range(n)][::-1]
dp=[]
for i in a:
  if bisect.bisect_right(dp,i)==len(dp):
    dp.append(i)
  else:
    dp[bisect.bisect_right(dp,i)]=i
print(len(dp))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import queue
INF=10**18
n=int(input())
a=queue.Queue()
for _ in range(n):
  a.put(int(input()))
cnt=0
while a.qsize():
  dp=[]
  for i in range(a.qsize()):
    i=a.get()
    if bisect.bisect_left(dp,i)==len(dp):
      dp.append(i)
    else:
      a.put(bisect.bisect_left(dp,i))
      dp[bisect.bisect_left(dp,i)]=i
  cnt+=1
print(cnt)

Fixed submission:
import bisect
n=int(input())
a=[int(input()) for _ in range(n)][::-1]
dp=[]
for i in a:
  if bisect.bisect_right(dp,i)==len(dp):
    dp.append(i)
  else:
    dp[bisect.bisect_right(dp,i)]=i
print(len(dp))
Buggy python submission (verdict: Runtime Error):
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans])

Fixed submission:
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans>0])

Buggy python submission (verdict: Runtime Error):
from collections import*
n=int(input())
a=dict(Counter(list(map(int,input().split()))))
flag=1
if n%3:flag=0
elif len(a)==1 and a.key()[0]!=0:flag=0
elif len(a)==2 and a.get(0)!=n//3:flag=0
elif len(a)==3 and not(a.key()[0]==a.key()[1]==a.key()[2]==n//3):flag==0
print(['No','Yes'][flag])

Fixed submission:
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans>0])
Buggy python submission (verdict: Runtime Error):
from math import factorial
n,k=map(int,input().split())
mod=10**9+7
for i in range(k):
  div=factorial(k-1)//factorial(k-1-i)//factorial(i)
  print(factorial(n-k+1)//factorial(n-k-i)//factorial(i+1)*div%mod)

Fixed submission:
n,k=map(int,input().split())
class mod_comb_k():
  def __init__(self, MAX_N = 10**6, mod = 10**9+7):
    self.fact = [1]
    self.fact_inv = [0] * (MAX_N + 4)
    for i in range(MAX_N + 3):self.fact.append(self.fact[-1] * (i + 1) % mod)
    self.fact_inv[-1] = pow(self.fact[-1], mod - 2, mod)
    for i in range(MAX_N + 2, -1, -1):
      self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % mod
  def comb(self, n, k, mod = 10**9+7):
    return self.fact[n] * self.fact_inv[k] % mod * self.fact_inv[n - k] % mod
c=mod_comb_k(n)
mod=10**9+7
for i in range(k):
  div=c.comb(k-1,i)
  if n-k+1>=i+1:print(c.comb(n-k+1,i+1)*div%mod)
  else:print(0)
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
print(w*h/2,int(w/x==h/y==2))

Fixed submission:
w,h,x,y=map(int,input().split())
if (x,y)==(w/2,h/2):
  frag=1
else:frag=0
print(w*h/2,frag)
Buggy python submission (verdict: Runtime Error):
from collections import *
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
a=[]
for i in range(n):
  for j in range(i+1,n):
    a+=[(x[i]-x[j],y[i]-y[j])]
print(n-max(list(Counter(a).values())))

Fixed submission:
from collections import *
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
a=[]
for i in range(n):
  for j in range(n):
    if i==j:continue
    a+=[(x[i]-x[j],y[i]-y[j])]
c=list(Counter(a).values())
print(n-max(c) if c else n)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[int(input()) for _ in range(m)]
a=[]
if 1 not in b:
  a.append=1
else:a.append=0
if 2 not in b:
  a.append=2
else:a.append=0
for i in range(2,n):
  if i+1 not in b:
    a.append=(a[-1]+a[-2])%(10**9+7)
  else:a.append=0
print(a[-1])

Fixed submission:
n,m=map(int,input().split())
mod=10**9+7
dp=[1]*(n+1)
for _ in range(m):
  dp[int(input())]=0
dp[1]*=dp[0]
for i in range(2,n+1):
  dp[i]*=dp[i-1]+dp[i-2]
print(dp[-1]%mod)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[int(input()) for _ in range(m)]
a=[0]*n
if 1 not in b:
  a[0]=1
if 2 not in b:
  a[1]=2
for i in range(2,n):
  if i+1 not in b:
    a[i]=a[i-1]+a[i-2]
print(a)
print(a[-1]%(10**9+7))

Fixed submission:
n,m=map(int,input().split())
mod=10**9+7
dp=[1]*(n+1)
for _ in range(m):
  dp[int(input())]=0
dp[1]*=dp[0]
for i in range(2,n+1):
  dp[i]*=dp[i-1]+dp[i-2]
print(dp[-1]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import*
s=input()
n=len(s)
i=0
cnt=0
ans=0
while i<n:
  if s[i]=='A':
    i+=1
    cnt+=1
    while s[i:i+2]=='BC':
      ans+=cnt
      i+=2
  elif s[i:i+2]!='BC':
    cnt=0
    i+=1
print(ans)

Fixed submission:
s=input()
n=len(s)
i=0
cnt=0
ans=0
while i<n:
  if s[i]=='A':
    i+=1
    cnt+=1
    while s[i:i+2]=='BC':
      ans+=cnt
      i+=2
  else:
    cnt=0
    i+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=map(int,input().split())
INF=10**18
a=[input() for _ in range(h)]
d=[[INF for _ in range(w)]for _ in range(h)]
q=deque([])
for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      d[i][j]=0
      q.append((i,j))
dx=[1,0,-1,0]
dy=[0,1,0,-1]
ans=0
while q:
  x,y=q.popleft()
  for i in range(4):
    nx=x+dx[i]
    ny=y+dy[i]
    if 0<=nx<h and 0<=ny<w:
      if d[nx][ny]==INF:
        q.append((nx,ny))
        d[nx][ny]=d[x][y]+1
        ans=max(ans,d[nx][ny])
print(ans)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
INF=10**18
a=[input() for _ in range(h)]
d=[[INF for _ in range(w)]for _ in range(h)]
q=deque([])
for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      d[i][j]=0
      q.append((i,j))
dx=[1,0,-1,0]
dy=[0,1,0,-1]
ans=0
while q:
  x,y=q.popleft()
  for i in range(4):
    nx=x+dx[i]
    ny=y+dy[i]
    if 0<=nx<h and 0<=ny<w:
      if d[nx][ny]==INF:
        q.append((nx,ny))
        d[nx][ny]=d[x][y]+1
        ans=max(ans,d[nx][ny])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
ans=reduce(gcd,a[1:])
ans=max(ans,reduce(gcd,a[:n-1]))
for i in range(1,n-1):
  ans=max(gcd(reduce(gcd,a[:i]),reduce(gcd,a[i+1:])),ans)
print(ans)

Fixed submission:
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
ans=reduce(gcd,a[1:])
ans=max(ans,reduce(gcd,a[:n-1]))
for i in range(1,n-1):
  ans=max(gcd(reduce(gcd,a[:i]),reduce(gcd,a[i+1:])),ans)
print(ans*gc)

Fixed submission:
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
gc=reduce(gcd,a)
for i in range(n):
  a[i]//=gc
ans=reduce(gcd,a[1:])
ans=max(ans,reduce(gcd,a[:n-1]))
for i in range(1,n-1):
  ans=max(gcd(reduce(gcd,a[:i]),reduce(gcd,a[i+1:])),ans)
print(ans*gc)

Fixed submission:
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
gc=reduce(gcd,a)
for i in range(n):
  a[i]//=gc
ans=0
for _ in range(n):
  b=a.pop()
  ans=max(reduce(gcd,a),ans)
  a=[b]+a
print(ans*gc)

Fixed submission:
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
gc=reduce(gcd,a)
for i in range(n):
  a[i]//=gc
ans=0
for _ in range(n):
  b=a.pop()
  ans=max(reduce(gcd,a),ans)
  a=[b]+a
print(ans*gc)

Fixed submission:
from math import*
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
c=[a[-1]]
for i in range(1,n):
  b+=[gcd(b[-1],a[i])]
  c+=[gcd(c[-1],a[-i-1])]
ans=0
c=c[::-1]
for i in range(n):
  if i==0:ans=max(ans,c[i+1])
  elif i==n-1:ans=max(ans,b[i-1])
  else:
    ans=max(ans,gcd(c[i+1],b[i-1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
k=int(input())
a=''
b=s[k-1]
for i in s:
  if i==b:a+=i
  else:a+=*
print(a)

Fixed submission:
n=int(input())
s=input()
k=int(input())
a=''
b=s[k-1]
for i in s:
  if i==b:a+=i
  else:a+='*'
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
d=[]
for i in a:
  for j in b:
    d+=[i+j]
ans=[]
for i in c:
  for j in sorted(d)[::-1][:k]:
    ans+=[i+j]
print(*sorted(ans)[::-1][:k],sep='\n')

Fixed submission:
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
d=[]
for i in a:
  for j in b:
    d+=[i+j]
ans=[]
d=sorted(d)[::-1][:k]
for i in c:
  for j in d:
    ans+=[i+j]
print(*sorted(ans)[::-1][:k],sep='\n')
Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
i=0
while(k):
  i+=1
  if max(a%i,a%i):
    pass
  else:
    k-=1
print(i)

Fixed submission:
a,b,k=map(int,input().split())
i=min(a,b)+1
while(k):
  i-=1
  if max(a%i,b%i)==0:
    k-=1
print(i)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self, n=10**6):
    self.n=n
    self.root=[-1]*(n+1)
    self.rnk=[0]*(n+1)
  def find(self, x):
    if(self.root[x]<0):
      return x
    else:
      self.root[x]=self.find(self.root[x])
      return self.root[x]
  def unite(self, x, y):
    x=self.find(x)
    y=self.find(y)
    if(x==y):return 
    self.root[x]+=self.root[y]
    self.root[y]=x
n,m=map(int,input().split())
uf=UnionFind(n)
a=[0]*m
b=[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
c=[1]*(n+1)
ans=[n*(n-1)//2]
for i in range(m-1,0,-1):
  x,y=a[i],b[i]
  ans+=[max(ans[-1]-c[uf.find(x)]*c[uf.find(y)],0)]
  c[uf.find(x)]+=c[uf.find(y)]
  uf.unite(x,y)
print(*ans[::-1],sep='\n')

Fixed submission:
from itertools import combinations
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n,m=map(int,input().split())
uf=UnionFind(n)
e=[]
ans=[]
for _ in range(m):
  a,b=map(int,input().split())
  e.append((a,b))
n_m=n*(n-1)//2
for i,j in e[::-1]:
  ans.append(n_m)
  if not uf.isSameGroup(i,j):
    k=uf.Count(i)*uf.Count(j)
    n_m-=k
    uf.Unite(i,j)
for i in ans[::-1]:
  print(i)
Buggy python submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for _ in range(a)]+[INF]
T=[-INF]+[int(input()) for _ in range(b)]+[INF]
for i in range(q):
  x=int(input())
  i=bisect.bisect_left(S,x)
  j=bisect.bisect_left(T,x)
  d=INF
  for s in [S[i],S[i+1]]:
    for t in [T[i],T[j+1]]:
      d1=abs(s-x)+abs(t-s)
      d2=abs(t-x)+abs(t-s)
      d=min(d,d1,d2)
  print(d)

Fixed submission:
import bisect
INF=10**11
A,B,q=map(int,input().split())
a=[-INF]+[int(input()) for _ in range(A)]+[INF]
b=[-INF]+[int(input()) for _ in range(B)]+[INF]
for _ in range(q):
  x=int(input())
  i=bisect.bisect_left(a,x)
  j=bisect.bisect_left(b,x)
  ans=min(max(a[i],b[j])-x,x-min(a[i-1],b[j-1]),a[i]-b[j-1]+min(a[i]-x,x-b[j-1]),b[j]-a[i-1]+min(b[j]-x,x-a[i-1]))
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
n=len(s)
m=len(t)
dp=['' for _ in range(m+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[j+1]=dp[j]+s[i]
    else:dp[j+1]=max(dp[j+1],dp[j],key=len)
print(dp[-1])

Fixed submission:
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1])
ans=''
while n*m:
  if s[n-1]==t[m-1]:
    ans+=s[n-1]
    n-=1
    m-=1
  else:
    if dp[n-1][m]>dp[n][m-1]:n-=1
    else:m-=1
print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
n=len(s)
m=len(t)
dp=[['' for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+s[i]
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1],key=len)
print(dp[-1][-1])

Fixed submission:
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1])
ans=''
while n*m:
  if s[n-1]==t[m-1]:
    ans+=s[n-1]
    n-=1
    m-=1
  else:
    if dp[n-1][m]>dp[n][m-1]:n-=1
    else:m-=1
print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
n=len(s)
m=len(t)
dp=[['' for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+s[i]
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1],key=len)
print(dp[-1][-1])

Fixed submission:
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
    else:dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i+1][j+1])
ans=''
while n*m:
  if s[n-1]==t[m-1]:
    ans+=s[n-1]
    n-=1
    m-=1
  else:
    if dp[n-1][m]>dp[n][m-1]:n-=1
    else:m-=1
print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
def dfs(now):
  if v[now]:return v[now]
  res=1
  for to in e[now]:
    res=max(res,dfs(to)+1)
  v[now]=res
  return res
n,m=map(int,input().split())
e=[[]for _ in range(n+1)]
for i in range(m):
  x,y=map(int,input().split())
  e[x]+=[y]
v=[0]*(n+1)
v[0]=1
ans=0
for i in range(n+1):
  ans=max(ans,dfs(i))
print(ans-1)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
dp=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)

def dfs(s):
  if edge[s]:
    for i in edge[s]:
      if dp[i]:dp[s]=max(dp[s],dp[i]+1)
      else:dp[s]=max(dp[s],dfs(i)+1)
    return dp[s]
  else:return 0
for i in range(n):
  dfs(i)
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
dp=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)

def dfs(s):
  if edge[s]:
    for i in edge[s]:
      if dp[i]:dp[s]=max(dp[s],dp[i]+1)
      else:dp[s]=max(dp[s],dfs(i)+1)
    return dp[s]
  else:return 0
for i in range(n):
  dfs(i)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
dp=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)

def dfs(s):
  if edge[s]:
    for i in edge[s]:
      if dp[i]:dp[s]=max(dp[s],dp[i]+1)
      else:dp[s]=max(dp[s],dfs(i)+1)
    return dp[s]
  else:return 0
for i in range(n):
  dfs(i)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
import queue
INF=10**8
R=10**9+7
h,w=map(int,input().split())
maze=[input() for _ in range(h)]
d=[[0 for i in range(h)] for _ in range(w)]
sx=0
sy=0
gx=w-1
gy=h-1
q=queue.Queue()
dx=[1,0]
dy=[0,1]
q.put((sx,sy))
d[sy][sx]=1
while not q.empty():
  x,y=q.get()
  if (x,y)==(gx,gy):break
  for i in range(2):
    nx=x+dx[i]
    ny=y+dy[i]
    if nx<w and ny<h:
      if maze[ny][nx]=='.':
        if d[nx][ny]==0:
          q.put((nx,ny))
          d[nx][ny]=d[x][y]
        else:d[nx][ny]+=d[x][y]
print(d[gy][gx]%R)

Fixed submission:
import queue
INF=10**8
R=10**9+7
h,w=map(int,input().split())
maze=[input() for _ in range(h)]
d=[[0 for i in range(h)] for _ in range(w)]
sx=0
sy=0
gx=w-1
gy=h-1
q=queue.Queue()
dx=[1,0]
dy=[0,1]
q.put((sx,sy))
d[sy][sx]=1
while not q.empty():
  x,y=q.get()
  if (x,y)==(gx,gy):break
  for i in range(2):
    nx=x+dx[i]
    ny=y+dy[i]
    if nx<w and ny<h:
      if maze[ny][nx]=='.':
        if d[nx][ny]==0:
          q.put((nx,ny))
          d[nx][ny]=d[x][y]
        else:d[nx][ny]+=d[x][y]
print(d[gx][gy]%R)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=[]
for i in input().split():
  p+=[int(i.split(".")[1])]
dp=[[0]*(n+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
  dp[i+1][0]=dp[i][0]*(100-p[i])
  for j in range(i+1):
    dp[i+1][j+1]=dp[i][j]*p[i]+dp[i][j+1]*(100-p[i])
print(sum([dp[n][i] for i in range((n+1)//2,n+1)])/pow(100,n))

Fixed submission:
n=int(input())
p=list(map(float,input().split()))
dp=[[0 for _ in range(n+1)]for _ in range(n)]
dp[0][0]=1-p[0]
dp[0][1]=p[0]
for i in range(1,n):
  for j in range(i+2):
    dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i])
print(sum(dp[-1][(n+1)//2:]))
Buggy python submission (verdict: Runtime Error):
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n-1]+2:return p[n-1]+1
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x)) 

Fixed submission:
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n]:return p[n]
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))

Buggy python submission (verdict: Runtime Error):
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n-1]+1:return p[n-1]+1
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x)) 

Fixed submission:
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n]:return p[n]
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(list(map(int,input().split())))
b=list(zip(*a))
c=sorted(b[1])
d=[0]*n
for i in c:
  j=b[0][b[1].index(i)]-1
  d[j]+=1
  a[b[1].index(i)][1]=d[j]
for i in range(m):
  print('{0:06}{1:06} '.format(a[i][0],a[i][1]))

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
data=[]
pn=[0 for _ in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  heappush(data,(y,p,i))
data2=[]
while data:
  y,p,i=heappop(data)
  pn[p-1]+=1
  cid=str(p).zfill(6)+str(pn[p-1]).zfill(6)
  data2.append((i,cid))
for i,cid in sorted(data2):
  print(cid)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(list(map(int,input().split())))
b=list(zip(*a))
c=sorted(b[1])
d=[0]*n
for i in c:
  j=b[0][b[1].index(i)]-1
  d[j]+=1
  a[b[1].index(i)][1]=d[j]
for i in range(m):
  print('{0:06}{1:06} '.format(a[i][0],a[i][1]))

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
data=[]
pn=[0 for _ in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  heappush(data,(y,p,i))
data2=[]
while data:
  y,p,i=heappop(data)
  pn[p-1]+=1
  cid=str(p).zfill(6)+str(pn[p-1]).zfill(6)
  data2.append((i,cid))
for i,cid in sorted(data2):
  print(cid)