Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().split())
sa,ss=[input() for i in range(2)]
if a<s:
    a,s=s,a
    sa,ss=ss,sa
from math import gcd
g=gcd(a,s)
x,y=a//g,s//g
for i in range(1,s//x):
    if sa[y*i]!=ss[x*i]:print(-1);break
else:print(x*s)

Fixed submission:
a,s=map(int,input().split())
sa,ss=[input() for i in range(2)]
if a<s:
    a,s=s,a
    sa,ss=ss,sa
from fractions import gcd
g=gcd(a,s)
x,y=a//g,s//g
for i in range(g):
    if sa[x*i]!=ss[y*i]:print(-1);break
else:print(x*s)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==1:print("Hello world")
else:
    a,s=map(int,input().split())
    print(a+s)

Fixed submission:
n=int(input())
if n==1:print("Hello World")
else:
    a,s=int(input()),int(input())
    print(a+s)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=1
for i in range(1,int(m**(1/2))+1):
    if m%i==0:
        if i>=n:ans=max(m//i*,ans)
        if m//i>=n:
            ans=max(i,ans)
print(ans)

Fixed submission:
n,m=map(int,input().split())
ans=1
ps=[]
for i in range(1,int(m**(1/2))+1):
    if m%i:continue
    if n*(i)<=m:ans=max(i,ans)
    if n*(m//i)<=m:ans=max(ans,m//i)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
for i in range(n,m):
    if m%i:continue
    print(m//i);exit()
print(1)


Fixed submission:
n,m=map(int,input().split())
ans=1
ps=[]
for i in range(1,int(m**(1/2))+1):
    if m%i:continue
    if n*(i)<=m:ans=max(i,ans)
    if n*(m//i)<=m:ans=max(ans,m//i)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
for i in range(n,m):
    if m%i:continue
    print(m//i);exit()
print(1)

Fixed submission:
n,m=map(int,input().split())
ans=1
ps=[]
for i in range(1,int(m**(1/2))+1):
    if m%i:continue
    if n*(i)<=m:ans=max(i,ans)
    if n*(m//i)<=m:ans=max(ans,m//i)
print(ans)
Buggy python submission (verdict: Runtime Error):
s,t=input(),input()
ss,ts=[set()for i in range(26)],[set()for i in range(26)]
sc={}
tc={}
for i in range(len(s)):
    if s[i]not in sc:
        if t[i] in tc:print("No");exit()
        else:
            d=len(sc)
            ss[d].add(i)
            ts[d].add(i)
            tc[t[i]]=d
            sc[s[i]]=d
    else:
        if sc[s[i]]!=tc[t[i]]:print("No");exit()
        else:
            ss[sc[s[i]]].add(i)
            ts[sc[s[i]]].add(i)
for i in range(26):
    if ss[i]!=ts[i]:print("No");break
else:print("Yes")

Fixed submission:
s=input();d=input();n=len(s)
di={"abcdefghijklmnopqrstuvwxyz"[i]:i for i in range(26)}
sl,dl=[set() for _ in range(26)],[set() for _ in range(26)]
for i,(x,y) in enumerate(zip(s,d)):
  sl[di[x]].add(i);dl[di[y]].add(i)
for i in dl:
  if i and i not in sl :print("No");exit() 
print("Yes")
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))

now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(max(0,br(d,x)-1+(sum(l)==x)))

Fixed submission:
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
if sum(l)<=x:print(n-int(sum(l)!=x));exit()
if l[0]>x:print(0);exit()
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(br(d,x))
Buggy python submission (verdict: Runtime Error):
print(len([1 for i in [104,134,164,188,194] if i<int(input())]))

Fixed submission:
s=[]
for i in range(201)[105::2]:
  d=1;k=i
  for h in range(2,i+1):
    if i%h==0:
      cnt=0
      while i%h==0:
        cnt+=1
        i//=h
      d*=(cnt+1)
  if d==8:
    s.append(k)
ans=0;n=int(input())
for f in s:
  if n>=f:ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a=[int(input().split())]
print(max(a)-min(a))

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

Buggy python submission (verdict: Runtime Error):
a=list(int(input().split()))
print(max(a)-min(a))

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

Buggy python submission (verdict: Runtime Error):
a=list(int(input().split()) for i in range(3))
print(max(a)-min(a))

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

Buggy python submission (verdict: Runtime Error):
a=[int(input().split()) for i in range(3)]
print(max(a)-min(a))

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

Buggy python submission (verdict: Runtime Error):
*a=map(int,input().split())
print(max(a)-min(a))

Fixed submission:
*a,=map(int,input().split())
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
n=int(input())
from itertools import groupby as gb
ans=0
for a,b in gb(list(map(int,input().split()))):
    ans+=b//2
print(ans)

Fixed submission:
n=int(input())
from itertools import groupby as gb
ans=0
for a,b in gb(list(map(int,input().split()))):
    ans+=len(list(b)) //2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
from collections import defaultdict
l,r=s[:n],s[-1:-n-1:-1]

def g(l,n):
    b=set(range(n))
    d=defaultdict(int)
    for i in range(2**n):
        a={j for j in range(n)if (i>>j)%2}
        abar=b-a
        d[("".join(l[p] for p in sorted(list(a))),"".join(l[o] for o in sorted(list(abar))))]+=1
    return d
f,c=g(l,n),g(r,n)
#print(f,c,sep="\n")
print(sum(f[k]*c[k] for k in f))

Fixed submission:
def f():
    n=int(input())
    s=list(input())
    a,b=s[n-1::-1],s[n:]
    from collections import defaultdict

    ad=defaultdict(int)
    bd=defaultdict(int)
    for i in range(2**n):
        sa,ta,sb,tb="","","",""
        for j in range(n):
            if i%2:
                sa+=a[j]
                sb+=b[j]
            else:
                ta+=a[j]
                tb+=b[j]
            i//=2
        ad[(sa,ta)]+=1
        bd[(sb,tb)]+=1
    ans=0
    for k in ad:
        if k in bd:
            ans+=bd[k]*ad[k]
    print(ans)
if __name__ == "__main__":
    f()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
a,b=s[n-1::-1],s[n:]

ad={}
bd={}
for i in range(2**n):
    sa=tuple(a[j]for j in range(n)if (i>>j)%2)
    ta=tuple(a[j]for j in range(n)if (i>>j)%2==0)
    sb=tuple(b[j]for j in range(n)if (i>>j)%2)
    tb=tuple(b[j]for j in range(n)if (i>>j)%2==0)
    if (sa,ta)in ad:ad[(sa,ta)]+=1
    else:ad[(sa,ta)]=1
    if (sb,tb)in bd:bd[(sb,tb)]+=1
    else:bd[(sb,tb)]=1
ans=0
for k in ad:
    if k in bd:
        ans+=bd[k]*ad[k]
print(ans)

Fixed submission:
def f():
    n=int(input())
    s=list(input())
    a,b=s[n-1::-1],s[n:]
    from collections import defaultdict

    ad=defaultdict(int)
    bd=defaultdict(int)
    for i in range(2**n):
        sa,ta,sb,tb="","","",""
        for j in range(n):
            if i%2:
                sa+=a[j]
                sb+=b[j]
            else:
                ta+=a[j]
                tb+=b[j]
            i//=2
        ad[(sa,ta)]+=1
        bd[(sb,tb)]+=1
    ans=0
    for k in ad:
        if k in bd:
            ans+=bd[k]*ad[k]
    print(ans)
if __name__ == "__main__":
    f()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
n=int(input())
l=[0]+list(accumulate(list(map(int,input().split()))))
ans=float("INf")

for center in range(2,n-1):
    lnow=1
    laim=l[center]//2
    while lnow+1<center and l[lnow+1]<laim:lnow+=1
    rnow=center+1
    raim=(l[-1]-l[center])//2
    while rnow+1<n and l[rnow+1]-l[center]<raim:rnow+=1
    for i,j in ((0,0),(1,0),(1,1),(0,1)):
        if lnow+i<center and rnow+j<n:
            a,b,c,d=sorted([l[lnow+i],l[center]-l[lnow+i],l[rnow+j]-l[center],l[-1]-l[rnow+j]])
            ans=min(ans,d-a)
print(ans)

Fixed submission:
from itertools import accumulate
n=int(input())
l=[0]+list(accumulate(list(map(int,input().split()))))
ans=float("INf")
lnow=1
rnow=3
for center in range(2,n-1):

    laim=l[center]//2
    while lnow+1<center and l[lnow+1]<laim:lnow+=1
    if rnow<=center:rnow=center+1
    raim=(l[-1]-l[center])//2
    while rnow+1<n and l[rnow+1]-l[center]<raim:rnow+=1
    for i,j in ((0,0),(1,0),(1,1),(0,1)):
        if lnow+i<center and rnow+j<n:
            a=(l[lnow+i],l[center]-l[lnow+i],l[rnow+j]-l[center],l[-1]-l[rnow+j])
            ans=min(ans,max(a)-min(a))
print(ans)
Buggy python submission (verdict: Runtime Error):
print("ABD" if int(input())>999 else "ABC)

Fixed submission:
print("ABD" if int(input())>999 else "ABC")
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
st=[[] for i in range(26)]
n=len(s)
for i in range(n):
    st[ord(s[i])-97].append(i)

pre=0
now=set()
for i in st:
    for v in i:
        for c in range(v+1,n+1):
            now.add(s[v:c])
    if len(now)+pre<k:pre+=len(now);now=set()
    else:
        print(sorted(list(now))[k-pre-1]);exit()

Fixed submission:
s=input()
k=int(input())
st=[[] for i in range(26)]
n=len(s)
for i in range(n):
    st[ord(s[i])-97].append(i)

pre=0
now=set()
for i in st:
    for v in i:
        for c in range(v+1,min(n+1,v+6)):
            now.add(s[v:c])
    if len(now)+pre<k:pre+=len(now);now=set()
    else:
        print(sorted(list(now))[k-pre-1]);exit()

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
n=len(s)
print(sorted(list(set(s[i:j] for i in range(n) for j in range(i+1,n+1))))[k-1])


Fixed submission:
s=input()
k=int(input())
st=[[] for i in range(26)]
n=len(s)
for i in range(n):
    st[ord(s[i])-97].append(i)

pre=0
now=set()
for i in st:
    for v in i:
        for c in range(v+1,min(n+1,v+6)):
            now.add(s[v:c])
    if len(now)+pre<k:pre+=len(now);now=set()
    else:
        print(sorted(list(now))[k-pre-1]);exit()
Buggy python submission (verdict: Runtime Error):
p={2,3};n,c=5,0
while c<int(input()):
  for j in p:
    if n%j==0:break
  else:p.add(n);if n%5==1:print(n,end=" ");cnt+=1
print()

Fixed submission:
print(*[11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1471,1481,1511,1531][:int(input())],sep=" ")
Buggy python submission (verdict: Runtime Error):
a,s,k=map(int,input().split())
if s-a<=2*k-1:print(*list(range(a,s+1)),sep="\n")
else:print(*list(range(a,a+k)),*list(range(s+1-k,s+1)),sep="\n")

Fixed submission:
a,s,k=map(int,input().split())
if s-a<=2*k-1:print(*list(range(a,s+1)),sep="\n")
else:print(*list(range(a,a+k))+list(range(s+1-k,s+1)),sep="\n")
Buggy python submission (verdict: Runtime Error):
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    while chr(ord(s[-1])+1) not in des:
        des.add(l.pop())
    print("".join(l[:-1])+sorted(list(des))[0])

Fixed submission:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        from bisect import bisect_left as bl,bisect_right as br
        de=[s[-1]]
        for i in range(2,27):

            if de[-1]<s[-i]:de.append(s[-i])
            else:print(s[:-i]+de[bl(de,s[-i])]);exit()
Buggy python submission (verdict: Runtime Error):
n=input()
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print(ans if l[i+1]<l[i] else ans+dif)
  else:print(ansans if l[i+1]>l[i] else ans+dif)

Fixed submission:
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=0
for a,s in zip(l,l[1:]):
    ans+=abs(a-s)
for i in range(n):
    a,s=sorted([l[i],l[i+2]])
    if a<=l[i+1]<=s:print(ans)
    else:
        print(ans-abs(a-l[i+1])-abs(l[i+1]-s)+s-a)
Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().split())
ad=0
for i in range(a,b+1):
  s=str(i)
  if s==s[::-1]:ad+=1
print(ad)

Fixed submission:
a,b=map(int,input().split())
ans=0
for i in range(b+1)[a:]:
  if len(str(i))%2==0:
    p=list(str(i))[:len(str(i))//2]
    q=list(reversed(list(str(i))[len(str(i))//2:]))
    if p==q:
      ans+=1
  else:
    s=list(str(i))[:len(str(i))//2+1]
    d=list(reversed(list(str(i))[len(str(i))//2:]))
    if s==d:
      ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().split())
A=0
for i in range(a,b+1):
  if str(i)==str(i)[::-1]:A+=1
print(A)

Fixed submission:
a,b=map(int,input().split())
ans=0
for i in range(b+1)[a:]:
  if len(str(i))%2==0:
    p=list(str(i))[:len(str(i))//2]
    q=list(reversed(list(str(i))[len(str(i))//2:]))
    if p==q:
      ans+=1
  else:
    s=list(str(i))[:len(str(i))//2+1]
    d=list(reversed(list(str(i))[len(str(i))//2:]))
    if s==d:
      ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().split())
A=0
for i in range(a,b+1):
  if str(i)==str(i)[::-1]:A+=1
print(A)

Fixed submission:
a,b=map(int,input().split())
ans=0
for i in range(b+1)[a:]:
  if len(str(i))%2==0:
    p=list(str(i))[:len(str(i))//2]
    q=list(reversed(list(str(i))[len(str(i))//2:]))
    if p==q:
      ans+=1
  else:
    s=list(str(i))[:len(str(i))//2+1]
    d=list(reversed(list(str(i))[len(str(i))//2:]))
    if s==d:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
h,w,d=map(int,input().split())
inds={}
for i in range(h):
    for d,j in enumerate(input().split()):
        inds[int(j)-1]=(i,d)
nows=[[0]for c in range(d)]
for k in range(d,h*w):
    a,b=inds[k]
    x,y=inds[k-d]
    k%=d
    nows[k].append(nows[k][-1]+abs(a-x)+abs(b-y))
q=input()
for i in inputs():
    l,r=map(int,i.split())
    l-=1;r-=1
    l,b=divmod(l,d)
    r,b=divmod(r,d)
    print(nows[b][r]-nows[b][l])


Fixed submission:
h,w,d=map(int,input().split())
ind={}
for i in range(h):
    l=list(map(int,input().split()))

    for j in range(w):
        ind[l[j]]=(i,j)
table=[0]*((((h*w)//d).bit_length())*h*w)
now=1
for i in range(1,h*w-d+1):
    a,s=ind[i]
    de,f=ind[i+d]
    table[i-1+d]=abs(a-de)+abs(s-f)
step=2
for i in range(1,((h*w)//d).bit_length()):
    for j in range(1,h*w-step*d+1):
        table[j-1+step*d+i*h*w]=table[j-1+d*step//2+(i-1)*h*w]+table[j-1+d*step+(i-1)*h*w]
    step*=2
#print(*[table[k*h*w:k*w*h+h*w]for k in range(((h*w)//d).bit_length())],sep="\n")
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    times=(r-l)//d
    cost=0
    now=1
    kata=0
    while times:
        if times%2:
            l+=d*now
            cost+=table[l-1+kata*h*w]

        times//=2
        now*=2
        kata+=1
    print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())
ind={}
for i in range(h):
    l=list(map(int,input().split()))

    for j in range(w):
        ind[l[j]]=(i,j)
table=[0]*((((h*w)//d).bit_length())*h*w)
now=1
for i in range(1,h*w-d+1):
    a,s=ind[i]
    de,f=ind[i+d]
    table[i-1+d]=abs(a-de)+abs(s-f)
step=2
for i in range(1,((h*w)//d).bit_length()):
    for j in range(1,h*w-step*d+1):
        table[j-1+step*d+i*h*w]=table[j-1+d*step//2+(i-1)*h*w]+table[j-1+d*step+(i-1)*h*w]
    step*=2
#print(*[table[k*h*w:k*w*h+h*w]for k in range(((h*w)//d).bit_length())],sep="\n")
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    times=(r-l)//d
    cost=0
    now=1
    kata=0
    while times:
        if times%2:
            l+=d*now
            cost+=table[l-1+kata*h*w]

        times//=2
        now*=2
        kata+=1
    print(cost)

Fixed submission:
h,w,d=map(int,input().split())
ind={}
for i in range(h):
    l=list(map(int,input().split()))

    for j in range(w):
        ind[l[j]]=(i,j)
table=[0]*((((h*w)//d).bit_length())*h*w)
now=1
for i in range(1,h*w-d+1):
    a,s=ind[i]
    de,f=ind[i+d]
    table[i-1+d]=abs(a-de)+abs(s-f)
step=2
for i in range(1,((h*w)//d).bit_length()):
    for j in range(1,h*w-step*d+1):
        table[j-1+step*d+i*h*w]=table[j-1+d*step//2+(i-1)*h*w]+table[j-1+d*step+(i-1)*h*w]
    step*=2
#print(*[table[k*h*w:k*w*h+h*w]for k in range(((h*w)//d).bit_length())],sep="\n")
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    times=(r-l)//d
    cost=0
    now=1
    kata=0
    while times:
        if times%2:
            l+=d*now
            cost+=table[l-1+kata*h*w]

        times//=2
        now*=2
        kata+=1
    print(cost)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
print("No") if (n%500) >= a else ptrint("Yes")

Fixed submission:
n=int(input())
a=int(input())
print("No") if (n%500) > a else print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
print("No") if n%500 >= a else ptrint("Yes")

Fixed submission:
n=int(input())
a=int(input())
print("No") if (n%500) > a else print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
print("No") if (n%500)>=a else ptrint("Yes")

Fixed submission:
n=int(input())
a=int(input())
print("No") if (n%500) > a else print("Yes")
Buggy python submission (verdict: Runtime Error):
x,y,z=*[int(input()) for i in range(3)]
x-=(x//y)*y
x-=(x//z)*z
print(x)

Fixed submission:
x,y,z=[int(input()) for i in range(3)]
x-=y
x-=(x//z)*z
print(x)
Buggy python submission (verdict: Runtime Error):
mai,yen=map(int,input().split())
for i in range(mai+1):
  for j in range(mai+1-j):
    if 10000*i+5000*j+1000*(mai-i-j)==yen:print(i,j,mai-i-j);exit()
else:print(-1,-1,-1)

Fixed submission:
mai,yen=map(int,input().split())
for i in range(mai+1):
  for j in range(mai+1-i):
    if 10000*i+5000*j+1000*(mai-i-j)==yen:print(i,j,mai-i-j);exit()
else:print(-1,-1,-1)

Buggy python submission (verdict: Runtime Error):
mai,yen=map(int,input().split())
for i in range(mai+1):
  for j in range(mai+1-j):
    if 10000*i+5000*j+1000*(mai-i-j)==yen:print(i,j,mai-i-j);exit()
else:pint(-1,-1,-1)

Fixed submission:
mai,yen=map(int,input().split())
for i in range(mai+1):
  for j in range(mai+1-i):
    if 10000*i+5000*j+1000*(mai-i-j)==yen:print(i,j,mai-i-j);exit()
else:print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
def f():
  n=int(input())
  l=(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Fixed submission:
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
al=[]
mati=0
for i in range(n):
  now=l[i][1]+l[i][0]
  for j in range(i+1,n):
    now=l[j][0]+l[j][1]-(-max(0,now-l[j][1])//l[j][2])*l[j][2]
  al.append(now)
print(*al,sep="\n")
Buggy python submission (verdict: Runtime Error):
n,c=map(int,input().split())
table=[0]*220000
for i in range(n):
    a,s,c=map(int,input().split())
    table[2*a-1]+=1
    table[s*2]-=1
from itertools import accumulate
print(max(list(accumulate(table))))


Fixed submission:
a,s,d=map(int,input().split());print(min(a*s,d))
Buggy python submission (verdict: Runtime Error):
s=input()
l=list("AKIHABARA".split("A"))[1:-1]

for ii in range(2**4):
  p="A" if ii%2 else ""
  i=ii
   for j in range(3):
    p+=l[j]
    i//=2
    p+="A" if i%2 else ""
  if s==p:print("YES");exit()
print("NO")

Fixed submission:
s=input()
l=list("AKIHABARA".split("A"))[1:-1]

for ii in range(2**4):
  p="A" if ii%2 else ""
  i=ii
  for j in range(3):
    p+=l[j]
    i//=2
    p+="A" if i%2 else ""
  if s==p:print("YES");exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
from collections import Counter as co
s=input()
n=len(s)
l=sorted(co(list(s)).values())
if len(l)<=2:
    print("YES") if n==len(l) else print("NO")

else:
    m=l[0]
    for i,v in l:
        if v-m<=1:continue
        print("NO");exit()

    print("YES")

Fixed submission:
from collections import Counter as co
s=input()
n=len(s)
l=sorted(co(list(s)).values())
if len(l)<=2:
    print("YES") if n==len(l) else print("NO")

else:
    m=l[0]
    for v in l:
        if v-m<=1:continue
        print("NO");exit()

    print("YES")
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
ll=[list(map(int,input().split())) for i in range(10)]

for i in range(10**3-1):
    for i in range(10):
        for j in range(10):
            if i!=j:
                ll[i][j]=min(ll[i][j],min(ll[i][o]+tra[o][j] for o in range(10) if o!=i and o!=j))
ans=0
for i in range(h):
    for j in map(int,input().split()):
        if j==-1 or j==1:continue
        ans+=ll[j][1]
print(ans)

Fixed submission:
h,w=map(int,input().split())
tra=[list(map(int,input().split())) for i in range(10)]
ll=[[tra[i][j] for j in range(10)] for i in range(10)]
for i in range(10**3-1):
    for i in range(10):
        for j in range(10):
            if i!=j:
                ll[i][j]=min(ll[i][j],min(ll[i][o]+tra[o][j] for o in range(10) if o!=i and o!=j))
ans=0
for i in range(h):
    for j in map(int,input().split()):
        if j==-1 or j==1:continue
        ans+=ll[j][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
print(2**m*(100n+1800m))

Fixed submission:
n,m=map(int,input().split())
print((2**m)*(100*n+1800*m))
Buggy python submission (verdict: Runtime Error):
s=input()
d=s.replace("x","")
rd=d[::-1]
if d!=rd:print(-1)
else:
    ans=0
    x,y=0,len(s)-1
    while abs(x-y)>0:
        if s[x]==s[y]:x+=1;y-=1
        elif s[x]=="x":ans+=1;x+=1
        else:ans+=1;y-=1
    print(ans)

Fixed submission:
s=input()
d=s.replace("x","")
rd=d[::-1]
if d!=rd:print(-1)
else:
    ans=0
    x,y=0,len(s)-1
    while y-x>0:
        if s[x]==s[y]:
            x+=1;y-=1
        elif s[x]=="x":
            ans+=1;x+=1
        else:
            ans+=1;y-=1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=["!"*(m+2)]+["!"+input()+"!" for i in range(n)]+["!"*(m+2)]
ans=["0"*m for c in range(n)] 
for i in range(n):
  for d in range(m):
    if l[i+1][d+1]==".":
      ret=0
      for a,b in[[1,1],[1,0],[0,1],[-1,-1],[-1,0],[0,-1],[1,-1],[-1,1]] :
        if l[i+1+a][d+1+b]=="#":
          ret+=1
        ans[i][d]=str(ret)
    else:ans[i][d]="#"
for i in range(n):
  print(ans[i])

Fixed submission:
gyou,retu=map(int,input().split())
l=[input() for _ in range(gyou)]
d=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
for g in range(gyou):
  preans=str()
  for r in range(retu):
    s=0
    if l[g][r]=="#":
      preans += "#"
    else:
      for x in range(8):
        a,b=d[x]
        try:
          if l[g+a][r+b]=="#" and g+a>=0 and r+b>=0:
            s+=1
        except IndexError:
          s+=0
      preans += str(s)
  print(preans)

Buggy python submission (verdict: Runtime Error):
gyou,retu=map(int,input().split())
l=[input() for _ in range(gyou)]
d=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
for g in range(gyou):
  preans=str()
  for r in range(retu):
    s=0
    if l[g][r]=="#":
      preans += "#"
    else:
      for x in range(8):
        a,b=*d[x]
        try:
          if l[g+a][r+b]=="#" and g+a>=0 and r+b>=0:
            s+=1
        except IndexError:
          s+=0
      preans += str(s)
  print(preans)

Fixed submission:
gyou,retu=map(int,input().split())
l=[input() for _ in range(gyou)]
d=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
for g in range(gyou):
  preans=str()
  for r in range(retu):
    s=0
    if l[g][r]=="#":
      preans += "#"
    else:
      for x in range(8):
        a,b=d[x]
        try:
          if l[g+a][r+b]=="#" and g+a>=0 and r+b>=0:
            s+=1
        except IndexError:
          s+=0
      preans += str(s)
  print(preans)
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
n,m=min(n,m),max(n,m)
for i in range(n//2+n%2):
  num,dem=k-i*m,n-2*i
  if num%dem or not(0<=num///dem<=m):continue
  print("Yes");exit()
print("No")

Fixed submission:
n,m,k=map(int,input().split())
n,m=min(n,m),max(n,m)
for i in range(n//2+n%2):
  num,dem=k-i*m,n-2*i
  if num%dem or not(0<=num//dem<=m):continue
  print("Yes");exit()
print("No")