Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

sumA = [A[0]%M] + [0]*(N-1)
for i in range(1,N):
  sumA[i] = (sumA[i-1]+A[i]%M)%M

ans = 0
for i in range(N):
  ans += sumA[i+1:].count(sumA[i])
  if sumA[i] == 0: ans += 1
print(ans)

Fixed submission:
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

sumA = [0] + [0]*N
for i in range(N):
  sumA[i] = (sumA[i-1]+A[i])%M

cnt = Counter(sumA).values()
ans = sum(i*(i-1)//2 for i in cnt)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
modA = [a%M for a in map(int,input().split())]
ans = 0
for l in range(N):
  sumA = 0
  for r in range(l,N):
    sumA += modA[r]
    sumA = sumA%M
    if sumA%M == 0: ans += 1
print(ans)

Fixed submission:
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

sumA = [0] + [0]*N
for i in range(N):
  sumA[i] = (sumA[i-1]+A[i])%M

cnt = Counter(sumA).values()
ans = sum(i*(i-1)//2 for i in cnt)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
modA = [a%M for a in map(int,input().split())]
ans = 0
for l in range(N):
  sumA = 0
  for r in range(l,N):
    sumA += modA[r]
    if sumA%M == 0: ans += 1
print(ans)

Fixed submission:
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

sumA = [0] + [0]*N
for i in range(N):
  sumA[i] = (sumA[i-1]+A[i])%M

cnt = Counter(sumA).values()
ans = sum(i*(i-1)//2 for i in cnt)

print(ans)
Buggy python submission (verdict: Runtime Error):
def calc_sadness(b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans


N = int(input())
A = []
for idx, a in enumerate(map(int, input().split())):
    A.append(a - idx - 1)
A.sort()

if N % 2 == 0:
    b = [[N // 2]]
else:
    b = [A[N // 2 - 1], A[N // 2]]

print(min(map(calc_sadness, b)))

Fixed submission:
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = int(statistics.median(A))
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = statistics.median(A)
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)


Fixed submission:
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = int(statistics.median(A))
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = prv_ans = float('inf')
for b in range(min(A), max(A)+1):
  tmp_ans = sum([abs(A[i]-b) for i in range(N)])
  if prv_ans < tmp_ans: break
  ans = min(ans, tmp_ans)
  tmp_ans = ans
print(ans)

Fixed submission:
import statistics
N = int(input())
A = [int(a)-(i+1) for i, a in enumerate(input().split())]
ans = float('inf')
medi = int(statistics.median(A))
for b in range(medi-1, medi+2):
  ans = min(ans, sum([abs(A[i]-b) for i in range(N)]))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import permutations

N,C = map(int,input().split())
D = [list(map(int,sys.stdin.readline().split())) for _ in range(C)]
grids = [list(map(int,sys.stdin.readline().split())) for _ in range(N)]

ans = float('inf')
for cmb in permutations([i for i in range(1,C+1)],3):
  tmp_ans = 0
  for j, row in enumerate(grids):
    for i, val in enumerate(row):
      if val != cmb[(i+j+2)%3]: tmp_ans += D[val-1][cmb[(i+j+2)%3]-1]
      #print(i, j, val, cmb, tmp_ans)
  ans = min(tmp_ans, ans)
  #print(ans, tmp_ans, cmb)
print(ans)

Fixed submission:
[print('ABC') if int(input()) < 1000 else print('ABD')]
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline())
P = [int(sys.stdin.readline()) for _ in range(N)]
Q = [P.index(i) for i in range(1, N + 1)]
ans = 0
prv_q = 0
now = 0
for i in range(N):
    if prv_q > Q[i]:
        now = 0
    now += 1
    prv_q = Q[i]
    ans = max(ans, now)
print(N - ans)


Fixed submission:
import sys

N = int(sys.stdin.readline())
P = {int(sys.stdin.readline()): i for i in range(N)}
Q = [P[i] for i in range(1, N + 1)]

ans = 0
prv_q = 0
now = 0
for i in range(N):
    if prv_q > Q[i]:
        now = 0
    now += 1
    prv_q = Q[i]
    ans = max(ans, now)
print(N - ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())

N = len(S)
substr = []
for i in range(N):
    for j in range(i, N):
        tmp_substr = S[i:j+1]
        
        if tmp_substr in substr:
            continue

        if len(substr) <= 4:
            substr.append(tmp_substr)
            substr.sort()
        else:
            substr.append(tmp_substr)
            substr.sort()
            del substr[-1]

print(substr[K-1])

Fixed submission:
s = input()
K = int(input())
subs = []
for i in range(len(s)):
  subs += [s[i:i+j] for j in range(1,min(len(s)-i+1,K+1))]

subs = list(set(subs))
subs.sort()
print(subs[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(si, ei):
  q = deque()
  q.append(si)
  used = set([])
  while len(q) > 0:
    prvi = q.pop()
    for i in g[prvi]:
      if i in used: continue
      if i == ei: return True
      q.append(i)
      used.add(i)
  return False

N,M = map(int,input().split())
P = [val-1 for val in map(int,input().split())]
g = {i:[] for i in range(N)}
ans = 0
for _ in range(M):
  x,y = map(int,input().split())
  g[x-1].append(y-1)
  g[y-1].append(x-1)

for i in range(N):
  if i == P[i]: ans += 1
  elif bfs(i,P[i]): ans += 1
print(ans)

Fixed submission:
from collections import deque

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n+1)]
    self.rank = [0] * (n+1)
  
  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]

  def same_check(self, x, y):
    return self.find(x) == self.find(y)
 
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if self.rank[x] < self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1


N,M = map(int,input().split())
P = [val-1 for val in map(int,input().split())]
ans = 0
uf = UnionFind(N)

for _ in range(M):
  x,y = map(int,input().split())
  if uf.same_check(x-1,y-1) is False:
    uf.union(x-1,y-1)

for i in range(N):
  if uf.same_check(i,P[i]):
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

n = int(input())
A = list(map(int,input().split()))
acmA = [0] + list(accumulate(A))
ans = 0
for i in range(1,n+1):
  for j in range(n-i+1):
    if acmA[j+i]-acmA[j]==0: ans += 1
print(ans)

Fixed submission:
from itertools import accumulate
from collections import Counter

int(input())
A = list(map(int,input().split()))
acmA = list(accumulate(A))
ans = 0
for key, num in Counter(acmA).items():
  ans += (num*(num-1))//2
  if key == 0:ans += num
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, C= map(int,input().split())
XV = sorted([list(map(int,input().split())) for _ in range(N)])
acmXV = []
dbl_acmXV = []
for i, xv in enumerate(XV):
  x,v = xv
  if i == 0:
    acmXV.append(v-x)
    dbl_acmXV.append(v-x*2)
  else:
    acmXV.append(v-(x-XV[i-1][0])+acmXV[i-1])
    dbl_acmXV.append(v-(x-XV[i-1][0])*2+dbl_acmXV[i-1])

acmXV_rev = [0 for _ in range(N)]
dbl_acmXV_rev = [0 for _ in range(N)]
for i in range(N-1, -1, -1):
  x,v = XV[i]
  if i == N-1:
    acmXV_rev[i] = v-(C-x)
    dbl_acmXV_rev[i] = v-(C-x)*2
  else:
    acmXV_rev[i] = (v-(XV[i+1][0]-XV[i][0])+acmXV_rev[i+1])
    dbl_acmXV_rev[i] = (v-(XV[i+1][0]-XV[i][0])*2+dbl_acmXV_rev[i+1])
    
ans = max(0,max(acmXV),max(acmXV_rev))
for i in range(N):
  for j in range(N-1,i,-1):
    #print(i,j,dbl_acmXV[i],acmXV_rev[N-1-j])
    ans = max(ans, dbl_acmXV[i]+acmXV_rev[j], acmXV[i]+dbl_acmXV_rev[j]) 
print(ans)

Fixed submission:
import copy

N, C= map(int,input().split())
XV = sorted([list(map(int,input().split())) for _ in range(N)])
acmXV = []
dbl_acmXV = []

for i, xv in enumerate(XV):
  x,v = xv
  if i == 0:
    acmXV.append(v-x)
    dbl_acmXV.append(v-x*2)
  else:
    acmXV.append(v-(x-XV[i-1][0])+acmXV[i-1])
    dbl_acmXV.append(v-(x-XV[i-1][0])*2+dbl_acmXV[i-1])

acmXV_rev = [0 for _ in range(N)]
dbl_acmXV_rev = [0 for _ in range(N)]
for i in range(N-1, -1, -1):
  x,v = XV[i]
  if i == N-1:
    acmXV_rev[i] = v-(C-x)
    dbl_acmXV_rev[i] = v-(C-x)*2
  else:
    acmXV_rev[i] = (v-(XV[i+1][0]-XV[i][0])+acmXV_rev[i+1])
    dbl_acmXV_rev[i] = (v-(XV[i+1][0]-XV[i][0])*2+dbl_acmXV_rev[i+1])


max_acmXV_rev = copy.deepcopy(acmXV_rev)
max_dbl_acmXV_rev = copy.deepcopy(dbl_acmXV_rev)
for i in range(N-2,-1,-1):
  max_acmXV_rev[i] = max(max_acmXV_rev[i], max_acmXV_rev[i+1])
  max_dbl_acmXV_rev[i] = max(max_dbl_acmXV_rev[i],max_dbl_acmXV_rev[i+1])

ans = max(0,max(acmXV),max(acmXV_rev))
for i in range(N-1):
  ans = max(ans, dbl_acmXV[i]+max_acmXV_rev[i+1], acmXV[i]+max_dbl_acmXV_rev[i+1]) 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)
if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if cmb(maxA,A[idx]) > cmb(maxA,A[idx-1]):
    print(maxA,A[idx])
  else:
    print(maxA,A[idx-1])

Fixed submission:
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)

if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
    print(maxA,A[idx-1])
  else:
    print(maxA,A[idx])

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)

max_cmb = -float('inf')
done = set([])
for i, n in enumerate(A):
  for j in range(i+1,N):
    r = A[j]
    r = min(n-r,r)
    #print(n,r,cmb(n,r))
    if [n,r] in done: continue
    
    tmp_cmb = cmb(n,r)
    if max_cmb < tmp_cmb:
      max_cmb = tmp_cmb
      nr = [n,A[j]]
    
print(*nr)

Fixed submission:
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)

if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
    print(maxA,A[idx-1])
  else:
    print(maxA,A[idx])
Buggy python submission (verdict: Runtime Error):
nums = sorted(list(map(int, input().split())))
ans = 0
while nums[0] != nums[-1]:
  if nums[-1] - nums[0] >= 2:
    nums[0] += 2
  else:
    nums[0] += 1
    nums[1] += 1
  nums = sorted(nums)
  ans += 1
print(ans)

Fixed submission:
S = input()
print('Yes' if all([True if S.count(s)==1 else False for s in 'abc']) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())

if K == 0:
  print(N**2)
  exit()

ans = 0
for b in range(1,N+1):
  for a in range(b,N+1):
    if a%b >= K : ans += 1
    
for a in range(1,N+1):
  if a >= K: ans += N-a

print(ans)

Fixed submission:
N,K = map(int,input().split())

if K == 0:
  print(N**2)
  exit()

ans = 0
for b in range(1,N+1):
  if b <= K: continue
  else: ans += N//b*(b-K) + max(0,(N-(N//b)*b)-K+1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int,input().split())

turn = 1
while abs(a-b) != 1:  
  if turn == 1:
    if a<b:
      if (b-a)%2==0 or a==1: a += 1
      else: a -=1
    else:
      if (a-b)%2==0 or a==n: a -= 1
      else: a +=1
  else:
    if a<b:
      if (b-a)%2==1 or b==1: b += 1
      else: b -=1
    else:
      if (a-b)%2==1 or b==n: b -= 1
      else: b +=1
  turn *= -1
print('Alice' if turn==-1 else 'Borys')

Fixed submission:
n,a,b = map(int,input().split())
print('Alice' if abs(b-a)%2==0 else 'Borys')
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
for nb in range(N+1):
  pointB = sum(B[:nb])
  ans = min(ans,ceil((H-pointB)/maxA)+nb)
print(ans)

Fixed submission:
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,max(0,ceil((H-pointB)/maxA))+nb)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
N,H = map(int,input().split())
A, B = [], []
for _ in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

