Harryxun/testdata huggingface dataset:
Buggy python 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)

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 python 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)

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 python submission (verdict: Time Limit Exceeded):
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        *_,=map(temp.append,(self.popleft()for _ in range(n//2)))
        *_,=map(self.append,(self.popleft()for _ in range(n//2,n)))
        *_,=map(self.appendleft,temp[::-1])
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        *_,=map(temp.append,(self.pop()for _ in range(n//2)))
        *_,=map(self.appendleft,(self.pop()for _ in range(n//2,n)))
        *_,=map(self.append,temp[::-1])
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Fixed submission:
def main():
  def update(k,x):
    k+=N0-1
    data_min[k]=data_max[k]=x
    while k>=0:
      k=(k-1)//2
      a,b=data_min[2*k+1],data_min[2*k+2]
      data_min[k]=a if a<b else b
      a,b=data_max[2*k+1],data_max[2*k+2]
      data_max[k]=a if a>b else b
  def query_min(l,r):
    L,R=l+N0,r+N0
    s=INF
    while L<R:
      if R&1:
        R-=1
        t=data_min[R-1]
        if t<s:s=t
      if L&1:
        t=data_min[L-1]
        if t<s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def query_max(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
      if R&1:
        R-=1
        t=data_max[R-1]
        if t>s:s=t
      if L&1:
        t=data_max[L-1]
        if t>s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def root(x):
    while table[x]>=0:x=table[x]
    return x
  def unite(x,y):
    x=root(x)
    y=root(y)
    if x!=y:
      if table[x]>table[y]:x,y=y,x
      table[x]+=table[y]
      table[y]=x
  def same(x,y):return root(x)==root(y)
  def size(x):return-table[root(x)]
  n,k,*p=map(int,open(0).read().split())
  N0=2**(n-1).bit_length()
  INF=10**18
  data_min=[INF]*2*N0
  data_max=[0]*2*N0
  table=[-1]*n
  c=[0]
  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
  x=not f
  for i,q in enumerate(p):update(i,q)
  for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1
  print(x+f)
main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import*
n,m,*a=map(int,open(0).read().split())
a.sort()
while m:insort(a,a.pop()//2);m-=1
print(sum(a))

Fixed submission:
from heapq import*;n,m,*a=[-int(i)for i in open(0).read().split()];heapify(a);exec('heappush(a,0--heappop(a)//2);'*-m);print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import*
n,m,*a=map(int,open(0).read().split())
a.sort()
while m:insort(a,a.pop()//2);m-=1
print(sum(a))

Fixed submission:
from heapq import*;n,m,*a=[-int(i)for i in open(0).read().split()];heapify(a);exec('heappush(a,0--heappop(a)//2);'*-m);print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import*
n,m,*a=map(int,open(0).read().split())
a.sort()
exec('insort(a,a.pop()//2);'*m)
print(sum(a))

Fixed submission:
from heapq import*;n,m,*a=[-int(i)for i in open(0).read().split()];heapify(a);exec('heappush(a,0--heappop(a)//2);'*-m);print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import*;n,m,*a=[-int(i)for i in open(0).read().split()];heapify(a);exec('heappush(a,0--heappop(a)//2);'*-m);print(-sum(a))

Fixed submission:
from heapq import*;n,m,*a=[-int(i)for i in open(0).read().split()];heapify(a);exec('heappush(a,0--heappop(a)//2);'*-m);print(-sum(a))
Buggy python 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)

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 python submission (verdict: Time Limit Exceeded):
n,s=open(0)
n=int(n)
a=l=s[0]<'W'>s[-2]
r=f=0
for b,c in zip(s,s[1:-1]):f^=b==c;a*=(l-r)**f;r+=f;l+=f^1
while n:a=a*n%(10**9+7);n-=1
print(a*(l==r))

Fixed submission:
from math import*
M=10**9+7
n=int(input())
s=input()
if s[0]==s[-1]=='W':
  print(0)
  exit()
l=a=1
r=f=0
for b,c in zip(s,s[1:]):
  if b==c:
    f^=1
  if f:
    a*=l-r
    a%=M
    r+=1
  else:
    l+=1
print(a*factorial(n)%M*(l==r))

Buggy python submission (verdict: Time Limit Exceeded):
n,s=open(0)
n=int(n)
a=s[0]<'W'>s[-2]
while n:a*=n;n-=1
l=1
r=f=0
for b,c in zip(s,s[1:-1]):f^=b==c;a=a*(l-r)**f%(10**9+7);r+=f;l+=f^1
print(a*(l==r))

Fixed submission:
from math import*
M=10**9+7
n=int(input())
s=input()
if s[0]==s[-1]=='W':
  print(0)
  exit()
l=a=1
r=f=0
for b,c in zip(s,s[1:]):
  if b==c:
    f^=1
  if f:
    a*=l-r
    a%=M
    r+=1
  else:
    l+=1
print(a*factorial(n)%M*(l==r))
Buggy python submission (verdict: Time Limit Exceeded):
from subprocess import*
with open('A.py','w')as f:
    f.write('a,b=map(int,input().split())\n')
    for i in range(-100,101):
        f.write('if a==%d:\n'%i)
        for j in range(-100,101):
            f.write('    if b==%d:print(%d)\n'%(j,max(i+j,i-j,i*j)))
call(('pypy3','A.py'))

Fixed submission:
from subprocess import*
with open('A.py','w')as f:
    f.write('a,b=map(int,input().split())\n')
    for i in range(-100,101):
        f.write('if a==%d:\n'%i)
        for j in range(-100,101):
            f.write('    if b==%d:print(%d)\n'%(j,max(i+j,i-j,i*j)))
call(('python3','A.py'))
Buggy python submission (verdict: Runtime Error):
print(max(0,eval('-'+input().replace(' ','+')))

Fixed submission:
print(max(0,eval('-'+input().replace(' ','+'))))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  M=10**9+7
  d=[1]+[0]*12
  for c in input():
    if c>'9':
      d=[sum(d[(j-k)*9%13]for j in range(10))%M for k in range(13)]
    else:
      d=[d[(int(c)-k)*9%13]for k in range(13)]
  print(d[5])
main()

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 python submission (verdict: Time Limit Exceeded):
def main():
  d=[1]+[0]*12
  for c in input():
    d=[sum(d[(j-k)*9%13]for j in(range(10)if c>'9'else[int(c)]))%(10**9+7)for k in range(13)]
  print(d[5])
main()

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 python submission (verdict: Time Limit Exceeded):
def main():
  d=[1]+[0]*12
  for c in input():
    d=tuple(sum(d[(j-k)*9%13]for j in c<'?'and[int(c)]or range(10))%(10**9+7)for k in range(13))
  print(d[5])
main()

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 python submission (verdict: Time Limit Exceeded):
def main():
  d=[1]+[0]*12
  for c in input():
    d=[sum(d[(j-k)*9%13]for j in c<'?'and[int(c)]or range(10))%(10**9+7)for k in range(13)]
  print(d[5])
main()

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 python 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])

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 python 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]])

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 python submission (verdict: Runtime Error):
_,a=open(0);print('YNeos'[eval(a.replace(' ','^'))>0::2])

Fixed submission:
_,a=open(0);a,*b=map(int,a.split())
for b in b:a^=b
print('YNeos'[a>0::2])
Buggy python submission (verdict: Time Limit Exceeded):
from time import sleep
n, a, b = map(int, input().split())
sleep(1.99)
print(max(a * n, b))

Fixed submission:
n,a,b=map(int,input().split());print(min(n*a,b))

Buggy python submission (verdict: Time Limit Exceeded):
from time import sleep
n, a, b = map(int, input().split())
sleep(1.99)
print(min(a * n, b))

Fixed submission:
n,a,b=map(int,input().split());print(min(n*a,b))
Buggy python 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)))

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 python 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)))

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 python submission (verdict: Time Limit Exceeded):
_,a=open(0);*a,=map(int,a.split());t=sum(a)-2*sum(a[1::2]);x=t,
for i in a:t=i*2-t;x+=t,
print(*x[:-1])

Fixed submission:
_,a=open(0)
*a,=map(int,a.split())
t=sum(a)-2*sum(a[1::2])
x=[t]
for i in a:
  t=i*2-t
  x+=t,
print(*x[:-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k,*t=map(int,open(0).read().split())
c,e=k,[0]*-~n
for v in t:
 e[v]+=1
 if(v>1)-e[v]:c*=k-e[v]
print(c%(10**9+7))

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 python 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))

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 python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
def dfs(v,c):
  for i,w in enumerate(e[v]):
    e[w].discard(v)
    c*=dfs(w,k-i+~(v>0))
  return c%(10**9+7)
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))

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 python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=n-k+1
for i in range(k):print(p%(10**9+7));p=p*(k-i)*(n-k+1-i)//i//-~i

Fixed submission:
class F:
    def __init__(self,n,mod):
        self.mod=mod
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return 0 if k>n else self.f[n]*self.i[n-k]*self.i[k]%self.mod
n,k=map(int,input().split())
M=10**9+7
c=F(n,M).comb
for i in range(k):
    print(c(n-k+1,i+1)*c(k-1,i)%M)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    for i,s in e(u[:n]):
        for j,t in e(u[n:]):
            dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j]*(s!=t))%(10**9+7)
    print(dp[n][m])
