Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02684 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:34:02 2020

@author: shinba
"""
import sys
sys.setrecursionlimit(500000)

n,k = map(int,input().split())

a = list(map(int,input().split()))

data = [0]*n
data[0] = 1

li = [0]

while k > 0:
    b = a[li[-1]]-1
    if data[b] == 0:
        data[b] = 1
        li.append(b)
        k -= 1
    else:
        break

if k != 0:
    for i in range(len(li)-1,-1,-1):
        if li[i] == b:
            s = i
            break
    newli = li[s:]
    l = (k-1) % len(newli)
    print(newli[l]+1)
else:
    print(li[-1]+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:34:02 2020

@author: shinba
"""


n,k = map(int,input().split())

a = list(map(int,input().split()))

data = [0]*n
data[0] = 1

li = [0]

while k > 0:
    b = a[li[-1]]-1
    if data[b] == 0:
        data[b] = 1
        li.append(b)
        k -= 1
    else:
        break

if k != 0:
    for i in range(len(li)-1,-1,-1):
        if li[i] == b:
            s = b
            break
    newli = li[b:]
    l = (k-1) % len(newli)
    print(li[l]+1)
else:
    print(li[-1]+1)
Problem p02687 (python)

Fixed submission:
S = input()

if S == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
S = input()

if S = "ABC":
    print("ARC")
else:
    print("ABC")
Problem p02690 (python)

Fixed submission:
X = int(input())

B = [n**5 for n in range(200)]

A = []

for i in range(200):
    a = i**5- X if i**5 >= X else X-i**5
    A.append(a)

for j in range(200):
    if A[j] in B:
        a = j
        b = B.index(A[j])
        if a**5-b**5 == X:
            print(a,b)
        elif a**5+b**5 == X:
            print(a,-b)
        else:
            print(b,a)
        break

Buggy submission (verdict: Runtime Error):
X = int(input())

B = [n**5 for n in range(300)]

A = []

for i in range(300):
    a = i**5- X if i**5 >= X else X-i**5
    A.append(a)

for j in range(300):
    if A[j] in B:
        a = j
        b = B.index(A[j])
        if a**5-b**5 = X:
            print(a,b)
        elif a**+b**5 = X:
            print(a,-b)
        break
Problem p02714 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""
import sys

N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

if R==[] or G==[] or B==[]:
    print(0)
    sys.exit()
    
ans = len(R)*len(G)*len(B)

m = min(B)
M = max(B)

for i in R:
    for j in G:
        a = 2*j - i 
        b = (i+j)//2 if (i+j)%2 == 0 else 0
        c = 2*i - j
        if m <= a <= M:
            if S[a-1] == "B":
                ans -= 1
        if b != 0 and S[b-1] == "B":
            ans -= 1
        if m <= c <= M:
            if S[c-1] == "B":
                ans -= 1
            
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""

N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

ans = len(R)*len(G)*len(B)

m = min(B)
M = max(B)

for i in R:
    for j in G:
        a = 2*j - i 
        b = (i+j)//2 if (i+j)%2 == 0 else 0
        c = 2*i - j
        if m <= a <= M:
            if S[a-1] == "B":
                ans -= 1
        if b != 0 and S[b-1] == "B":
            ans -= 1
        if m <= c <= M:
            if S[c-1] == "B":
                ans -= 1
            
print(ans)
Problem p02845 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
    ans *= data.count(i)
    ans %= mod
    if ans == 0:
        break
    data[data.index(i)] += 1
print(ans)

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

Fixed submission:
from collections import deque,defaultdict
n = int(input())
data = [[] for _ in range(n)]
sides = []
for _ in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    data[a].append(b)
    data[b].append(a)
    sides.append((a,b))
I = defaultdict(lambda:0)
cs = [0]*n
used = [0]*n
q = deque([0])
used[0]=1
k = 0
while q:
    u = q.popleft()
    if k < len(data[u]):
        k = len(data[u])
    cur = 1
    for v in data[u]:
        if used[v]:continue
        if cur==cs[u]:cur+=1
        cs[v] = cur
        I[(u,v)] = cur
        I[(v,u)] = cur
        cur += 1
        used[v] = 1
        q.append(v)
print(k)
for i,j in sides:
    print(I[(i,j)])