maxA = max(A)
B.sort(reverse=True)

ans = float('inf')
for nb in range(N+1):
  pointB = sum(B[:nb])
  ans = min(ans,ceil((H-pointB)/maxA)+nb)
print(ans)

Fixed submission:
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,max(0,ceil((H-pointB)/maxA))+nb)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))

ans = 0
num = len(A.keys())
while num > K:
  min_key = [key for key in A if A[key] == min(A.values())][0]
  ans += A[min_key]
  num -= 1
  del A[min_key]
print(ans)

Fixed submission:
from collections import Counter

N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
nums = sorted(A.values(), reverse= True)
num = len(nums)
ans = 0

while num > K:
  ans += nums[-1]
  del nums[-1]
  num -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))

ans = 0
while len(A.keys()) > K:
  min_key = [key for key in A if A[key] == min(A.values())][0]
  ans += A[min_key]
  del A[min_key]
print(ans)

Fixed submission:
from collections import Counter

N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
nums = sorted(A.values(), reverse= True)
num = len(nums)
ans = 0

while num > K:
  ans += nums[-1]
  del nums[-1]
  num -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,input().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

Fixed submission:
N,A,B = map(int,input().split())
print(min(B,A*N))
Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,input().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

Fixed submission:
import sys

N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,sys.stdin.readline().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,input().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
  rs.sort()