main()

Fixed submission:
def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m])
main()
Buggy python submission (verdict: Time Limit Exceeded):
n,_,*a=map(int,open(0).read().split())
c,d=1,0
for i in range(n):n=(c+d)%(10**9+7)*(not-~i in set(a));c,d=n,c
print(n)

Fixed submission:
n,_,*a=map(int,open(0).read().split())
a=set(a)
c,d=1,0
for i in range(n):n=(c+d)%(10**9+7)*(not-~i in a);c,d=n,c
print(n)

Buggy python submission (verdict: Time Limit Exceeded):
n,_,*a=map(int,open(0).read().split())
c,d=1,0
for i in range(n):n=(c+d)%(10**9+7)*(not-~i in a);c,d=n,c
print(n)

Fixed submission:
n,_,*a=map(int,open(0).read().split())
a=set(a)
c,d=1,0
for i in range(n):n=(c+d)%(10**9+7)*(not-~i in a);c,d=n,c
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b*=2
  print((a+b)%M)
main()

Fixed submission:
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b=b*2%M
  print((a+b)%M)
main()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
a=0
b=1
M=10**9+7
p=[1]
for i in range(n-1):
  p.append(p[i]*3%M)
for i,t in enumerate(map(int,s)):
  if t:
    a=(a+b*p[~i])%M
    b*=2
