Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = Input()
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()

Fixed submission:
def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, k = Input()
    data = sorted(int(input()) for _ in range(n))
    ans = 1e9
    for i in range(n-k+1):
        x = data[i:i+k]
        ans = min(ans, max(x) - min(x))
    print(ans)
main()

Fixed submission:
def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()
Buggy python submission (verdict: Runtime Error):
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    x = Input()

    data = [abs(X - x[i]) for i in range(N)]
    ans = data[0]
    for i in range(1, len(data)):
        ans = gcd(data[i], ans)
    print(ans)



main()

Fixed submission:
def gcd(a, b):
    """最大公約数"""
    if b == 0: return a
    return gcd(b, a % b)
  

def mapt(fn, *args):
    return list(map(fn, *args))
 
 
def Input():
    return mapt(int, input().split(" "))
 
def main():
    N, X = Input()
    x = Input()
 
    if N == 1:
        print(abs(x[0] - X))
        exit()
 
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]
 
    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)
 
 
 
main()

Buggy python submission (verdict: Runtime Error):
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    x = Input()

    if N == 1:
        print(abs(x[0] - X))
        exit()

    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]

    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)



main()

Fixed submission:
def gcd(a, b):
    """最大公約数"""
    if b == 0: return a
    return gcd(b, a % b)
  

def mapt(fn, *args):
    return list(map(fn, *args))
 
 
def Input():
    return mapt(int, input().split(" "))
 
def main():
    N, X = Input()
    x = Input()
 
    if N == 1:
        print(abs(x[0] - X))
        exit()
 
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]
 
    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)
 
 
 
main()

Buggy python submission (verdict: Runtime Error):
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    if N == 1:
        print(abs(N-X))
        exit()
        
    x = Input()
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]

    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)



main()

Fixed submission:
def gcd(a, b):
    """最大公約数"""
    if b == 0: return a
    return gcd(b, a % b)
  

def mapt(fn, *args):
    return list(map(fn, *args))
 
 
def Input():
    return mapt(int, input().split(" "))
 
def main():
    N, X = Input()
    x = Input()
 
    if N == 1:
        print(abs(x[0] - X))
        exit()
 
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]
 
    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)
 
 
 
main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())

    ans = 0
    for a, b in (list(combinations(range(1, n+1), 2))):
        if (a%2==0 and b%2 != 0) or (b%2==0 and a%2!=0):
            ans += 1

    print(ans)


main()

Fixed submission:
from itertools import combinations


def main():
    n = int(input())

    ans = 0
    for a, b in (list(combinations(range(1, n+1), 2))):
        if (a%2==0 and b%2 != 0) or (b%2==0 and a%2!=0):
            ans += 1

    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, k = Input()
    if n % k == 0:
        print(0)
    else:
        max_n = math.ceil(k/n)
        min_n = math.floor(k/n)
        print(max_n - min_n)


main()

Fixed submission:
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, k = Input()
    if n % k == 0:
        print(0)
    else:
        print(1)


main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a_list = list(map(int, input().split()))

ans = 1
for a in a_list:
  if a == 0:
    print(0)
    sys.exit()
  
  if a > 1000000000000000000:
    print(-1)
    sys.exit()
  
  ans *= a
 
if ans > 1000000000000000000:
  print(-1)
else:
  print(ans)


Fixed submission:
import sys

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)

if a_list[-1] == 0:
  print(0)
  sys.exit()

if a_list[0] > 1000000000000000000:
  print(-1)
  sys.exit()

ans = 1
for a in a_list:
  ans *= a

  if ans > 1000000000000000000:
    print(-1)
    sys.exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a_list = list(map(int, input().split()))

ans = 1
for a in a_list:
  if a > 1000000000000000000:
    print(-1)
    sys.exit()
    
  if a == 0:
    print(0)
    sys.exit()
  
  ans *= a
 
if ans > 1000000000000000000:
  print(-1)
else:
  print(ans)


Fixed submission:
import sys

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)

if a_list[-1] == 0:
  print(0)
  sys.exit()

if a_list[0] > 1000000000000000000:
  print(-1)
  sys.exit()

ans = 1
for a in a_list:
  ans *= a

  if ans > 1000000000000000000:
    print(-1)
    sys.exit()

print(ans)

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

ans = 1
for a in a_list:
  ans *= a
 
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)


Fixed submission:
import sys

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)

if a_list[-1] == 0:
  print(0)
  sys.exit()

if a_list[0] > 1000000000000000000:
  print(-1)
  sys.exit()

ans = 1
for a in a_list:
  ans *= a

  if ans > 1000000000000000000:
    print(-1)
    sys.exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math

a, b, h, m = map(int, input().split())