print(len(rs))

Fixed submission:
import sys

N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,sys.stdin.readline().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))
Buggy python submission (verdict: Runtime Error):
S = input()
akb = 'AKIHABAR'
if len(S) <= len(akb)+1:
  i = 0
  for a in akb:
    if S[i] == a: i+=1
    elif S[i] != a and a == 'A': continue
    else:
      print('NO')
      exit()
  print('YES')
else:
  print('NO')



Fixed submission:
S = input()
akb = 'AKIHABAR'
if len(S) <= len(akb)+1:
  i = 0
  for a in akb:
    if i >= len(S):
      print('NO')
      exit()
    if S[i] == a: i+=1
    elif S[i] != a and a == 'A': continue
    else:
      print('NO')
      exit()
  print('YES')
else:
  print('NO')

Buggy python submission (verdict: Runtime Error):
S = input()
i = 0
for a in 'AKIHABARA':
  if i >= len(S) and a == 'A':
    S = S + 'A'
    i += 1
  elif S[i] != a:
    if a == 'A':
      S = S[:i] + 'A' + S[i:]
      i += 1
    else:
      print('NO')
      exit()
  else:
    i += 1
print('YES')  


Fixed submission:
S = input()
akb = 'AKIHABAR'
if len(S) <= len(akb)+1:
  i = 0
  for a in akb:
    if i >= len(S):
      print('NO')
      exit()
    if S[i] == a: i+=1
    elif S[i] != a and a == 'A': continue
    else:
      print('NO')
      exit()
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if abs(A[-1]-A[-2]) >= abs(A[-1]-W):
  print(abs(A[-1]-A[-2]))
