Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s,_,*q=open(0)
a=s[:-1]
p=1
for q in q:p^=q<'2';c=q[-2]*(q>'2');f=(q<'2 2')^p;a=(f^1)*c+a+c*f
print(a[::p or-1])

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

head = ""
tail = ""
main = S

status = 0

while Q:
  Q -= 1
  l = list(map(str,input().split()))
  if l[0] == "1":
    status = (status+1)%2
  else:
    letter = l[2]
    if l[1] == "1":
      if status == 0:
        head += letter
      else:
        tail += letter
    else:
      if status == 0:
        tail += letter
      else:
        head += letter

if status == 0:
  print(head[::-1]+main+tail)
else:
  print(tail[::-1]+main[::-1]+head)

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Buggy python submission (verdict: Time Limit Exceeded):
s,_,*q=open(0)
a=s[:-1]
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:a+=c
    else:a=c+a
  except:p^=1
print(a[::p or-1])

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Buggy python submission (verdict: Time Limit Exceeded):
s,_,*q=open(0)
a=['',s[:-1]]
p=1
for q in q:
  try:
    q,f,c=q.split()
    i=(f<'2')^p
    a[i]=''.join((a[i],c))
  except:p^=1
print(a[p^1][::-1]+a[p])

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Buggy python submission (verdict: Time Limit Exceeded):
s,_,*q=open(0)
a=['','']
p=1
for q in q:
  try:
    q,f,c=q.split()
    a[(f<'2')^p]+=c
  except:p^=1
print(a[p^1][::-1]+s[:-1][::p or-1]+a[p])

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Buggy python submission (verdict: Time Limit Exceeded):
s,_,*q=open(0)
a=['',s[:-1]]
p=1
for q in q:p^=q<'2';a[(q<'2 2')^p]+=q[-2]*(q>'2')
print(a[p^1][::-1]+a[p])

Fixed submission:
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])
Buggy python submission (verdict: Runtime Error):
f=lambda a:any(all(b)for b in a)or all(a[i][i]for i in(0,1,2))   
a=eval('list(map(int,input().split())),'*3)
exec('b=int(input());a=[[u*(u!=b)for u in t]for t in a];'*int(input()))
a=[[not u for u in t]for t in a]
print('NYoe s'[f(a)|f(t[::-1]for t in zip(*a))::2])

Fixed submission:
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2))   
a=eval('list(map(int,input().split())),'*3)
exec('b=int(input());a=[[u*(u!=b)for u in t]for t in a];'*int(input()))
a=[[not u for u in t]for t in a]
print('NYoe s'[f(a)|f([t[::-1]for t in zip(*a)])::2])
Buggy python submission (verdict: Runtime Error):
(n,_),*t=[t.split()for t in open(0)]
n=int(n)
for i in range(10**(n-1-(n<2)),10**n):
  i=str(i)
  for s,c in t:
    if i[int(s)-1]!=c:
      break
  else:
    print(i)
    break
else:
  print(-1)

Fixed submission:
(n,_),*t=[t.split()for t in open(0)]
n=int(n)
for i in range(10**(n-1)-(n<2),10**n):
  i=str(i)
  for s,c in t:
    if i[int(s)-1]!=c:
      break
  else:
    print(i)
    break
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
s=input();print(100*max(0,10-int(s[:2]))+int(s[2:]))

Fixed submission:
n,r=map(int,input().split());print(100*max(0,10-n)+r)
Buggy python submission (verdict: Runtime Error):
n,k=input().split();print(len(str(int(n,int(k)))))

Fixed submission:
n,k=map(int,input().split())
c=0
while n:n//=k;c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
s,a,u=open(0);i=s.find(u)<1;print(int(a[0])-i,int(a[2])-1+i)

Fixed submission:
s,t,a,b,u=open(0).read().split();i=u==s;print(int(a)-i,int(b)-1+i)
Buggy python submission (verdict: Runtime Error):
n,k,*p=map(int,open(0).read().split())
p+=0,
for i in range(n):p[i]-=~p[i-1]
print(max(p[i+k]-p[i-1]for i in range(n-k))/2)

