Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
food=[0 for i in range(m)]
for i in range(n):
  per=list(map(int,input().split()))
  for j in range(1,per[0]+1):
    food[per[j]]+=1
ans=0
for i in range(m):
  if food[i] == n:
    ans+=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
food=[0 for i in range(m)]
for i in range(n):
  per=list(map(int,input().split()))
  for j in range(1,per[0]+1):
    food[per[j]-1]+=1
ans=0
for i in range(m):
  if food[i] == n:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m = int(input())
a = []
b = [1 for i in range(m)]
for i in range(n):
  a.append(list(int(input()).split()))
for s in range(m):
  for i in range(n):
    if (s+1) in a[i] == False:
      b[s] = 0
cnt = 0
for d in range(len(b)):
  if b[d] = 1:
    cnt+= 1
print(cnt)

Fixed submission:
n,m=map(int,input().split())
food=[0 for i in range(m)]
for i in range(n):
  per=list(map(int,input().split()))
  for j in range(1,per[0]+1):
    food[per[j]-1]+=1
ans=0
for i in range(m):
  if food[i] == n:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n=int(input())
num=list(map(int,input().split()))
for i in range(len(num-1)):
  if i==0:
    ans=gcd(num[0],num[1])
  else:
    ans=gcd(ans,num[i+1])
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
num=list(map(int,input().split()))
for i in range(len(num)-1):
  if i==0:
    ans=gcd(num[0],num[1])
  else:
    ans=gcd(ans,num[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
map(int,input().split())
print(a/b)

Fixed submission:
a,b=map(int,input().split())
print(a/b)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=len(format(max(l),"b"))
x=[None]*n
xl=[0]*a
for i in range(n):
  b=format(l[i],"b")
  x[i]=b.zfill(a)
for i in range(a):
  for j in range(n):
    if x[j][i]=="1":
      xl[i]+=1
c=format(k,"b")
if len(c)>a:
  c,d=c[:len(c)-a],c[len(c)-a:]
  ans=int("0b"+c,2)*(2**a)*n
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
        ans+=xl[i]*(2**(a-i-1))
        check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
else:
  c=c.zfill(a)
  ans=0
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
        ans+=xl[i]*(2**(a-i-1))
        check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
print(ans)


Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=len(format(max(l),"b"))
x=[None]*n
xl=[0]*a
for i in range(n):
  b=format(l[i],"b")
  x[i]=b.zfill(a)
for i in range(a):
  for j in range(n):
    if x[j][i]=="1":
      xl[i]+=1
c=format(k,"b")
if len(c)>a:
  c,d=c[:len(c)-a],c[len(c)-a:]
  ans=int("0b"+c,2)*(2**a)*n
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
          ans+=xl[i]*(2**(a-i-1))
          check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
else:
  c=c.zfill(a)
  ans=0
  check=0
  for i in range(a):
    if check==0:
      if c[i]=="1":
        if xl[i]>=n-xl[i]:
          ans+=xl[i]*(2**(a-i-1))
          check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  while s % 2 == 0:
  s = s/2
  n += 1
  if s!=1 and s%2 == 1:
    s = 3*s+1
    n+=1
  if s == 1:
    print(n+2)
    break



Fixed submission:
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  s = 2*s
  while s % 2 == 0:
    s = s/2
    n += 1
    if s!=1 and s%2 == 1:
      s = 3*s+1
      n+=1
    if s == 1:
      print(n+1)
      break
Buggy python submission (verdict: Runtime Error):
n=int(input())
flowers=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  ans+=max(flowers[i+1]-flowers[i],0)
print(ans)

Fixed submission:
n=int(input())
flowers=[0]+list(map(int,input().split()))
ans=0
for i in range(n):
  ans+=max(flowers[i+1]-flowers[i],0)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
dp=[["" for i in range(len(t)+1)] for j in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=join(dp[i-1][j-1],s[i-1])
        else:
            A=len(dp[i-1][j])
            B=len(dp[i][j-1])
            if A>=B:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=dp[i][j-1]
print(dp[-1][-1])


Fixed submission:
n=int(input())
l=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(l[i]-l[i-2]),dp[i-1]+abs(l[i]-l[i-1]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
cost=[[0 for i in range(w+1)] for j in range(n+1)]
value=[tuple(map(int,input().split())) for i in range(n)]
for i in range(1,n+1):
  for j in range(w+1):
    weight_=value[i-1][0]
    value_=value[i-1][1]
    if j < weight_:
      cost[i][j]=cost[i-1][j]
    else:
      cost[i][j]=max(cost[i-1][j-weight_]+value_,cost[i-1][j])
print(cost[-1][-1])


Fixed submission:
n,w=map(int,input().split())
cost=[[0 for i in range(w+1)] for j in range(n+1)]
value=[tuple(map(int,input().split())) for i in range(n)]
for i in range(1,n+1):
  for j in range(w+1):
    weight_=value[i-1][0]
    value_=value[i-1][1]
    if j < weight_:
      cost[i][j]=cost[i-1][j]
    else:
      cost[i][j]=max(cost[i-1][j-weight_]+value_,cost[i-1][j])
print(cost[-1][-1])
Buggy python submission (verdict: Runtime Error):
D = int(input())
a_dict={22:Christmas Eve Eve Eve,23:Christmas Eve Eve,24:Christmas Eve,25:Christmas}
print(a_dict[D])

Fixed submission:
D = int(input())
a_dict={22:"Christmas Eve Eve Eve",23:"Christmas Eve Eve",24:"Christmas Eve",25:"Christmas"}
print(a_dict[D])
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
length=[0]*n;p=[0]*n
length[0]=1
p[0]=1
for i in range(1,n):
  length[i]=length[i-1]*2+3
  p[i]=p[i-1]*2+1
def meat(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1+length[i-1]:
    return meat(n-1,x-1)
  elif x==2+length[i-1]:
    return p[n-1]+1
  else:
    return p[n-1]+1+meat(n-1,x-length[n-1]-2)
print(meat(n,x))

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
pre="P"
for i in range(1,n):
  cur="B"+pre+"P"+pre+"B"
  pre=cur
print(cur[:k].count("P"))

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
burger=[None]*n
burger[0]="P"
for i in range(1,n):
  burger[i]="B"+burger[i-1]+"P"+burger[i-1]+"B"
print(sum(1 for i in burger[-1][:k] if i=="P"))

Fixed submission:
n,x=map(int,input().split())
length=[0]*n;p=[0]*n
length[0]=1
p[0]=1
for i in range(1,n):
  length[i]=length[i-1]*2+3
  p[i]=p[i-1]*2+1
def meat(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1+length[n-1]:
    return meat(n-1,x-1)
  elif x==2+length[n-1]:
    return p[n-1]+1
  else:
    return p[n-1]+1+meat(n-1,x-length[n-1]-2)
print(meat(n,x))
Buggy python submission (verdict: Runtime Error):
s=input()
ans=1000
l=len(s)
for i in range(l-2):
  if ans>abs(753-s[i:i+3]):
    ans=abs(753-s[i:i+3])
print(ans)

Fixed submission:
s=input()
ans=1000
l=len(s)
for i in range(l-2):
  if ans>abs(753-int(s[i:i+3])):
    ans=abs(753-int(s[i:i+3]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
t,a = map(int,input().split())
height = [int(input()) for i in range(N)]
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
print(min(subduction)) 


Fixed submission:
N = int(input())
t,a = map(int,input().split())
height = list(map(int,input().split()))
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
ans = float(10**7)
lst = []
for i in range(N):
  if ans > subduction[i]:
    ans = subduction[i]
    lst.append(i)
print(lst[-1]+1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
height = [int(input()) for i in range(N)]
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
print(min(subduction)) 

Fixed submission:
N = int(input())
t,a = map(int,input().split())
height = list(map(int,input().split()))
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
ans = float(10**7)
lst = []
for i in range(N):
  if ans > subduction[i]:
    ans = subduction[i]
    lst.append(i)
print(lst[-1]+1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
cities=[[] for i in range(n)]
for i in range(1,m+1):
  p,y=map(int,input().split())
  cities[p-1].append(y)
  print(format(str(p),"0>6")+format(str(len(cities[p-1],"0>6"))))
  

Fixed submission:
import sys
n,m=map(int,input().split())
if m==1:
  a,b=map(int,input().split())
  print(str(a).zfill(6)+str(m).zfill(6));sys.exit()
cities=[None]*m
for i in range(m):
  p,y=map(int,input().split())
  cities[i]=[p,y,i]
cities.sort(key=lambda x:x[1]);cities.sort(key=lambda x:x[0])
i=0
c=1
while True:
  cities[i].append(c)
  c+=1
  if i!=m-1 and cities[i][0]!=cities[i+1][0]:c=1
  elif i==m-1:break
  i+=1
cities.sort(key=lambda x:x[2])
for i in cities:
  print(str(i[0]).zfill(6)+str(i[3]).zfill(6))
Buggy python submission (verdict: Runtime Error):
print(input() if len(input())==2 else input()[::-1])

Fixed submission:
a=input()
print(a if len(a)==2 else a[::-1])
Buggy python submission (verdict: Runtime Error):
from math import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
ans=n*m//g
stepn=n//g
stepm=m//g
for i in range(g):
    if s[stepn*i]!=t[stepm*i]:print(-1);exit()
print(ans)

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
ans=n*m//g
stepn=n//g
stepm=m//g
for i in range(g):
    if s[stepn*i]!=t[stepm*i]:print(-1);exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
info=[list(map(int,input().split())) for i in range(N)]
info.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    height=info[0][2]+abs(info[0][0]-i)+abs(info[0][1]-j)
    for h in range(1,N):
      if info[h][2]+abs(info[h][0]-i)+abs(info[h][1]-j)!=height;break
    print(i,j,height);exit()

Fixed submission:
n=int(input())
data=[list(map(int,input().split())) for i in range(n)]
data.sort(key=lambda x:x[2],reverse=True)
def cal(y,x,datum,height):
  return max(height-(abs(y-datum[1])+abs(x-datum[0])),0)==datum[2]
for i in range(101):
  for j in range(101):
    height=abs(i-data[0][1])+abs(j-data[0][0])+data[0][2]
    flag=0
    for k in data[1:]:
      if not cal(i,j,k,height):
        flag=1
        break
    if flag:pass
    else:print(j,i,height);exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = 111
for i in range(9):
  if a*i < n <= a*(i+1)
  print(a*(i+1))

Fixed submission:
n = int(input())
a = 111
for i in range(9):
  if a*i < n <= a*(i+1):
    print(a*(i+1))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common[1][1]-o.most_common[0][1],e.most_common[1][1]-e.most_common[0][1]))
  else:  
    print(ans)


Fixed submission:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common()[0][1]-o.most_common()[1][1],e.most_common()[0][1]-e.most_common()[1][1]))
  else:  
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common[0][0]==e.most_common[0][0]:
    print(ans+min(o.most_common[1][1]-o.most_common[0][1],e.most_common[1][1]-e.most_common[0][1]))
  else:  
    print(ans)


Fixed submission:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common()[0][1]-o.most_common()[1][1],e.most_common()[0][1]-e.most_common()[1][1]))
  else:  
    print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter as c
s=input()
t=input()
if sorted(s.values())==sorted(t.values()):
  print("Yes")
else:
  print("No")

Fixed submission:
from collections import Counter as c
s=input()
S=c(s)
t=input()
T=c(t)
if sorted(S.values())==sorted(T.values()):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
sum=0
i=0
while sum<m:
  sum+=ch[ans]
  ans+=1
  if sum > m:
    ans-=1
    break
print(ans)

Fixed submission:
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
if m>sum(ch):
  print(n-1)
else:
  sum=0
  i=0
  while sum<m and ans!=n:
    sum+=ch[ans]
    ans+=1
    if sum > m:
      ans-=1
      break
  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
shiritori = [list(input()) for i in range(n)]
for i in range(n-1):
  if shiritori[i][-1] != shiritori[i+1][0]:
    print("No")
    break
  if i =n-2:
    print("Yes")

Fixed submission:
n=int(input())
shiritori=[]
for i in range(n):
  shiritori.append(input())
check=set(shiritori)
if len(check)!=n:
  print("No")
else:
  flag=0
  for i in range(n-1):
    if shiritori[i][-1]!=shiritori[i+1][0]:
      flag=1
      break
  if flag==0:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  lit=c[i:i+k]
  if lit[0]*lit[-1]>0:
    d=abs(lit[0])+abs(lit[-1])+min(abs(lit[0]),abs(lit[-1]))
  else:
    d=max(abs(lit[0],abs(lit[-1])))
  if d<ans:
    ans=d
print(ans)


Fixed submission:
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  l,r=i,i+k-1
  d=min(abs(c[l]),abs(c[r]))+abs(c[l]-c[r])
  if d<ans:
    ans=d
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  lit=c[i:i+k]
  if lit[0]*lit[-1]>0:
    d=abs(lit[0])+abs(lit[-1])+min(abs(lit[0]),abs(lit[-1]))
  else:
    d=max(abs(lit[0],abs(lit[-1])))
  if d<ans:
    d=ans
print(ans)

Fixed submission:
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  l,r=i,i+k-1
  d=min(abs(c[l]),abs(c[r]))+abs(c[l]-c[r])
  if d<ans:
    ans=d
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s=input()
a=len(s)
counter = Counter(s[2:a-2])
if s[0]!="A":
  print("WA")
  break
else:
  if counter("C")!=1:
    print("WA")
else:
  s.replace("A","a",1)
  s.replace("C","c",1)
  if s.islower()==False:
    print("WA")
  else:
    print("AC")

Fixed submission:
from collections import Counter
s=input()
a=len(s)
counter = Counter(s[2:a-1])
if s[0]!="A":
  print("WA")
  
elif counter["C"]!=1:
  
    print("WA")
else:
  
  s[1:].replace("C","c",1)
  if s[1:].replace("C","c",1).islower()==False:
    print("WA")
  else:
    print("AC")
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
mod=10**9+7
retnum={"?":0,"A":1,"B":2,"C":3}
count=[[0 for i in range(len(s))] for j in range(4)]
for i in range(len(s)):
    for j in range(4):
        if retnum[s[i]] == j:
            count[j][i]=count[j][i-1]+1
        else:
            count[j][i]=count[j][i-1]
ans=0
for i in range(1,len(s)-1):
    if s[i]=="B" or s[i]=="?":
        ans+=((3**(max(0,count[0][i-1]-1)))*count[0][i-1]+(3**count[0][i-1])*count[1][i-1])*(3**(max(0,count[0][-1]-count[0][i]-1))*(count[0][-1]-count[0][i])+(3**(count[0][-1]-count[0][i]))*(count[3][-1]-count[3][i]))
        ans%=mod
print(ans)

Fixed submission:
s=input()
mod=10**9+7
retnum={"?":0,"A":1,"B":2,"C":3}
count=[[0 for i in range(len(s))] for j in range(4)]
for i in range(len(s)):
    for j in range(4):
        if retnum[s[i]] == j:
            count[j][i]=count[j][i-1]+1
        else:
            count[j][i]=count[j][i-1]
ans=0
g=[1]*100002
for i in range(1,100002):
    g[i]=g[i-1]*3
    g[i]%=mod
for i in range(1,len(s)-1):
    if s[i]=="B" or s[i]=="?":
        ans+=(g[max(0,count[0][i-1]-1)]*count[0][i-1]+g[count[0][i-1]]*count[1][i-1])*(g[max(0,count[0][-1]-count[0][i]-1)]*(count[0][-1]-count[0][i])+g[count[0][-1]-count[0][i]]*(count[3][-1]-count[3][i]))
        ans%=mod
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
mod=10**9+7
retnum={"?":0,"A":1,"B":2,"C":3}
count=[[0 for i in range(len(s))] for j in range(4)]
for i in range(len(s)):
    for j in range(4):
        if retnum[s[i]] == j:
            count[j][i]=count[j][i-1]+1
        else:
            count[j][i]=count[j][i-1]
ans=0
for i in range(1,len(s)-1):
    if s[i]=="B" or s[i]=="?":
        ans+=((3**(count[0][i-1]-1))*count[0][i-1]+(3**count[0][i-1])*count[1][i-1])*(3**(count[0][-1]-count[0][i]-1)*(count[0][-1]-count[0][i])+(3**(count[0][-1]-count[0][i]))*(count[3][-1]-count[3][i]))
        ans%=mod
print(ans)

Fixed submission:
s=input()
mod=10**9+7
retnum={"?":0,"A":1,"B":2,"C":3}
count=[[0 for i in range(len(s))] for j in range(4)]
for i in range(len(s)):
    for j in range(4):
        if retnum[s[i]] == j:
            count[j][i]=count[j][i-1]+1
        else:
            count[j][i]=count[j][i-1]
ans=0
g=[1]*100002
for i in range(1,100002):
    g[i]=g[i-1]*3
    g[i]%=mod
for i in range(1,len(s)-1):
    if s[i]=="B" or s[i]=="?":
        ans+=(g[max(0,count[0][i-1]-1)]*count[0][i-1]+g[count[0][i-1]]*count[1][i-1])*(g[max(0,count[0][-1]-count[0][i]-1)]*(count[0][-1]-count[0][i])+g[count[0][-1]-count[0][i]]*(count[3][-1]-count[3][i]))
        ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input()) 
num=list(int,input().split())
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dif=abs(num[i]-num[j])
    if dif>ans:
      ans=dif
print(ans)

Fixed submission:
n=int(input()) 
num=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dif=abs(num[i]-num[j])
    if dif>ans:
      ans=dif
print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
l=len(n)
s=0
for i in range(l):
  s+=int(n[i])
if n%s==0:
  print("Yes")
else:
  print("No")

Fixed submission:
n=input()
l=len(n)
s=0
for i in range(l):
  s+=int(n[i])
if int(n)%s==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
if n<=3:
  print(1)
else:
  ans=4
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**e>ans:
        ans=i**e
        e+=1
  print(ans)


Fixed submission:
n=int(input())
if n<=3:
  print(1)
else:
  ans=[]
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**(e+1)>n:
        ans.append(i**e)
        break
      e+=1
  print(max(ans))

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<=3:
  print(1)
else:
  ans=4
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**e>ans:
        ans=i**e
print(ans)

Fixed submission:
n=int(input())
if n<=3:
  print(1)
else:
  ans=[]
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**(e+1)>n:
        ans.append(i**e)
        break
      e+=1
  print(max(ans))
Buggy python submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]
 
    def merge(self, a, b):
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
    
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r
n,m=map(int,input().split())
a=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  if a>b:a,b=b,a
  uf.merge(a-1,b-1)
print(sum(1 for i in range(n) if uf.parent[i]==uf.parent[a[i]-1]))

Fixed submission:
n,m=map(int,input().split())
p=list(map(int,input().split()))
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for i in range(N)]
    
    def merge(self, a, b):
        if self.issame(a,b):
            return
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
        self.size[pb] += self.size[pa]
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r
    
    def issame(self, x, y):
        return self.root(x) == self.root(y)
    
    def getsize(self, x):
        return self.size[self.root(x)]

uf=UnionFind(2*n)
for i in range(n):
    uf.merge(i,p[i]+n-1)
for i in range(m):
    x,y=map(int,input().split())
    x-=1;y-=1
    uf.merge(x,y)
ans=0
for i in range(n):
    ans+=int(uf.issame(i,i+n))
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
n=int(input())
lst=[]
for i in range(len(s)):
  for j in range(i+1,min(i+n+1,len(s)+1)):
    lst.append(s[i:j])
sub=set(lst)
sub.sort()
print(sub[n-1])

Fixed submission:
s=input()
n=int(input())
lst=[]
for i in range(len(s)):
  for j in range(i+1,min(i+n+1,len(s)+1)):
    lst.append(s[i:j])
sub=set(lst)
sub=sorted(sub)
print(sub[n-1])