print((a+b)%M)

Fixed submission:
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b=b*2%M
  print((a+b)%M)
main()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
a=0
b=1
M=10**9+7
p=[1]
for _ in range(n):
  p.append(p[-1]*3%M)
for i,t in enumerate(s):
  if int(t):
    a=(a+b*p[n-i-1])%M
    b*=2
print((a+b)%M)

Fixed submission:
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b=b*2%M
  print((a+b)%M)
main()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
a=0
b=1
M=10**9+7
for i in range(n):
  if'0'<s[i]:
    a=(a+b*pow(3,n-i-1,M))%M
    b*=2
print((a+b)%M)

Fixed submission:
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b=b*2%M
  print((a+b)%M)
main()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
a=b=0
M=10**9+7
for i in range(n):
  if'0'<s[i]:
    a+=2**b*3**(n-i-1)%M
    b+=1
print((a+2**b)%M)

Fixed submission:
def main():
  s=input()
  n=len(s)
  a,b,M=0,1,10**9+7
  p=[1]
  for i in range(n-1):
    p.append(p[i]*3%M)
  for i,t in enumerate(map(int,s)):
    if t:
      a=(a+b*p[~i])%M
      b=b*2%M
  print((a+b)%M)
main()
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split());s=input();t=[b-2:d+1];print('YNeos'[not'...'*(d<c)in t or'##'in s[a:c]+t::2])

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=input()
if'##'in s[a:c]or'##'in s[b:d]or d<c and not'...'in s[b-2:d+1]:
  print('No')
else:
  print('Yes')
Buggy python 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)

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 python submission (verdict: Runtime Error):
for*_,i in sorted((t[:5],-int(t[-4:]),i)for i,t in enumerate(open(0)))[1:]:print(i)

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 python 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)

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 python 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)

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 python submission (verdict: Runtime Error):
n,m,*t=map(int,open(0).read().split())
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
 while a*b and c>a[-1]:m+=c;b-=1;a.pop()
print(m+sum(a))

Fixed submission:
n,m,*t=map(int,open(0).read().split())
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
 while a and b and c>a[-1]:m+=c;b-=1;a.pop()
print(m+sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import*;M=10**9+7;n,m,k=map(int,input().split());s=lambda x,y:sum(y*y*i*(x-i)for i in range(x));print((s(n,m)+s(m,n))%M*comb(n*m-2,k-2,1)%M)

Fixed submission:
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]*self.i[k]
n,m,k=map(int,input().split())
M=10**9+7
print((sum(m*m*i*(n-i)for i in range(n))+sum(n*n*i*(m-i)for i in range(m)))*Factorial(n*m,M).comb(n*m-2,k-2)%M)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import*;n,m,k=map(int,input().split());s=lambda x,y:sum(y*y*i*(x-i)for i in range(x));print((s(n,m)+s(m,n))*comb(n*m-2,k-2,1)%(10**9+7))

Fixed submission:
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]*self.i[k]
n,m,k=map(int,input().split())
M=10**9+7
print((sum(m*m*i*(n-i)for i in range(n))+sum(n*n*i*(m-i)for i in range(m)))*Factorial(n*m,M).comb(n*m-2,k-2)%M)
Buggy python submission (verdict: Runtime Error):
s=input();print['NA','MMYY','YYMM','AMBIGUOUS'][(99<s<1300)-(0<s%100<13)*2]

Fixed submission:
s=input();a,b=int(s[:2]),int(s[2:]);print(['NA','MMYY','YYMM','AMBIGUOUS'][(0<a<13)-(0<b<13)*2])