else:
  print(abs(A[-1]-W))


Fixed submission:
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
  print(abs(A[0]-W))
  exit()
  
if abs(A[-1]-A[-2]) >= abs(A[-1]-W):
  print(abs(A[-1]-A[-2]))
else:
  print(abs(A[-1]-W))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()

ans = 0
mem_idx_a = {}
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    if B[i] in mem_idx_a:
      idx_a = mem_idx_a[B[i]]
    else:
      idx_a = bisect.bisect_left(A,B[i])
      mem_idx_a[B[i]] = idx_a
    ans += idx_a
print(ans)

Fixed submission:
import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)

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

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
mem_idx_a = {}
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    if B[i] in mem_idx_a:
      idx_a = mem_idx_a[B[i]]
    else:
      idx_a = bisect.bisect_left(A,B[i])
      mem_idx_a[B[i]] = idx_a    
    ans += idx_a
print(ans)

Fixed submission:
import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)

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

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    idx_a = bisect.bisect_left(A,B[i])
    if idx_a == 0: continue
    ans += idx_a
print(ans)

Fixed submission:
import bisect

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

def get_t_strs(T):
  lenT = len(T)
  strs = ['?'*lenT, T]
  for i in range(1,lenT):
    cmbs = list(combinations([i for i in range(lenT)],i))
    for cmb in cmbs:
      T_list = [t for t in T]
      for idx in cmb: T_list[idx] = '?'
      strs.append(''.join(T_list))
  return strs

S,T = input(), input()
if S.count('?') == 0:
  print(S)
  exit()

idx_options = []
t_strs = get_t_strs(T)
for t_str in t_strs:
  idx = S.rfind(t_str)
  if idx != -1: idx_options.append(idx+1)

if len(idx_options) == 0: print('UNRESTORABLE')
else:
  max_idx = max(idx_options)
  print((S[:max_idx-1] + T + S[max_idx+len(T)-1:]).replace('?','a'))

Fixed submission:
def is_matched(i, inputS, T):
  for s,t in zip(inputS, T):
    if s == '?': continue
    if s != t: return False
  return True

S, T = input(), input()
lenS, lenT = len(S), len(T)
matched_i = None
ans = []
for i in range(lenS-lenT+1):
  if is_matched(i, S[i:i+lenT], T):
    tmpS = S.replace('?', 'a')
    ans.append(''.join([s for s in S[:i].replace('?', 'a') + T + S[i+lenT:].replace('?', 'a')]))
if ans == []: print('UNRESTORABLE')
else: print(sorted(ans)[0])