Fixed submission:
n,k,*p=map(int,open(0).read().split())
p+=0,
for i in range(n):p[i]-=~p[i-1]
print(max(p[i+k]-p[i]for i in range(-1,n-k))/2)

Buggy python submission (verdict: Runtime Error):
n,k,*p=map(int,open(0).read().split())
p+=0,
for i in range(n):p[i]+=p[i-1]
print(max(p[i+k]-p[i-1]for i in range(n-k))/2)

Fixed submission:
n,k,*p=map(int,open(0).read().split())
p+=0,
for i in range(n):p[i]-=~p[i-1]
print(max(p[i+k]-p[i]for i in range(-1,n-k))/2)
Buggy python submission (verdict: Runtime Error):
(h,n),*t=[[*map(int,t.split())]for t in open(0)]
d=[0]*h*n
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h])

Fixed submission:
h,n,*t=map(int,open(0).read().split())
dp=[10**18]*(h+1)
dp[0]=0
for a,b in zip(*[iter(t)]*2):
    for j in range(h+1):
        dp[j]=min(dp[j],dp[max(0,j-a)]+b)
print(dp[h])

Buggy python submission (verdict: Runtime Error):
(h,n),*t=[[*map(int,t.split())]for t in open(0)]
d=[0]*-~h
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h])

Fixed submission:
h,n,*t=map(int,open(0).read().split())
dp=[10**18]*(h+1)
dp[0]=0
for a,b in zip(*[iter(t)]*2):
    for j in range(h+1):
        dp[j]=min(dp[j],dp[max(0,j-a)]+b)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
intLine=lambda:map(int,input().split())
h,n=intLine()
dp=[10**9]*(h+1)
dp[0]=0
for _ in range(n):
  a,b=intLine()
  for j in range(h+1):
    dp[j]=min(dp[j],dp[max(0,j-a)]+b)
print(dp[h])

Fixed submission:
h,n,*t=map(int,open(0).read().split())
dp=[10**18]*(h+1)
dp[0]=0
for a,b in zip(*[iter(t)]*2):
    for j in range(h+1):
        dp[j]=min(dp[j],dp[max(0,j-a)]+b)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h,n,*t=map(int,open(0).read().split())
d=[0]+[9e9]*h
for a,b in zip(*[iter(t)]*2):
 for j in range(h+1):d[j]=min(d[j],d[max(0,j-a)]+b)
print(d[h])

Fixed submission:
h,n,*t=map(int,open(0).read().split())
dp=[10**18]*(h+1)
dp[0]=0
for a,b in zip(*[iter(t)]*2):
    for j in range(h+1):
        dp[j]=min(dp[j],dp[max(0,j-a)]+b)
print(dp[h])
Buggy python submission (verdict: Runtime Error):
_,a,b=sorted(input())[1:];print(a*int(b))

Fixed submission:
a,b=input().split()
print(min(a*int(b),b*int(a)))
Buggy python submission (verdict: Runtime Error):
from networkx import*
_,*s=open(i:=0)
g=[]
for t in s:
 i+=1;j=0
 for u in t:g+=[(k:=i*20+j,k+20)]*(u>'#'<(s+['#'*k])[i][j])+[(k,k+1)]*(u>'#'<t[j:=j+1])
print(max(t[i]for _,t in shortest_path_length(Graph(g))for i in t))

Fixed submission:
from scipy.sparse import*
e=enumerate
h,*s=open(0)
h,w=map(int,h.split())
r,c=[],[]
for i,t in e(s):
  for j,u in e(t):
    if u>'#'<t[j+1]:r+=i*w+j,;c+=i*w+j+1,
    if(i<h-1)*u>'#'<s[i+1][j]:r+=i*w+j,;c+=j-~i*w,    
print(int((csgraph.johnson(csr_matrix(([1]*len(r),(r,c)),[h*w]*2),0).clip(0,999)%999).max()))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
M=999
*s,=open(0)
*g,=eval('[0]*M,'*M)
i=0
for t in s:
 i+=1;j=0
 for u in t:k=i*20+j;g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1;g[k][k+1]=u>'#'<t[j]
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<M])))