Buggy submission (verdict: Runtime Error):
from collections import deque
from heapq import heapify,heappop,heappush
n = int(input())
data = [[] for _ in range(n)]
color = [[-1]*n for _ in range(n)]
sides = []
for _ in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    data[a].append(b)
    data[b].append(a)
    sides.append((a,b))
kinds = -1
m = -1
for i in range(n):
    if kinds < len(data[i]):
        kinds = len(data[i])
        m = i
unused = [[i for i in range(1,kinds+1)] for _ in range(n)]
against = [[] for _ in range(n)]
for i in range(n):
    heapify(unused[i])
    heapify(against[i])
print(kinds)
q = deque([m])
visited = [0]*n
while q:
    p = q.popleft()
    visited[p] = 1
    for i in data[p]:
        if visited[i]:
            continue
        while against[p] and (unused[p][0] == against[p][0]):
            heappop(against[p])
            heappop(unused[p])
        color[p][i] = unused[p][0]
        color[i][p] = unused[p][0]
        q.append(i)
        heappush(against[i],heappop(unused[p]))
for i,j in sides:
    print(color[i][j])

Buggy submission (verdict: Runtime Error):
n = int(input())
sides = []
data = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    data[a].append(b)
    data[b].append(a)
    sides.append((a,b))
kinds = -1
for i in range(n):
    kinds = max(kinds,len(data[i]))
print(kinds)
strage = [[i for i in range(1,kinds+1)] for i in range(n)]
for i,j in sides:
    p = strage[i].pop()
    q = strage[j].pop()
    if p == q:
        print(p)
    elif p > q:
        print(q)
        strage[i].remove(q)
        strage.append(p)
    else:
        print(p)
        strage[j].remove(p)
        strage.append(q)
Problem p03001 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

w,h,x,y = map(int,input().split())

if w%2 == 0 and h%2 == 0:
    if w//2 == x and h//2 == y:
        print((h*w)/2,1)
        sys.exit()
        
print(h*w/2,0)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

w,h,x,y = map(int,input().split())

if (x==0 and y==0) or (x==w and y==0) or (x==0 and y==h) or (x==w and y==h):
    print((w*h)/2,0)
    sys.exit()
if w != x:
    if y/x == h/w or y/(w-x) == h/w:
        #print(y/x,h/w,y/(w-x))
        if y/x == h/w and y/(w-x) == h/w:
            print((w*h)/2,1)
        else:
            print((w*h)/2,0)
        sys.exit()
    
a1 = h*min(w-x,x)
a2 = w*min(h-y,y)

if a1 == a2:
    print(a1,1)
else:
    print(max(a1,a2),0)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

w,h,x,y = map(int,input().split())

if (x==0 and y==0) or (x==w and y==0) or (x==0 and y==h) or (x==w and y==h):
    print((w*h)/2,0)
    sys.exit()
if y/x == h/w or y/(w-x) == h/w:
    #print(y/x,h/w,y/(w-x))
    if y/x == h/w and y/(w-x) == h/w:
         print((w*h)/2,1)
    else:
        print((w*h)/2,0)
    sys.exit()
    
a1 = h*min(w-x,x)
a2 = w*min(h-y,y)

if a1 == a2:
    print(a1,1)
else:
    print(max(a1,a2),0)
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
rw = s.count(".")
lb = 0
M = rw+lb
for i in range(n):
    if s[i] =="#":
        lb += 1
    else:
        rw -= 1
    M = min(M,rw+lb)
print(M)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
while s[-1] == "#":
    s.pop()
s = "".join(s)
n = len(s)
data = []
ind = []
cnt = 0
ans = 0
for i in range(n):
    if s[i] == "#":
        cnt += 1
        ind.append(i)
    data.append(cnt)
if not ind:
    print(0)
    exit()
for i in ind:
    m = data[-1]-data[i]+1
    l = n-m-i
    if l > m:
        ans += 1
    else:
        print(ans+l)
        break
else:
    print(ans)
Problem p03160 (python)

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

dp = [float("inf")]*N
dp[0] = 0

for i in range(1,N):
    if i == 1:
        dp[i] = min(dp[i],dp[i-1] + abs(H[i]-H[i-1]))
    else:
        dp[i] = min(dp[i],dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])
Problem p03229 (python)

Fixed submission:
from collections import deque
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
if n == 2:
    print(abs(A[1]-A[0]))
    exit()
