Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  if k-i>n-2:
    for i in range(n):
      a[i]=n
    for i in a:
      print(i,end=' ')
    sys.exit()
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  cnt=0
  for j in range(n):
    if a[j]>=max(n-j,j)
    cnt+=1
  if cnt==n:
    for j in range(n):
      a[j]=(k-i)*n
    break
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  cnt=0
  for j in range(n):
    if a[j]>=max(n-j,j)
    cnt+=1
  if cnt==n:
    for i in j in range(n):
      a[j]=(k-i)*n
    break
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  if min(a)>=n:
    for j in range(n):
      a[j]+=k-i      
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k):
  b=[0]*n
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)
Buggy python submission (verdict: Runtime Error):
a,b=map(float,input().split())
b*=100
a,b=map(int,(a,b))
print(a*b//100)a,b=map(float,input().split())
b*=100
a,b=map(int,(a,b))
print(a*b//100)

Fixed submission:
a,b=input().split()
a=int(a)
b,c=map(int,b.split('.'))
print(a*(b*100+c)//100)
Buggy python submission (verdict: Time Limit Exceeded):
x=int(input())
for i in range(int(x**.5+1)):
  for j in range(-int((x**.5+1)),int(x**.5+1)):
    if i**5-j**5==x:
      print(i,j)
      exit()

Fixed submission:
x=int(input())
for i in range(int(x**.3+1)):
  for j in range(-int((x**.3+1)),int(x**.3+1)):
    if i**5-j**5==x:
      print(i,j)
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n,m,q=map(int,input().split())
a=[]
for i in range(q):
  a.append(list(map(int,input().split())))
ans=0
data=set([''.join(list(i)) for i in list(permutations('1'*(m-1)+'0'*n))])
for i in data:
  s=[1]*(n+1)
  cnt=0
  k=0
  for j in range(n+m-1):
    if i[j]=='1':s[k]+=1
    else:
      s[k+1]=s[k]
      k+=1
  for x,y,z,w in a:
    if s[y-1]-s[x-1]==z:cnt+=w
  ans=max(ans,cnt)
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
  a=[1]
  for j in range(m+n):
    if (i>>j)&1:a[-1]+=1
    else:a+=[a[-1]]
    if a[-1]>m:
      flag=0
      break
    if len(a)>n:
      flag=1
      break
  else:flag=1
  if flag==0 or len(a)<n:continue
  cnt=0
  for s,t,u,v in e:
    if a[t-1]-a[s-1]==u:cnt+=v
  ans=max(ans,cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n,m,q=map(int,input().split())
a=[]
for i in range(q):
  a.append(list(map(int,input().split())))
ans=0
data=set([''.join(list(i)) for i in list(permutations('1'*(m-1)+'0'*n))])
for i in data:
  s=[1]*(n+1)
  cnt=0
  k=0
  for j in range(n+m-1):
    if i[j]=='1':s[k]+=1
    else:
      s[k+1]=s[k]
      k+=1
  for x,y,z,w in a:
    if s[y-1]-s[x-1]==z:cnt+=w
  ans=max(ans,cnt)
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
  a=[1]
  for j in range(m+n):
    if (i>>j)&1:a[-1]+=1
    else:a+=[a[-1]]
    if a[-1]>m:
      flag=0
      break
    if len(a)>n:
      flag=1
      break
  else:flag=1
  if flag==0 or len(a)<n:continue
  cnt=0
  for s,t,u,v in e:
    if a[t-1]-a[s-1]==u:cnt+=v
  ans=max(ans,cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n,m,q=map(int,input().split())
a=[]
for i in range(q):
  a.append(list(map(int,input().split())))
ans=0
data=set([''.join(list(i)) for i in list(permutations('1'*(m-1)+'0'*n))])
for i in data:
  s=[1]*(n+m)
  cnt=0
  t=[]
  for j in range(n+m-1):
    if i[j]=='1':s[j]+=1
    else:t.append(s[j])
    s[j+1]=s[j]
  for x,y,z,w in a:
    if t[y-1]-t[x-1]==z:cnt+=w
  ans=max(ans,cnt)
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
  a=[1]
  for j in range(m+n):
    if (i>>j)&1:a[-1]+=1
    else:a+=[a[-1]]
    if a[-1]>m:
      flag=0
      break
    if len(a)>n:
      flag=1
      break
  else:flag=1
  if flag==0 or len(a)<n:continue
  cnt=0
  for s,t,u,v in e:
    if a[t-1]-a[s-1]==u:cnt+=v
  ans=max(ans,cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
d=dict(zip(list(range(2019)),[0]*2019))
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
d=dict(zip(list(range(2019)),[0]*2019))
d[0]=1
j=1
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  d[now]+=1
  j*=10
ans=0
for _,i in d.items():
  ans+=i*(i-1)//2
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
d=dict(zip(list(range(2019)),[0]*2019))
i=1
while i//10<=s:
  d[s%i%2019]+=1
  i*=10
ans=0
for _,i in d.items():
  ans+=i*(i-1)//2
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
d=dict(zip(list(range(2019)),[0]*2019))
i=0
while 10**(i-1)<=s:
  d[s%10**i%2019]+=1
  i+=1
ans=0
for _,i in d.items():
  ans+=i*(i-1)//2
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
d=dict(zip(list(range(2019)),[0]*2019))
for i in range(n):
  d[int(s[i:])%2019]+=1
ans=0
for _,i in d.items():
  ans+=i*(i-1)//2
ans+=d[0]
print(ans)

Fixed submission:
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)
Buggy python submission (verdict: Runtime Error):
print(int(input()/3)**3)

Fixed submission:
print((int(input())/3)**3)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
flag=0
t=['' for _ in range(2)]
cnt=0
for _ in range(q):
  a=list(input().split())
  if a[0]=='1':
    flag=1-flag
    cnt+=1
  else:
    if a[1]=='1':t[flag]+=a[2]
    else:t[1-flag]+=a[2]
if cnt%2:ans=t[1][::-1]+s[::-1]+t[0]
else:ans=t[0][::-1]+s+t[1]
print(ans)

Fixed submission:
s=input()
q=int(input())
flag=0
t=['' for _ in range(2)]
cnt=0
for _ in range(q):
  a=list(input().split())
  if a[0]=='1':
    flag=1-flag
    cnt+=1
  else:
    if a[1]=='1':t[flag]+=a[2]
    else:t[1-flag]+=a[2]
ans=t[0][::-1]+s+t[1]
if cnt%2:ans=ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=[s for s in input()]
q=int(input())
for _ in range(q):
  a=list(input().split())
  if a[0]=='1':s=s[::-1]
  else:
    if a[1]=='1':s=[a[2]]+s
    else:s+=[a[2]]
print(''.join(s))

Fixed submission:
s=input()
q=int(input())
flag=0
t=['' for _ in range(2)]
cnt=0
for _ in range(q):
  a=list(input().split())
  if a[0]=='1':
    flag=1-flag
    cnt+=1
  else:
    if a[1]=='1':t[flag]+=a[2]
    else:t[1-flag]+=a[2]
ans=t[0][::-1]+s+t[1]
if cnt%2:ans=ans[::-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[s for s in input()]
for _ in range(int(input())):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1:s[b-1]=c
  else:print(len(set(s[b-1:int(c)])))

Fixed submission:
def segfunc(x,y):
  return set(x)|set(y)
ide_ele=set()
class SegTree():
  def __init__(self,init_val,segfunc,ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n=int(input())
s=input()
q=int(input())
st=SegTree(s,segfunc,ide_ele)
for _ in range(q):
  q,c,r=input().split()
  if q=='1':st.update(int(c)-1,r)
  else:print(len(st.query(int(c)-1,int(r))))
Buggy python submission (verdict: Runtime Error):
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][k==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]
    if s[i]!='0':dp[i][j][1]+=dp[i-1][j][0]
print(sum(dp[-1][-1]))

Fixed submission:
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][m==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]
    if s[i]!='0':dp[i][j][1]+=dp[i-1][j][0]
print(sum(dp[-1][-1]))

Buggy python submission (verdict: Runtime Error):
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][k==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]+dp[i-1][j][0]
print(sum(dp[-1][-1]))

Fixed submission:
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][m==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]
    if s[i]!='0':dp[i][j][1]+=dp[i-1][j][0]
print(sum(dp[-1][-1]))
Buggy python submission (verdict: Runtime Error):
from bisect import*
INF=10**18
n,d,a=map(int,input().split())
mon=[]
for _ in range(n):
  mon+=[list(map(int,input().split()))]
mon.sort()
i=0
ans=0
while i<n:
  j=bisect_left(mon,[mon[i][0]+2*d+1,INF])
  h=max(mon[i:j],key=lambda x:x[1])[1]
  if h!=mon[j-1][1] or i==j-1:
    ans+=(b+a-1)//a
    i=j
  else:
    h=max(mon[i:j-1],key=lambda x:x[1])[1]
    ans+=(h+a-1)//a
    mon[j-1][1]-=(h+a-1)//a*a
    if mon[j-1][1]>0:i=j-1
    else:i=j
print(ans)

Fixed submission:
from collections import*
INF=10**18
n,d,a=map(int,input().split())
mon=[]
for _ in range(n):
  mon+=[list(map(int,input().split()))]
mon.sort()
ans=0
tot=0
q=deque()
for i in range(n):
  x,h=mon[i]
  while q and q[0][0]<x:
    tot-=q.popleft()[1]
  h-=tot
  if h>0:
    b=(h+a-1)//a
    tot+=b*a
    ans+=b
    q.append((x+2*d,b*a))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import *
from functools import reduce
def lcm(a,b):
  return a*b//gcd(a,b)
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
c=reduce(lcm,a)
ans=0
for i in a:
  ans+=c//i%mod
  ans%=mod
print(ans)

Fixed submission:
from math import gcd
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
c=a[0]
for i in a[1:]:
  c=c*i//gcd(c,i)
ans=0
c%=mod
for i in a:
  ans+=c*pow(i,mod-2,mod)
  ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
  x,l=map(int,input().split())
  a.append(list(range(x-l+1,x+l)))
ans=[]
while(len(a)):
  b=[]
  for i in a:
    b.append(i[-1])
  bi=b.index(min(b))
  bm=b.pop(bi)
  am=a.pop(bi)
  ans.append(am)
  for i in a:
    if bm in i:
      a.remove(i)
      
print(len(ans))

Fixed submission:
n=int(input())
itv=[]
for i in range(n):
  x,l=map(int,input().split())
  itv+=[(x+l,x-l)]
itv=sorted(itv)
l=-10**18
cnt=0
for t,s in itv:
  if l<=s:
    l=t
    cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
b=''
c=[]
d=[]
cnt=0
for i in range(n):
  if s[i] in b:continue
  b+=s[i]
  for j in range(i+1,n):
    if s[i]+s[j] in c:continue
    c+=s[i]+s[j]
    for k in range(j+1,n):
      if s[i]+s[j]+s[k] not in d:
        cnt+=1
        d.append(s[i]+s[j]+s[k])
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
a=[]
b=[]
c=[]
for i in range(n):
  d=s[i]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    e=s[i]+s[j]
    if e in c:continue
    else:c.append(e)
    for k in range(j+1,n):
      f=s[i]+s[j]+s[k]
      if f not in a:
        a.append(f)
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
a=[]
b=[]
c=[]
for i in range(n):
  d=s[i]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    d=s[i]+s[j]
    if d in c:continue
    else:c.append(d)
    for k in range(j+1,n):
      e=s[i]+s[j]+s[k]
      if e not in a:
        a.append(e)
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
cnt=0
a=[]
b=[]
for i in range(n):
  d=s[i]+s[j]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    for k in range(j+1,n):
      c=s[i]+s[j]+s[k]
      if c not in a:
        a.append(c)
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
a=[]
b=[]
for i in range(n):
  for j in range(i+1,n):
    d=s[i]+s[j]
    if d in b:continue
    else:b.append(d)
    for k in range(j+1,n):
      c=s[i]+s[j]+s[k]
      if c not in a:
        a.append(c)
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0

a=[]
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      c=s[i]+s[j]+s[k]
      if c not in a:
        a.append(c)
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
b=[0,0,0]
ans=1
for i in a:
  ans*=b.count(i)
  b[b.index(i)]+=1
print(ans%mod)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  b[b.index(i)]+=1
print(ans%m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[-1]*3
ans=1
for i in a:
  ans*=b.count(i-1)
  ans%=m
  b[b.index(i-1)]+=1
print(ans%m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[-1]*3
ans=1
for i in a:
  ans*=b.count(i-1)
  ans%=m
  b[b.index(i-1)]+=1
print(ans%m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[-1]*3
ans=1
for i in range(0,n):
  j=a[i]
  ans*=(b.count(j-1))
  ans%=m
  b[b.index(j-1)]+=1
print(ans%m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[-1]*3
ans=1
for i in range(0,n):
  j=a[i]
  ans*=(b.count(j-1))
  b[b.index(j-1)]+=1
print(ans%m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
b=[0]*3
ans=1
for i in a:
  ans*=b.count(i)
  ans%=m
  for j in range(3):
    if b[j]==i:
      b[j]+=1
      break
print(ans%m)
Buggy python submission (verdict: Runtime Error):
n=int(input())
frag='No'
for i in range(9):
  if n/(i+1)%1==0:
    frag='Yes
print(frag)

Fixed submission:
n=int(input())
frag='No'
for i in range(9):
  if n/(i+1)%1==0 and n/(i+1)<=9:
    frag='Yes'
print(frag)
Buggy python submission (verdict: Runtime Error):
n=int(input())
mn=n
for i in range(n):
  if n%i==0:
    j=n//i
    mn=min(mn,i+j)
print(mn)

Fixed submission:
N=int(input())
move=10**12
for n in range(1,int(N**.5)+1):
    if N%n==0:
        move=min(move,N//n+n-2)
print(move)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
n=int(input())
s=[input() for _ in range(n)]
e=[[]for _ in range(n)]
INF=10**18
for i,x in enumerate(s):
  for j,y in enumerate(x):
    if y=='1':e[i]+=[j]
ans=0
for i in range(n):
  d=[INF]*n
  q=deque([(i,1)])
  while q:
    now,c=q.popleft()
    d[now]=c
    for to in e[now]:
      if d[to]==INF:
        q+=[(to,c+1)]
      elif d[to]!=c+1 and d[to]!=c-1:
        print(-1)
        exit()
  ans=max(max(d),ans)
print(ans)

Fixed submission:
from collections import*
n=int(input())
s=[input() for _ in range(n)]
e=[[]for _ in range(n)]
INF=10**18
for i,x in enumerate(s):
  for j,y in enumerate(x):
    if y=='1':e[i]+=[j]
ans=0
for i in range(n):
  d=[INF]*n
  q=deque([i])
  d[i]=1
  while q:
    now=q.popleft()
    for to in e[now]:
      if d[to]==INF:
        q+=[to]
        d[to]=d[now]+1
      elif d[to]!=d[now]+1 and d[to]!=d[now]-1:
        print(-1)
        exit()
  ans=max(max(d),ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
x=0
while True:
  if x*(a-1)+1>=b: break
  else: x=+1
print(x)

Fixed submission:
a,b=map(int,input().split())
x=0
while True:
  if x*(a-1)+1>=b: break
  else: x+=1
print(x)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
x=0
while True:
  if x*(a-1)+1>=b: break
  else x=+1
print(x)

Fixed submission:
a,b=map(int,input().split())
x=0
while True:
  if x*(a-1)+1>=b: break
  else: x+=1
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for _ in range(n)]
alp=[chr(ord('a')+i) for i in range(26)]
sc=[[0] for _ in range(n)]
for i in range(n):
  for j in alp:
    sc[i].append(s[i].count(j))
cnt=0

for i in range(n):
  cnt+=sc.count(sc[0])-1
  sc.pop(0)
print(cnt)

Fixed submission:
from collections import Counter
n=int(input())
s=[]
for _ in range(n):
  s.append(''.join(sorted([i for i in input()])))
s=Counter(s)
ans=0
for i in Counter(s).values():
  ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(i+1,n):
    for k in s[i]:
      if s[j].count(k)!=s[i].count(k):
        break
    else:
      cnt+=1
print(cnt)

Fixed submission:
from collections import Counter
n=int(input())
s=[]
for _ in range(n):
  s.append(''.join(sorted([i for i in input()])))
s=Counter(s)
ans=0
for i in Counter(s).values():
  ans+=i*(i-1)//2
print(ans)