if h == 0 and m == 0:
  print(0)
  sys.exit()
  
angle_h = (h*60 + m) * (360 / 12 / 60)
angle_m = m * (360 / 60)

radian = math.radians(angle)
cosine = math.cos(radian)
ans = a*a + b*b - 2*a*b * cosine
ans = math.sqrt(ans)

print(ans)

Fixed submission:
import sys
import math
 
a, b, h, m = map(int, input().split())
 
#if h == 0 and m == 0:
#  print(0)
#  sys.exit()
  
angle_h = (h*60 + m) * (360 / 12 / 60)
angle_m = m * (360 / 60)
 
angle = abs(angle_h - angle_m)
radian = math.radians(angle)
cosine = math.cos(radian)
ans = a*a + b*b - 2*a*b * cosine
ans = math.sqrt(ans)
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
spells = sorted([tuple(map(int,input().split())) for _ in range(N)])
max_a = spells[-1][0]

dp = [10000000000 for _ in range(H + max_a + 1)]
dp[0] = 0

for i in range(1, H + max_a + 1):
  for spell in spells:
    if spell[0] > i:
      break
    else:
      dp[i] = min(dp[i], dp[i - spell[0]] + spell[1])

print(min(dp[H:H + max_a + 1]))


Fixed submission:
H,N = map(int,input().split())
spells = [tuple(map(int,input().split())) for _ in range(N)]
max_a = max(spells)[0]

dp = [0]
for i in range(1, H + max_a + 1):
  try:
    dp.append(min([dp[i - a] + b for a,b in spells if a <= i]))
  except ValueError:
    dp.append(10**8)