A.sort()
s = sum(A)
if n % 2 == 1:
    small = 0
    for i in range(n//2):
        small += A[i]
    big = s - small
    ans1 = 2*big-2*small-A[n//2]-A[n//2+1]
    small += A[n//2]
    big = s-small
    ans2 = 2*big -2*small+A[n//2]+A[n//2-1]
    print(max(ans1,ans2))
else:
    small = 0
    for i in range(n//2):
        small += A[i]
    big = s -small
    ans1 = 2*big -2*small + A[n//2-1]-A[n//2]
    small += A[n//2]
    big = s -small
    ans2 = 2*big-2*small+A[n//2]-A[n//2+1]
    print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
dq = deque(sorted(A))
ans = deque([dq.popleft()])
ans.append(dq.pop())
ans.appendleft(dq.pop())
flag = True
while dq:
    if flag:
        ans.append(dq.popleft())
        if dq:
            ans.appendleft(dq.popleft())
            flag = False
    else:
        ans.append(dq.pop())
        if dq:
            ans.appendleft(dq.pop())
            flag = True
B = list(ans)
s = 0
for i in range(n-1):
    s += abs(B[i+1]-B[i])
print(s)
Problem p03282 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1
    if cnt == len(s):
        break

if cnt >= k:
    print(1)
else:
    print(s[cnt])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1

if cnt >= k:
    print(1)
else:
    print(s[cnt])
Problem p03290 (python)

Fixed submission:
D,G = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(D)]

#print(pc)
ans = float("inf")

for i in range(2**D):
    sum = 0
    count = 0
    rem = set(range(1,D+1))
    for j in range(D):
        if (i >> j) & 1:
            sum += pc[j][0]*100*(j+1)+pc[j][1]
            count += pc[j][0]
            rem.discard(j+1)
    if sum < G:
        k = max(rem)-1
        n = min(pc[k][0],-(-(G-sum)//((k+1)*100)))
        count += n
        sum += n*100*(k+1)
    if sum >= G:
        ans = min(ans,count)

print(ans)

Buggy submission (verdict: Runtime Error):
D,G = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(D)]

ans = float("inf")
for i in range(2**D):
    sum = 0
    count = 0
    rem = set(range(1,D+1))
    for j in range(D):
        if (i >> j) & 1:
            sum += pc[j][0]*100*j+pc[j][1]
            count += pc[j][0]
            rem.discard(j+1)
    if sum < G:
        k = max(rem)-1
        n = min(pc[k][0],-(-(G-sum)//((k+1)*100))
        count += n
        sum += n*100*(k+1)
    if sum >= G:
        ans = min(ans,count)

print(ans)
Problem p03363 (python)

Fixed submission:
from collections import Counter
n = int(input())
A = [0]
for i in map(int,input().split()):
    A.append(A[-1]+i)
ans = 0
B = Counter(A)
for i in B.values():
    if i >= 2:
        ans += int(i*(i-1)/2)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import combinations
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

def comb(n,m):
    return kaijou(n)/kaijou(m)/kaijou(n-m)

n = int(input())
a = list(map(int,input().split()))
A = [0]
for i in a:
    A.append(A[-1]+i)
ans = 0
B = Counter(A)
for i in B.values():
    if i >= 2:
        ans += comb(i,2)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import combinations
from functools import lru_cache
@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

def comb(n,m):
    return int(kaijou(n)/kaijou(m)/kaijou(n-m))

n = int(input())
a = list(map(int,input().split()))
A = [0]
for i in a:
    A.append(A[-1]+i)
ans = 0
B = Counter(A)
for i in B.values():
    if i >= 2:
        ans += comb(i,2)
print(ans)
Problem p03380 (python)

Fixed submission:
import sys
import bisect
n = int(input())
A = list(map(int,input().split()))
A.sort()
m = A[-1]
if n == 2:
    print(A[-1],A[0])
    sys.exit()
i = bisect.bisect_left(A,m//2)
if i == 0:
    print(m,A[0])
else:
    if m - A[i] < A[i-1]:
        print(m,A[i-1])
    else:
        print(m,A[i])

Buggy submission (verdict: Runtime Error):
import bisect
from functools import lru_cache

@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

def comb(n,r):
    return kaijou(n)/kaijou(r)/kaijou(n-r)

n = input()
A = list(map(int,input().split()))
A.sort()
m = A[-1]
i = bisect.bisect_left(A,m//2)
if i == 0:
    if comb(m,A[i]) >= comb(m,A[i+1]):
        print(m,A[i])
    else:
        print(m,A[i+1])
else:
    if comb(m,A[i-1]) >= comb(m,A[i]):
        print(m,A[i-1])
    else:
        print(m,A[i])
Problem p03436 (python)

Fixed submission:
from collections import deque

def bfs():
    d = [[float("inf") for i in range(W)] for j in range(H)]
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    que = deque([])
    que.append((0,0))
    d[0][0] = 0
    while que:
        p = que.popleft()
        if p[0] == W-1 and p[1] == H-1:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0<=nx<W and 0<=ny<H and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                que.append((nx,ny))
                d[ny][nx] = d[p[1]][p[0]] + 1
    return d[H-1][W-1]

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

cnt = 1

for i in range(H):
    cnt += maze[i].count("#")

if bfs() == float("inf"):
    print(-1)
else:
    print(H*W-bfs()-cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque

def bfs():
    d = [[float("inf") for i in range(W)] for j in range(H)]
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    que = deque([])
    que.append((0,0))
    d[0][0] = 0
    while que:
        p = que.popleft()
        if p[0] == W-1 and p[1] == H-1:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0<=nx<W and 0<=ny<H and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                que.append((nx,ny))
                d[ny][nx] = d[p[1]][p[0]] + 1
    return d[H-1][W-1]

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

cnt = 1

for i in range(H):
    cnt += maze[i].count("#")

if d[H-1][W-1] == float("inf"):
    print(-1)
else:
    print(H*W-bfs()-cnt)
Problem p03485 (python)

Fixed submission:
a, b = map(int, input().split())

c = a + b

if c % 2 == 0:
    print(int(c / 2))
else:
    print(int(int(c / 2) + 1))

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())

a.sort()
b.sort(reverse=True)


for i in range(int(len(b))):
    c =(a[i],b[i])
    d = sorted(c)
    if i != int(len(b))-1:
        if a[i] == b[i]:
            continue
        elif c == d and a[i] != b[i]:
            print("No")
            break
        else:
            print("Yes")
            break
    if i == int(len(b))-1:
        if a[i] == b[i]:
            if int(len(a)) >= int(len(b)):
                print("No")
            else:
                print("Yes")
        elif c == d and a[i] != b[i]:
            print("No")
            break
        else:
            print("Yes")
            break

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

c = a + b

if c % 2 == 0
    print(int(c/2))
else:
    print(int(c // 2 + 1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

c = a + b

if c % 2 == 0
    print(int(c/2))
else:
    print(int(c // 2 + 1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

c = a + b

if c % 2 == 0
    print(int(c/2))
else:
    print(int(c // 2 + 1))
Problem p03486 (python)

Fixed submission:
a = list(input())
b = list(input())

a.sort()
b.sort(reverse=True)
f = [int(len(b)), int(len(a))]
e = min(f)
for i in range(int(e)):
    c =[a[i],b[i]]
    d = sorted(c)
    if i != int(e)-1:
        if a[i] == b[i]:
            continue
        elif c != d:
            print("No")
            break
        else:
            print("Yes")
            break
    if i == int(e)-1:
        if a[i] == b[i]:
            if int(len(a)) >= int(len(b)):
                print("No")
            else:
                print("Yes")
        elif c != d:
            print("No")
            break
        else:
            print("Yes")
            break

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())

a.sort()
b.sort(reverse=True)


for i in range(int(len(b))):
    c =(a[i],b[i])
    d = sorted(c)
    if i != int(len(b))-1:
        if a[i] == b[i]:
            continue
        elif c == d and a[i] != b[i]:
            print("No")
            break
        else:
            print("Yes")
            break
    if i == int(len(b))-1:
        if a[i] == b[i]:
            if int(len(a)) >= int(len(b)):
                print("No")
            else:
                print("Yes")
        elif c == d and a[i] != b[i]:
            print("No")
            break
        else:
            print("Yes")
            break

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())

a.sort()
b.sort(reverse=True)


for i in range(int(len(b))):
    c =(a[i],b[i])
    d = sorted(c)
    if i != int(len(b))-1:
        if a[i] == b[i]:
            continue
        elif c == d and a[i] != b[i]:
            print("Yes")
            break
        else:
            print("No")
            break
    if i == int(len(b))-1:
        if a[i] == b[i]:
            if int(len(a)) >= int(len(b)):
                print("No")
            else:
                print("Yes")
        elif c == d and a[i] != b[i]:
            print("Yes")
            break
        else:
            print("No")
            break
Problem p03503 (python)

Fixed submission:
n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*n
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])

Buggy submission (verdict: Runtime Error):
n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*10
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])
Problem p03523 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 12:45:03 2020

@author: shinba
"""
import sys

S = list(input())

if S.count("K") != 1 or S.count("I") != 1 or S.count("H") != 1 or S.count("B") != 1 or S.count("R") != 1:
    print("NO")
    sys.exit()    

l = len(S)

k = S.index("K")
i = S.index("I")
h = S.index("H")
b = S.index("B")
r = S.index("R")

while "A" in S:
    S.remove("A")
    
if len(S) != 5:
    print("NO")
    sys.exit()
    

if (0 <= k <= 1) and (h - k == 2) and (1 <= b - h <= 2) and (1 <= r - b <= 2) and (l-2 <= r <= l-1):
    if k < i < h < b < r:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 12:45:03 2020

@author: shinba
"""
import sys

S = list(input())

if S.count("K") != 1 and S.count("I") != 1 and S.count("H") != 1 and S.count("B") != 1 and S.count("R") != 1:
    print("NO")
    sys.exit()    

k = S.index("K")
i = S.index("I")
h = S.index("H")
b = S.index("B")
r = S.index("R")

if (0 <= k <= 1) and (i - k == 1) and (h - i == 1) and (0 <= b - h <= 1) and (0 <= r - b <= 1):
    if k < i < h < b < r:
        print("YES")
    else:
        print("NO")
else:
    print("NO")
Problem p03599 (python)

Fixed submission:
A,B,C,D,E,F = map(int,input().split())

water = set()
sugar = set()

s = 0
a = 0
b = 0

for i in range(30):
    for j in range(30-i):
        if 100*A*i+100*B*j <= F:
            water.add(100*A*i+100*B*j)

water.remove(0)

for i in range(3000):
    for j in range(3000-i):
        if C*i+D*j <= F:
            sugar.add(C*i+D*j)

sugar.remove(0)

WATER = list(water)
SUGAR = list(sugar)

for i in WATER:
    for j in SUGAR:
        if (j <= i*E/100) and (i+j <= F):
            if s == 0:
                s = 100*j /(i + j)
                a = i
                b = j
            else:
                if s < 100*j /(i + j):
                    s = 100*j /(i + j)
                    a = i
                    b = j

if a == 0 and b == 0:
    print(100*A,0)
else:
    print(a+b,b)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

water = set()
sugar = set()

s = 0
a = 0
b = 0

for i in range(30):
    for j in range(30-i):
        if 100*A*i+100*B*j <= F:
            water.add(100*A*i+100*B*j)

water.remove(0)

for i in range(3000):
    for j in range(3000-i):
        if C*i+D*j <= F:
            sugar.add(C*i+D*j)

sugar.remove(0)

WATER = list(water)
SUGAR = list(sugar)

for i in WATER:
    for j in SUGAR:
        if (j <= i*E/100) and (i+j <= F):
            if s == 0:
                s = 100*j /(i + j)
                a = i
                b = j
            else:
                if s < 100*j /(i + j):
                    s = 100*j /(i + j)
                    a = i
                    b = j

if a = 0 and b = 0:
    print(100*A,0)
else:
    print(a+b,b)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

water = set()
sugar = set()

s = 0

for i in range(30):
    for j in range(30-i):
        if 100*A*i+100*B*j <= F:
            water.add(100*A*i+100*B*j)

water.remove(0)

for i in range(3000):
    for j in range(3000-i):
        if C*i+D*j <= F:
            sugar.add(C*i+D*j)

sugar.remove(0)

WATER = list(water)
SUGAR = list(sugar)

for i in WATER:
    for j in SUGAR:
        if (j <= i*E/100) and (i+j <= F):
            if s == 0:
                s = 100*j /(i + j)
                a = i
                b = j
            else:
                if s < 100*j /(i + j):
                    s = 100*j /(i + j)
                    a = i
                    b = j

print(a+b,b)