Fixed submission:
from scipy.sparse import*
e=enumerate
h,*s=open(0)
h,w=map(int,h.split())
r,c=[],[]
for i,t in e(s):
  for j,u in e(t):
    if u>'#'<t[j+1]:r+=i*w+j,;c+=i*w+j+1,
    if(i<h-1)*u>'#'<s[i+1][j]:r+=i*w+j,;c+=j-~i*w,    
print(int((csgraph.johnson(csr_matrix(([1]*len(r),(r,c)),[h*w]*2),0).clip(0,999)%999).max()))
Buggy python submission (verdict: Runtime Error):
n=int(input())
print(0--n//500)

Fixed submission:
print('YNeos'[eval(input().replace(' ','*500<'))::2])
Buggy python submission (verdict: Runtime Error):
from itertools import*
n,a,b=eval('eval(input().replace(" ",",")),'*3)
i=list(permutations(range(n+1))).index
print(abs(i(a)-i(b)))

Fixed submission:
from itertools import*;(n,),a,b=eval('tuple(map(int,input().split())),'*3);i=list(permutations(range(1,n+1))).index;print(abs(i(a)-i(b)))

Buggy python submission (verdict: Runtime Error):
from itertools import*
(n,),a,b=eval('eval(input().replace(" ",",")),'*3)
i=list(permutations(range(1,n+1))).index
print(abs(i(a)-i(b)))

Fixed submission:
from itertools import*;(n,),a,b=eval('tuple(map(int,input().split())),'*3);i=list(permutations(range(1,n+1))).index;print(abs(i(a)-i(b)))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import*
n,m,*a=map(int,open(0).read().split())
s=1
d=set()
for i in a:
  i//=2
  s*=i//gcd(s,i)
  t=0
  while i%2<1:t+=1
  d|={t}
print((0--(m//s)//2)*(len(d)<2))

Fixed submission:
from fractions import*
n,m,*a=map(int,open(0).read().split())
s=1
d=set()
for i in a:
  i//=2
  s*=i//gcd(s,i)
  t=0
  while i%2<1:
    t+=1
    i//=2
  d|={t}
print((0--(m//s)//2)*(len(d)<2))
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
print(t+s)

Fixed submission:
s,t=input().split();print(t+s)
Buggy python submission (verdict: Runtime Error):
*t,s=open(0).read().split()
n,k,r,s,p=map(int,t)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(s[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)

Fixed submission:
*n,t=open(0).read().split()
n,k,r,s,p=map(int,n)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(t[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)
Buggy python submission (verdict: Runtime Error):
int(input())

Fixed submission:
print('bwuisnt'[sum(map(int,input().split()))<22::2])

Buggy python submission (verdict: Runtime Error):
*a,=map(int,open(0))

Fixed submission:
print('bwuisnt'[sum(map(int,input().split()))<22::2])

Buggy python submission (verdict: Runtime Error):
a,b=map(int,open(0))
if a+b>21:
    print('No')
else:
    print('Yes')

Fixed submission:
print('bwuisnt'[sum(map(int,input().split()))<22::2])

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a+b>21:
    print('No')
else:
    print('Yes')

Fixed submission:
print('bwuisnt'[sum(map(int,input().split()))<22::2])
Buggy python submission (verdict: Runtime Error):
i=input
n=int(i())
a=eval('eval("list(map(int,i().split())),"*int(i())),'*n)
#print(max(all([y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t]+[1])*bin(i).count('1')for i in range(2**n)))

Fixed submission:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    if s[~j]:
      for x,y in t:f&=s[-x]==y
  m=max(m,sum(s)*f)
print(m)

Buggy python submission (verdict: Runtime Error):
i=input
n=int(i())
a=eval('eval("list(map(int,i().split())),"*int(i())),'*n)
print(max(all([y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t]+[1])*bin(i).count('1')for i in range(2**n)))

Fixed submission:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    if s[~j]:
      for x,y in t:f&=s[-x]==y
  m=max(m,sum(s)*f)
print(m)

Buggy python submission (verdict: Runtime Error):
i=input
n=int(i())
a=eval('eval("list(map(int,i().split())),"*int(i())),'*n)
print(max(all(y==i>>x-1&1for j,t in enumerate(a)if i>>j&1for x,y in t)*bin(i).count('1')for i in range(2**n)))

Fixed submission:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    if s[~j]:
      for x,y in t:f&=s[-x]==y
  m=max(m,sum(s)*f)
print(m)

Buggy python submission (verdict: Runtime Error):
i=input
n=int(i())
a=eval('eval("list(map(int,i().split())),"*int(i())),'*n)
print(max(all(all(y==i>>x-1&1for x,y in t)for j,t in enumerate(a)if i>>j&1)*bin(i).count('1')for i in range(2**n)))

Fixed submission:
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    if s[~j]:
      for x,y in t:f&=s[-x]==y
  m=max(m,sum(s)*f)
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):t=sum(2**i&b and 1for b in a);c+=t*(n-t)*2**i
print(c%(10**9+7))

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,*a=map(int,open(0).read().split())
  c=0
  for i in range(61):
    i=2**i
    t=sum(i&b>0for b in a)
    c=(c+t*(n-t)*i)%(10**9+7)
  print(c)
main()

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&b>0for b in a)
  c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(pow(2,i,M)*c*(n-c)%M for i,c in enumerate(b))%M)

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(pow(2,i,M)*c*(n-c)for i,c in enumerate(b))%M)

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))

Fixed submission:
n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))
Buggy python submission (verdict: Runtime Error):
n=int(input());print(+(n%100/(n//100)<=5))

Fixed submission:
n=int(input())
try:print(+(n%100/(n//100)<=5))
except:print(+(n<1))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
_,s=open(0)
dp=defaultdict(bool)
for c in s[:-1]:
  for i in range(100):
    j=str(i).zfill(2)
    dp[j+c]|=dp[j]
  for i in range(10):
    j=str(i)
    dp[j+c]|=dp[j]
  dp[c]=True
print(sum(dp[str(i).zfill(3)]for i in range(1000)))

Fixed submission:
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  for t in y:z.add(t+c)
  for t in x:y.add(t+c)
  x.add(c)
print(len(z))
Buggy python submission (verdict: Runtime Error):
_,a=open(0)
c=1
d=[3]+[0]*10**6
for a in map(int,a.split()):
  c=c*dp[a]%(10**9+7)
  d[a]-=1
  d[a]+=1
print(c)

Fixed submission:
n,*a=map(int,open(0).read().split())
c=1
d=[0]*3
for b in a:
  c=c*sum(t==b for t in d)%(10**9+7)
  for i,t in enumerate(d):
    if t==b:
      d[i]+=1
      break
print(c)
Buggy python submission (verdict: Runtime Error):
_,s=open(0)
for c in s[:-1]:print(chr(65+(ord(c)-65+n)%26),end='')

Fixed submission:
n=int(input())
print(''.join(chr((ord(c)+n-65)%26+65)for c in input()))
Buggy python submission (verdict: Runtime Error):
n,k,*a=map(int,open(0).read().split())
a=[0]+a
for i in range(n):a[i+1]=(a[i+1]-1+a[i])%k
d=[0]*k
c=0
for i,b in enumerate(a):
  c+=d[b]
  d[b]+=1
  if i-k>-2:d[a[i-k+1]]-=1
print(c)

Fixed submission:
n,k,*a=map(int,open(0).read().split())
a=[0]+a
for i in range(n):a[i+1]=(a[i+1]-1+a[i])%k
d={}
c=0
for i,b in enumerate(a):
  v=d.get(b,0)
  c+=v
  d[b]=v+1
  j=i-k+1
  if j>=0:d[a[j]]=d.get(a[j],0)-1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
m,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
a=0
flag=False
for d,c in z:
    if flag:
        m=[b]
    else:
        m=[]
        flag=True
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=sum(map(int,str(d)))
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=sum(map(int,str(d)))
            a+=1
    b=d
print(a)

Fixed submission:
m,*t=map(int,open(0).read().split())
a=b=0
for d,c in zip(*[iter(t)]*2):
    m=[b]
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=d//10+d%10
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=d//10+d%10
            a+=1
    b=d
print(a-1)
Buggy python submission (verdict: Runtime Error):
from numpy import*
N,T,*L=int64(open(0).read().split())
d=zeros(T*2,int)
for w,v in sorted(zip(*[iter(L)]*2)):d[w:T+w]=maximum(d[w:T+w],d[:T]+v)
print(max(d))

Fixed submission:
e=enumerate
(n,t),*g=[list(map(int,t.split()))for t in open(0)]
d=[0]
g.sort()
dp=[]
d=[0]*t
for a,b in g:
  p=d[:]
  for i in range(a,t):
    v=d[i-a]+b
    if v>p[i]:p[i]=v
  dp+=p,
  d=p
a=m=0
for(*_,v),(_,w)in zip(dp[-2::-1],g[::-1]):
  if w>m:m=w
  if v+m>a:a=v+m
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,*d=map(int,open(0).read().split())
  e=[0]*n
  for i in d:e[i]+=1
  a=1if d[0]<1else 0
  for i in d[1:]:a*=e[i-1]
  print(a%998244353)
main()

Fixed submission:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Buggy python submission (verdict: Time Limit Exceeded):
n,*d=map(int,open(0).read().split())
e=[0]*n
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Fixed submission:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Buggy python submission (verdict: Time Limit Exceeded):
_,d=open(0)
*d,=map(int,d.split())
e=[0]*10**5
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Fixed submission:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Buggy python submission (verdict: Time Limit Exceeded):
_,d=open(0)
*d,=map(int,d.split())
e=[0]*10**5
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Fixed submission:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,*t=map(int,open(0).read().split())
d=[0,0]+[1e18]*n
for l,r,c in sorted(zip(*[iter(t)]*3)):
 for i in range(r,l,-1):
  if d[l]+c<d[i]:d[i]=d[l]+c
  else:break
print(-(d[-2]>1e17)or d[-2])

Fixed submission:
from heapq import*
n,_,*t=map(int,open(0).read().split())
e=[[]for _ in'_'*n]
for l,r,c in zip(*[iter(t)]*3):e[l-1]+=(c,r-1),
for i in range(n-1):e[i+1]+=(0,i),
d=[0]+[1e18]*n
q=[(0,0)]
while q:
  c,v=heappop(q)
  for b,w in e[v]:
    if b+c<d[w]:
      d[w]=b+c
      heappush(q,(b+c,w))
print(-(d[-2]>1e17)or d[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,m,*t=map(int,open(0).read().split())
d=[0,0]+[1e18]*n
for l,r,c in sorted(zip(*[iter(t)]*3)):
 for i in range(r,l,-1):d[i]=min(d[i],d[l]+c)
print(-(d[-2]>1e17)or d[-2])

Fixed submission:
from heapq import*
n,_,*t=map(int,open(0).read().split())
e=[[]for _ in'_'*n]
for l,r,c in zip(*[iter(t)]*3):e[l-1]+=(c,r-1),
for i in range(n-1):e[i+1]+=(0,i),
d=[0]+[1e18]*n
q=[(0,0)]
while q:
  c,v=heappop(q)
  for b,w in e[v]:
    if b+c<d[w]:
      d[w]=b+c
      heappush(q,(b+c,w))
print(-(d[-2]>1e17)or d[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,m,*t=map(int,open(0).read().split())
d=[0,0]+[1e18]*n
for l,r,c in sorted(zip(*[iter(t)]*3)):
 for i in range(r,l,-1):d[i]=min(d[i],d[l]+c)
print(-(d[-2]>1e17)or d[-2])

Fixed submission:
from heapq import*
n,_,*t=map(int,open(0).read().split())
e=[[]for _ in'_'*n]
for l,r,c in zip(*[iter(t)]*3):e[l-1]+=(c,r-1),
for i in range(n-1):e[i+1]+=(0,i),
d=[0]+[1e18]*n
q=[(0,0)]
while q:
  c,v=heappop(q)
  for b,w in e[v]:
    if b+c<d[w]:
      d[w]=b+c
      heappush(q,(b+c,w))
print(-(d[-2]>1e17)or d[-2])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import*
n,*t=map(int,open(0).read().split())
*u,=range(n+1)
a=csgraph.johnson(csr_matrix(([0]*n+t[3::3],(u[1:]+t[1::3],u[:-1]+t[2::3])),[n+1]*2),1,1)[n]
print(int(a)if a<1e18else-1)

Fixed submission:
from heapq import*
n,_,*t=map(int,open(0).read().split())
e=[[]for _ in'_'*n]
for l,r,c in zip(*[iter(t)]*3):e[l-1]+=(c,r-1),
for i in range(n-1):e[i+1]+=(0,i),
d=[0]+[1e18]*n
q=[(0,0)]
while q:
  c,v=heappop(q)
  for b,w in e[v]:
    if b+c<d[w]:
      d[w]=b+c
      heappush(q,(b+c,w))
print(-(d[-2]>1e17)or d[-2])
Buggy python submission (verdict: Runtime Error):
s=input();print(max(0,int(s[:3])-2*int(s[3:])))

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

Buggy python submission (verdict: Runtime Error):
s=input();print(max(0,int(s[:2])-2*int(s[2:])))

Fixed submission:
a,b=map(int,input().split())
print(max(0,a-b-b))
Buggy python submission (verdict: Runtime Error):
from bisect import*
_,l=open(0)
*e,=enumerate(sorted(map(int,l.split())))
print(sum(j-bisect(l,a-b,0,j)for i,a in e for j,b in e[:i]))

Fixed submission:
from bisect import*
n,*l=map(int,open(0).read().split())
l.sort()
A=0
for i in range(n):
    a=l[i]
    for j in range(i+1,n):
        b=l[j]
        k1=max(j+1,bisect(l,b-a))
        k2=bisect_left(l,a+b)
        A+=max(0,k2-k1)
print(A)
Buggy python submission (verdict: Runtime Error):
from itertools import*
s,k=open(0)
k=int(k)
g=[len(list(v))for _,v in groupby(s)]
print(sum(c//2for c in g)*k+((s[0]==s[-2])*g[0]%2&g[-2]%2)*(k//2*(-len(s)~g[0])or k-1))

Fixed submission:
from itertools import*
s,k=open(0)
k,x=int(k),0
g=[len(list(v))for _,v in groupby(s)]
for c in g:x+=c//2
x*=k
if(s[0]==s[-2])*g[0]%2&g[-2]%2:x+=k//2if-len(s)==~g[0]else k-1
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n,a=open(0);print(*sorted(range(1,int(n)+1),key=lambda x:int(a.split()[x-1])))

Fixed submission:
n,a=open(0)
n=int(n)
b=[0]*int(n)
for i,t in enumerate(a.split()):b[int(t)-1]=i+1
print(*b)
Buggy python submission (verdict: Runtime Error):
from fractions import*
n=gcd(*map(int,input().split()))
a=1
i=2
while i*i<=n:
 a+=n%i<1
 while n%i<1:n//=i
 i+=1
print(ans+(n>1))

Fixed submission:
from subprocess import*
a,b=map(int,input().split())
x=set(map(int,Popen(['factor',str(a)],stdout=PIPE).communicate()[0].decode().split()[1:]))
y=set(map(int,Popen(['factor',str(b)],stdout=PIPE).communicate()[0].decode().split()[1:]))
print(len(x&y)+1)

Buggy python submission (verdict: Runtime Error):
from subprocess import*;a,b=[set(Popen(('factor',x),stdout=PIPE).stdout.read().split())for x in input().split()[1:]];print(len(a&b)+1)

Fixed submission:
from subprocess import*
a,b=map(int,input().split())
x=set(map(int,Popen(['factor',str(a)],stdout=PIPE).communicate()[0].decode().split()[1:]))
y=set(map(int,Popen(['factor',str(b)],stdout=PIPE).communicate()[0].decode().split()[1:]))
print(len(x&y)+1)