print(min(dp[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
spells = sorted([tuple(map(int,input().split())) for _ in range(N)], key=lambda c: c[0])
max_a = spells[-1][0]

dp = [100000000 for _ in range(H + max_a + 1)]
dp[0] = 0

for i in range(1, H + max_a + 1):
  for spell in spells:
    if spell[0] <= i:
      dp[i] = min(dp[i], dp[i - spell[0]] + spell[1])
    else:
      break

print(min(dp[H:H + max_a + 1]))


Fixed submission:
H,N = map(int,input().split())
spells = [tuple(map(int,input().split())) for _ in range(N)]
max_a = max(spells)[0]

dp = [0]
for i in range(1, H + max_a + 1):
  try:
    dp.append(min([dp[i - a] + b for a,b in spells if a <= i]))
  except ValueError:
    dp.append(10**8)

print(min(dp[H:]))

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
spells = sorted([tuple(map(int,input().split())) for _ in range(N)], key=lambda c: c[0])
max_a = max(spells,key=lambda t: t[0])[0]

dp = [10000000000 for _ in range(H + max_a + 1)]
dp[0] = 0

for i in range(1, H + max_a + 1):
  for spell in spells:
    if spell[0] <= i:
      dp[i] = min(dp[i], dp[i - spell[0]] + spell[1])
    else:
      break

print(min(dp[H:H + max_a + 1]))


Fixed submission:
H,N = map(int,input().split())
spells = [tuple(map(int,input().split())) for _ in range(N)]
max_a = max(spells)[0]

dp = [0]
for i in range(1, H + max_a + 1):
  try:
    dp.append(min([dp[i - a] + b for a,b in spells if a <= i]))
  except ValueError:
    dp.append(10**8)

print(min(dp[H:]))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i] < A[i]:
    ans = max(ans, A[ImportError] - 1)
print(max(0,ans))


Fixed submission:
import sys
sys.setrecursionlimit(200000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i] < A[i]:
    ans = max(ans, A[i] - 1)
print(max(0,ans))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(110000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i+1] < A[i+1]:
    ans = max(ans, A[i+1] - 1)
print(max(0,ans))


Fixed submission:
import sys
sys.setrecursionlimit(200000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i] < A[i]:
    ans = max(ans, A[i] - 1)
print(max(0,ans))
Buggy python submission (verdict: Runtime Error):
global primeList
primeList = []

def primeFactorize(X):
  global primeList
  result = set()
  for prime in primeList:
      if X % prime == 0:
        result.add(prime)
  return result

A,B = map(int,input().split())

isPrime = [True for i in range(1000001)]
isPrime[0] = isPrime[1] = False;
primeList.append(2)
for i in range(4,1000001,2):
  isPrime[i] = False

for i in range(3,1000001,2):
    if not isPrime[i]:
      continue
    primeList.append(i)
    for j in range(i, 1000001//i + 1):
      isPrime[i*j] = False

pA = primeFactorize(A)
pB = primeFactorize(B)
print(len(pA.intersection(pB)) + 1)




Fixed submission:
global primeList
primeList = []

def primeFactorize(X):
  global primeList
  result = set()
  for prime in primeList:
      while X % prime == 0:
        result.add(prime)
        X //= prime
  if X != 1:
      result.add(X)
  return result

A,B = map(int,input().split())

isPrime = [True for i in range(1000001)]
isPrime[0] = isPrime[1] = False;
primeList.append(2)
for i in range(4,1000001,2):
  isPrime[i] = False

for i in range(3,1000001,2):
    if not isPrime[i]:
      continue
    primeList.append(i)
    for j in range(i, 1000000//i + 1):
      isPrime[i*j] = False

pA = primeFactorize(A)
pB = primeFactorize(B)
print(len(pA.intersection(pB)) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,Q = map(int,input().split())

graph, parents, values, visited = [],[],[],[]
for _ in range(N):
  graph.append([])
  parents.append(-1)
  values.append(0)
  visited.append(False)

for i in range(N-1):
  a,b = map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

for i in range(Q):
  p,x = map(int,input().split())
  values[p-1] += x

bfs_queue = deque()
bfs_queue.append(0)
bfs_queue_len = 1
while bfs_queue_len:
  cur = bfs_queue.popleft()
  bfs_queue_len -= 1
  visited[cur] = True

  for other in graph[cur]:
    if not visited[other]:
      parents[other] = cur
      values[other] += values[cur]
      bfs_queue_len += 1
      bfs_queue.append(other)

for i in range(N):
  print(values[i],end=" ")



Fixed submission:
from collections import deque

N,Q = map(int,input().split())

graph, parents, values, visited = [],[],[],[]
for _ in range(N):
  graph.append([])
  parents.append(-1)
  values.append(0)
  visited.append(False)

for i in range(N-1):
  a,b = map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

for i in range(Q):
  p,x = map(int,input().split())
  values[p-1] += x

bfs_queue = deque()
bfs_queue.append(0)
bfs_queue_len = 1
while bfs_queue_len:
  cur = bfs_queue.popleft()
  bfs_queue_len -= 1
  visited[cur] = True

  for other in graph[cur]:
    if not visited[other]:
      parents[other] = cur
      values[other] += values[cur]
      bfs_queue_len += 1
      bfs_queue.append(other)

print(*values)
Buggy python submission (verdict: Runtime Error):
N = int(input())
total = 0
for q in range(1,N // int(N**0.5) + 1):
	if N % (N // q - 1) == N // (N // q - 1):
		total += (N // q) - 1
print(total)

Fixed submission:
N = int(input())
total = 0
for q in range(1,N // int(N**0.5) + 1):
	try:
		if N % (N // q - 1) == N // (N // q - 1):
			total += (N // q) - 1
	except:
		pass
print(total)
Buggy python submission (verdict: Runtime Error):
from math import log2, ceil

A,B = map(int,input().split())
N = B - A + 1

#class A
ng = N // 2
ng %= 2
ans = ng ^ (B & 1)

for i in range(2,ceil(log2(B)) + 2):
  #class B
  K = N % pow(2,i)
  A_bit = int((A & pow(2,i-1)) > 0)
  next_multiple_dist = ceil(A / pow(2,i-1)) * pow(2,i-1) - A
  if next_multiple_dist == 0:
    next_multiple_dist = pow(2,i-1)
  
  #010
  if A_bit == 0:
    if next_multiple_dist < K:
      K -= next_multiple_dist
      next_multiple_dist = pow(2,i-1)
      ans += pow(2,i-1) * (min(K,next_multiple_dist) % 2)
  #101
  else:
    if next_multiple_dist < K:
      num_1 = next_multiple_dist
      K -= next_multiple_dist
      next_multiple_dist = pow(2,i-1)

      if next_multiple_dist < K:
        num_1 += K - next_multiple_dist

      ans += pow(2,i-1) * (num_1 % 2)
    else:
      ans += pow(2,i-1) * (K % 2)  

if A == B:
  print(A)
else:
  print(ans)


Fixed submission:
def F(N): return ((N + 1) // 2) % 2 if N & 1 else ((N // 2) % 2) ^ N
A,B = map(int,input().split())
print(F(A-1) ^ F(B))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

substrings = set()
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        substrings.add(s[i:j])

print(sorted(substrings)[K-1])
        


Fixed submission:
s = input()
K = int(input())

substrings = set()
for i in range(len(s)):
    for j in range(i+1,min(i+6,len(s)+1)):
        substrings.add(s[i:j])

print(sorted(substrings)[K-1])
Buggy python submission (verdict: Runtime Error):
global visited,num,graph

def dfs(subtree):
    global visited,num,graph
    if visited[subtree] != 0:
        return

    visited[subtree] = num
    for node in graph[subtree]:
        if visited[node] != 0:
            continue
        dfs(node)

N,M = map(int,input().split())

starting = list(map(int,input().split()))
graph = [[] for x in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

visited = [0 for x in range(N+1)]
num = 1
for i in range(1,N+1):
    if visited[i] == 0:
        dfs(i)
        num += 1

ans = 0
for i in range(1,N+1):
    if visited[i] == visited[starting[i-1]]:
        ans += 1

print(ans)
        


    





Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000)

global visited,num,graph

def dfs(subtree):
    global visited,num,graph
    if visited[subtree] != 0:
        return

    visited[subtree] = num
    for node in graph[subtree]:
        if visited[node] != 0:
            continue
        dfs(node)

N,M = map(int,input().split())

starting = list(map(int,input().split()))
graph = [[] for x in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

visited = [0 for x in range(N+1)]
num = 1
for i in range(1,N+1):
    if visited[i] == 0:
        dfs(i)
        num += 1

ans = 0
for i in range(1,N+1):
    if visited[i] == visited[starting[i-1]]:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = set(input().split())
if len(A) == 3:
   print(“Three”)
else:
   print(“Four”)

Fixed submission:
N = int(input())
A = set(input().split())
if len(A) == 3:
   print("Three")
else:
   print("Four")

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = set()
for i in range(N):
   A.add(input())
if len(A) == 3:
   print(“Three”)
else:
   print(“Four”)

Fixed submission:
N = int(input())
A = set(input().split())
if len(A) == 3:
   print("Three")
else:
   print("Four")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

suma = sumb = num = 0
for i in range(N):
    suma += A[i]
    sumb += B[i]
    if A[i] < B[i]:
        num += ceil((B[i] - A[i]) / 2)

if A == B:
    print("Yes")
else:
    if suma >= sumb:
        print("No")
    else:
        if num > sumb - suma:
            print("No")
        else:
            print("Yes")


Fixed submission:
from math import ceil

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

suma = sumb = num = 0
for i in range(N):
    suma += A[i]
    sumb += B[i]
    if A[i] < B[i]:
        num += ceil((B[i] - A[i]) / 2)

if A == B:
    print("Yes")
else:
    if suma >= sumb:
        print("No")
    else:
        if num > sumb - suma:
            print("No")
        else:
            print("Yes")

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

suma = sumb = num
for i in range(N):
    suma += A[i]
    sumb += B[i]
    if A[i] < B[i]:
        num += (B[i] - A[i]) // 2

if A == B:
    print("Yes")
else:
    if suma >= sumb:
        print("No")
    else:
        if num > sumb - suma:
            print("No")
        else:
            print("Yes")


Fixed submission:
from math import ceil

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

suma = sumb = num = 0
for i in range(N):
    suma += A[i]
    sumb += B[i]
    if A[i] < B[i]:
        num += ceil((B[i] - A[i]) / 2)

if A == B:
    print("Yes")
else:
    if suma >= sumb:
        print("No")
    else:
        if num > sumb - suma:
            print("No")
        else:
            print("Yes")
Buggy python submission (verdict: Runtime Error):
S = input()
L = len(s)

ans = L
for i in range(L - 1):
    if S[i] != S[i+1]:
        ans = min(max(L - i - 1, i + 1),ans)
print(ans)


Fixed submission:
S = input()

ans = len(S)
for i in range(len(S) - 1):
    if S[i] != S[i+1]:
        ans = min(max(len(S) - i - 1, i + 1),ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

if len(S) >= 9:
    print("NO")
else:
    if S.count("A") > 4:
        print("NO")
    elif "KIH" not in S:
        print("NO")
    elif S.index("B") > S.index("R") or S.index("B") < S.index("K") or S.index("R") < S.index("K"):
        print("NO")
    elif S[:S.index("K")].count("A") > 1 or S[S.index("H"):S.index("B")].count("A") > 1 or S[S.index("B"):S.index("R")].count("A") > 1 or S[S.index("R"):].count("A") > 1:
        print("NO")
    else:
        print("YES")
    


Fixed submission:
S = input()

if len(S) > 9:
    print("NO")
elif "KIH" not in S or "B" not in S or "R" not in S:
    print("NO")
elif ("A" in S and len(set(S)) > 6) or ("A" not in S and len(set(S)) > 5):
    print("NO")
elif S.index("B") > S.index("R") or S.index("B") < S.index("K") or S.index("R") < S.index("K"):
    print("NO")
elif S[:S.index("K")].count("A") > 1 or S[S.index("H"):S.index("B")].count("A") > 1 or S[S.index("B"):S.index("R")].count("A") > 1 or S[S.index("R"):].count("A") > 1:
    print("NO")
else:
    print("YES")