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

Fixed submission:
N,x= map(int, input().split())
Alist = list(map(int, input().split())) 
res = 0
if Alist[0] >x:
    res = Alist[0]-x
    Alist[0] = x
    
for i in range(0,N-1):    
    if Alist[i] + Alist[i+1] > x:
        de = Alist[i+1] + Alist[i] - x
        Alist[i+1] = Alist[i+1] - de
        res = res + de 

print(res)

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

if Alist[0] >x:
    res = Alist[0]-x
    Alist[0] = x
    
for i in range(0,N-1):    
    if Alist[i] + Alist[i+1] > x:
        de = Alist[i+1] + Alist[i] - x
        Alist[i+1] = Alist[i+1] - de
        res = res + de 

print(res)
Problem p04032 (python)

Fixed submission:
s = input()
slist = list(s)

if len(slist) ==2:
    if len(set(slist)) ==1:
        print(1,2)
        exit()
    else:
        print("-1 -1")
        exit()

else:
    for i in range(1,len(slist)-1):
        if len(set(slist[i-1:i+2])) !=3:
            print(i,i+2)
            exit()
            
    print("-1 -1")

Buggy submission (verdict: Runtime Error):
if len(slist) ==2:
    if len(set(slist)) ==1:
        print(1,2)
        exit()
    else:
        print("-1 -1")
        exit()

else:
    for i in range(1,len(slist)-1):
        if len(set(slist[i-1:i+2])) !=3:
            print(i,3)
            exit()
            
    print("-1 -1")
Problem p02573 (python)

Fixed submission:
def root(x):
  if F[x] < 0:
    return x
  else:
    F[x] = root(F[x])
    return F[x]

def unite(x, y):
  x = root(x)
  y = root(y)
  if x == y:
    return
  if x > y:
    x, y = y, x
  F[x] += F[y]
  F[y] = x

N, M = map(int, input().split())
F = [-1] * N

for m in range(M):
  a, b = map(int, input().split())
  unite(a - 1, b - 1)
ans = 0
for f in F:
  ans = min(ans, f)
print(-ans)

Buggy submission (verdict: Runtime Error):
def root(x):
  if F[x] < 0:
    return x
  else:
    F[x] = root(F[x])
    return F[x]

def unite(x, y):
  rx = root(x)
  ry = root(y)
  if rx == ry:
    return
  if rx > ry:
    x, y = y, x
  F[x] += F[y]
  F[y] = x

N, M = map(int, input().split())
F = [-1] * N

for m in range(M):
  a, b = map(int, input().split())
  unite(a - 1, b - 1)
ans = 0
for f in F:
  ans = min(ans, f)
print(-ans)
Problem p02639 (python)

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

for i in range(len(X)):
  if X[i] == 0:
    print(i + 1)

Buggy submission (verdict: Runtime Error):
import math

def isPrime(n):
  if n == 1:
    return False
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True

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

if len(A) == 1:
  print(N)
  exit()

if A[0] == 1 and A[1] == 1:
  print(N)
  exit()
if A[0] == 1 and A[1] != 1:
  print(N - 1)
  exit()

for i in range(N):
  x = A[i]
  if isPrime(x):
    if i - 1 >= 0:
      if x == A[i - 1]:
        cnt -= 1
        continue
    if i + 1 < N:
      if x == A[i + 1]:
        cnt -= 1
        continue
    continue
    
  for j in range(i):
    y = A[j]
    if x % y == 0:
      cnt -= 1
      break
print(cnt)
Problem p02642 (python)

Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]
B = [0] * m
for a in A:
  B[a - 1] += 1
  if B[a - 1] == 1:
    for j in range(a * 2, m + 1, a):
      B[j - 1] = 2
print(B.count(1))

Buggy submission (verdict: Runtime Error):
import math

def isPrime(n):
  if n == 1:
    return False
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True

def isDiv(x, y):
  if x % y == 0:
    return True
  else:
    return False

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

if A[0] == 1 and A[1] == 1:
  print(N)
  exit()
if A[0] == 1 and A[1] != 1:
  print(N - 1)
  exit()

for i in range(N):
  x = A[i]
  if isPrime(x):
    if i - 1 >= 0:
      y = A[i - 1]
      if isDiv(x, y):
        cnt -= 1
        continue
    if i + 1 < N:
      y = A[i + 1]
      if isDiv(x, y):
        cnt -= 1
        continue
    continue
  for j in range(N):
    if i == j:
      continue

    y = A[j]
    if x < y:
      break
    if isDiv(x, y):
      cnt -= 1
      break
print(cnt)
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 p02755 (python)

Fixed submission:
A, B = map(int, input().split())
f = False
ans = 0
for i in range(1, 1100):
  if i * 8 // 100 == A and i // 10 == B:
    f = True
    ans = i
    break
print(ans if f else -1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split
f = False
n = int(A / 8 * 100)
while n * 0.08 //1 == A:
  if n * 0.1 // 1 == B:
    f = True
    break
  n += 1
print(n if f else -1)
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 0
exist = False
if N == 1:
  x = 0
else:
  x = 10 ** (N - 1)
for i in range(x, 1000):
  s = str(i)
  f = True
  for j in range(M):
    if int(s[sc[j][0] - 1]) != sc[j][1]:
      f = False
      break
  if f:
    ans = i
    exist = True
    break
print(ans if exist else -1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 0
exist = False
if N == 1:
  x = 0
else:
  x = 10 ** (N - 1)
for i in range(x, 1000):
  s = str(i)
  f = True
  for j in range(len(s)):
    if int(s[sc[j][0] - 1]) != sc[j][1]:
      f = False
      break
  if f:
    ans = i
    exist = True
    break
print(ans if exist else -1)
Problem p02789 (python)

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

if N == M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input())

if N == M:
  print("Yes")
else:
  print("No")
Problem p02817 (python)

Fixed submission:
S, T = map(str, input().split())

print("{}{}".format(T, S))

Buggy submission (verdict: Runtime Error):
S, T = map(str, input().split())

print("{}{}",format(T, S))
Problem p02818 (python)

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

if K <= A:
  A = A - K
elif A < K <= A + B:
  B = B - ( K - A )
  A = 0
else:
  A = 0
  B = 0
print(A, B)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

if K <= A:
  res_A = A - K
elif A < K <= A + B:
  res_A = 0
  res_B = B - ( K - A )
else:
  res_A = 0
  res_B = 0
print(res_A, res_B)
Problem p02911 (python)

Fixed submission:
N, K, Q = map(int, input().split())
A = [0 for _ in range(N)]
for i in range(Q):
  A[int(input()) - 1] += 1

ans = []
for a in A:
  if K + a - Q > 0:
    ans.append("Yes")
  else:
    ans.append("No")
print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
N, K, Q = map(int, input().split())
A = ""
for i in range(Q):
  A += input()

res = ["No"] * N
for i in range(Q):
  seikai = A.count(A[i])
  if K - Q + seikai > 0:
    res[i - 1] = "Yes"
  
for r in res:
  print(r)
Problem p02921 (python)

Fixed submission:
S = input()
T = input()

cnt = 0

for i in range(3):
  if S[i] == T[i]:
    cnt += 1
print(cnt)

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

cnt = 0

for i in range(3)

if S[i] == T[i]:
  cnt += 1
print(cnt)
Problem p02957 (python)

Fixed submission:
A, B = map(int, input().split())

if A % 2 != B % 2:
  K = "IMPOSSIBLE"
else:
  # B - K = - (A - K)
  # 2K = B - A
  K = int((B + A) / 2)
print(K)

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

if A % 2 != B % 2:
  K = "IMPOSSIBLE"
elif:
  # A - K = - (B - K)
  # 2K = A + B
  K = int((A + B) / 2)
print(K)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())

if R - L >= 2019:
  print(0)
else:
  ans = 2018
  for i in range(L, R):
    for j in range(i + 1, R + 1):
      ans = min(ans, (i * j) % 2019)
  print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())

if R - L >= 2019:
  print(0)
else:
  ans = 2018
  for i in range(L, R):
    for j in range(i + 1, R + 1):
      ans = min(ans, (i * j) % 2019)
print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())

if R - L > 2019:
  print(0)
else:
  ans = 2018
  for i in range(L, R):
    for j in range(i + 1, R + 1):
      ans = min(ans, (i * j) % 2019)
print(ans)
Problem p02999 (python)

Fixed submission:
X, A = map(int, input().split())

if X < A:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
X, A = map(int, input().split())

if X < A:
  print(0)
else:
  pfint(10)
Problem p03029 (python)

Fixed submission:
A, P = map(int, input().split())

print(int((A*3+ P) //2))

Buggy submission (verdict: Runtime Error):
A, P = map(int, input())

print(int((A*3+ P) //2))
Problem p03035 (python)

Fixed submission:
A, B = map(int, input().split())

if A >= 13:
  print(B)
elif 13 > A >= 6:
  print(B//2)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())

if A >= 13:
  print(B)
elif 13 > A >= 6:
  print(B//2)
else:
  print(0)
Problem p03059 (python)

Fixed submission:
A, B, T = map(int, input().split())
cnt = 0

for i in range(A, T+1, A):
  cnt += B
print(cnt)

Buggy submission (verdict: Runtime Error):
A, B, T = map(int, input().split())
cnt = 0

for i in range(0, T+0.5, A):
  cnt += B
print(cnt)
Problem p03071 (python)

Fixed submission:
A, B = map(int, input().split())

if A - B > 1:
  x = 2 * A - 1
elif B - A > 1:
  x = 2 * B - 1
else:
  x = A + B

print(x)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
x = 0

if A - B > 1:
  x = 2A - 1
elif B - A > 1:
  x = 2B - 1
else:
  x = A + B

print(x)

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

if A - B > 1:
  x = 2A - 1
elif B - A > 1:
  x = 2B - 1
else:
  x = A + B

print(x)

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

if A - B > 1:
  x = 2A - 1
elif B - A > 1:
  x = 2B - 1
else:
 S = A + B

print(x)
Problem p03219 (python)

Fixed submission:
X, Y = map(int, input().split())

print(X + Y//2)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().sptit())

print(X + Y//2)
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
ans = []

if B + 1 - A < 2 * K:
  ans = [i for i in range(A, B + 1)]
else:
  ans = [i for i in range(A, A + K)] + [i for i in range(B + 1 - K, B + 1)]
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
ans = []
for i in range(A, min(A + K, B)):
  ans.append(i)

for i in range(max(ans[-1] + 1, B - K + 1), B + 1):
  ans.append(i)

for a in ans:
  print(a)
Problem p03408 (python)

Fixed submission:
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
ans = 0

for i in list(set(S)):
  tmp = S.count(i) - T.count(i)
  if ans < tmp:
    ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
ans = 0

for i in list(set(X)):
  tmp = S.count(i) - T.count(i)
  if ans < tmp:
    ans = tmp
print(ans)
Problem p03423 (python)

Fixed submission:
N = int(input())
print(N//3)

Buggy submission (verdict: Runtime Error):
N = int(input)
print(N//3)
Problem p03433 (python)

Fixed submission:
N = int(input())
A = int(input())

if N%500 <= A:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input)
A = int(input)

if N%500 <= A:
  print("Yes")
else:
  print("No")
Problem p02658 (python)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
if min(A) == 0:
    print(0)
else:
    ans = 1
    M = 10**18
    for i in A:
        ans *= i
        if ans > M:
            print(-1)
            break
    else:
        print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 1
for i in range(N):
    ans *= int(input())
if ans <= 10**18:
    print(ans)
else:
    print(-1)
Problem p02910 (python)

Fixed submission:
s = input()
for i, j in enumerate(s):
    if i % 2 == 0 and j == 'L':
        print('No')
        break
    elif i % 2 == 1 and j == 'R':
        print('No')
        break
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
for i, j in enumerate(s):
	if i % 2 == 0 and j == 'L':
		print('No')
        return
    elif i % 2 == 1 and j == 'R':
		print('No')
        return
print('Yes')
Problem p02724 (python)

Fixed submission:
X = int(input())
ans = 0
ans += X//500 * 1000
X = X % 500
ans += X // 5 * 5

print(ans)

Buggy submission (verdict: Runtime Error):
X = int(input())
ans = 0
ans += X//500 * 1000
x = x % 500
ans += X // 500 * 5

print(ans)
Problem p02755 (python)

Fixed submission:
A, B = map(int, input().split())

for i in range(1,1010):
  if (int(i*0.08)==A)&(int(i*0.1)==B):
    print(i)
    break
else:
    print(-1)

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

for i in range(1,1010):
  if (i*0.08//A==1)&(i*0.1//B==1):
    ans = i
    break
    
print(ans)
Problem p02760 (python)

Fixed submission:
A = []
B = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

test = [[0]*3 for _ in range(3)]

for i in range(N):
    B.append(int(input()))

for b in B:
    for m in range(3):
        for n in range(3):
            if b == A[m][n]:
                test[m][n] =1

ans = 'No'

for i in range(3):
    if sum(test[i]) == 3:
        ans = 'Yes'
    if test[0][i]+test[1][i]+test[2][i] == 3:
        ans = 'Yes'

if test[0][0]+test[1][1]+test[2][2] == 3:
    ans = 'Yes'

if test[2][0]+test[1][1]+test[0][2] == 3:
    ans = 'Yes'

print(ans)

Buggy submission (verdict: Runtime Error):
A = []
B = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

test = [[0]*3]*3

for i in range(N):
    b = int(input())
    for m in range(3):
        for n in range(3):
            if b == A[m][n]:
                test[m][n] =1

ans = 'No'
for i in range(3):
    if sum(test[i]) == 3:
        ans = 'Yes'
    if test[1][i]+test[2][i]+test[3][i] == 3:
        ans = 'Yes'

if test[0][0]+test[1][1]+test[2][2] == 3:
    ans = 'Yes'

if test[2][0]+test[1][1]+test[0][2] == 3:
    ans = 'Yes'

print(ans)

Buggy submission (verdict: Runtime Error):
A = []

for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

check = [0,0,0]*3
for n in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                 check[i][j] = 1

ans = 'No'

for i in range(3):
    if check[i][0]+check[i][1]+check[i][2]==3:
        ans = 'Yes'

for i in range(3):
    if check[0][i]+check[1][i]+check[2][i]==3:
        ans = 'Yes'

if check[0][0]+check[1][1]+check[2][2] == 3:
    ans = 'Yes'

if check[0][2]+check[1][1]+check[2][0] == 3:
    ans = 'Yes'

print(ans)

Buggy submission (verdict: Runtime Error):
A = []

for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

check = [0]*3*3
for n in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                 check[i][j] = 1

ans = 'No'

for i in range(3):
    if check[i][0]+check[i][1]+check[i][2]==3:
        ans = 'Yes'

for i in range(3):
    if check[0][i]+check[1][i]+check[2][i]==3:
        ans = 'Yes'

if check[0][0]+check[1][1]+check[2][2] == 3:
    ans = 'Yes'

if check[0][2]+check[1][1]+check[2][0] == 3:
    ans = 'Yes'

print(ans)
Problem p02797 (python)

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

if S == 10**9:
  ans = [S]*K +[1]*(N-K)
else:
  ans = [S]*K +[S+1]*(N-K)

ans_txt=''

for s in ans:
  ans_txt += str(s)+' '

print(ans_txt)

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

if S == 10**9:
  [S]*K +[1]*(N-K)
else:
  ans = [S]*K +[S+1]*(N-K)

ans_txt=''

for s in ans:
  ans_txt += str(s)+' '

print(ans_txt)
Problem p02801 (python)

Fixed submission:
C = input()

ans = ''
for i in range(26):
  if chr(ord('a') + i) == C:
    ans = chr(ord('a') + i + 1)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n,k,m = map(int, input().split())
a = input().split()
a = [int(_a) for _a in a]
ans = m*n - sum(a)
if ans >= k:
  ans = -1
print(ans)
Problem p02802 (python)

Fixed submission:
n,m = map(int, input().split())
ac = [0]*n
wa = [0]*n

for i in range(m):
  p,s = input().split()
  p = int(p)-1
  if s == 'AC':
     ac[p] = 1
  elif s == 'WA':
    if ac[p] == 0:
      wa[p] += 1

num_ac = 0
num_wc = 0

for a, w in zip(ac,wa):
  num_ac += a
  if a > 0:
    num_wc += w  
print(num_ac,num_wc)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
num_ac = 0
num_wa = 0
tmp_num_wa = 0
answerd = []

for i in range(m):
  p,s = input().split()
  if p in answerd:
    continue
  if s == 'WA':
    tmp_num_wa += 1
  if s == 'AC':
    num_ac += 1
    num_wa += tmp_num_wa
    tmp_num_wa = 0
    answerd.append(_p)
    
print(num_ac, num_wa)
Problem p02818 (python)

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

if k >= a:
  _a = 0
  if k-a >= b:
    _b = 0
  else:
    _b = b-(k-a)
else:
  _a = a - k
  _b = b
     
print('{} {}'.format(_a,_b))

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

if k >= a:
  _a = 0
  if k-a >= b:
    _b = 0
  else:
    _b = b-(k-a)
else:
  _a = a - k
     
print('{} {}'.format(_a,_b))
Problem p02579 (python)

Fixed submission:
from collections import deque


def is_inside(x, y, W, H, G):
    return (x <= H-1 and y <= W-1 and
            x >= 0 and y >= 0 and
            G[x][y] != "#")


def main():
    H, W = map(int, input().split())
    Cx, Cy = map(int, input().split())
    Dx, Dy = map(int, input().split())

    G = [list(input()) for _ in range(H)]
    INF = int(1e9)
    q = deque()
    q.append((Cx-1, Cy-1, -INF, Cx-1, Cy-1))
    warps = [[INF] * W for _ in range(H)]
    while q:
        x, y, warp, prev_x, prev_y = q.popleft()

        if warps[x][y] != INF:
            continue

        num_warps = warps[prev_x][prev_y] + warp
        warps[x][y] = num_warps

        for step_x in range(-2, 3):
            for step_y in range(-2, 3):
                x_, y_ = x+step_x, y+step_y
                if is_inside(x_, y_, W, H, G) and warps[x_][y_] == INF:
                    if ((max(abs(step_x), abs(step_y)) == 1) and
                            (min(abs(step_x), abs(step_y)) == 0)):

                        q.appendleft((x_, y_, 0, x, y))
                    else:
                        q.append((x_, y_, 1, x, y))

    ans = warps[Dx-1][Dy-1]
    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import networkx as nx


def is_inside(x, y, W, H, G):
    return (x <= H-1 and y <= W-1 and
            x >= 0 and y >= 0 and
            G[x][y] != "#")


def main():
    graph = nx.Graph()
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    G = [list(input()) for _ in range(H)]

    for h in range(H):
        for w in range(W):
            if not is_inside(h, w, W, H, G):
                continue

            v = h * W + w
            for step_h in range(-2, 3):
                for step_w in range(-2, 3):
                    h_, w_ = h+step_h, w+step_w
                    v_ = h_ * W + w_
                    if is_inside(h_, w_, W, H, G):
                        if ((max(abs(step_h), abs(step_w)) == 1) and
                                (min(abs(step_h), abs(step_w)) == 0)):
                            graph.add_edge(v, v_, weight=0)

                        else:
                            graph.add_edge(v, v_, weight=1)
    start = (Ch - 1) * W + (Cw - 1)
    end = (Dh - 1) * W + (Dw - 1)
    try:
        ans = nx.dijkstra_path_length(graph, start, end)
    except nx.NetworkXNoPath:
        ans = -1

    print(ans)


if __name__ == '__main__':
    main()
Problem p02684 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    prev_p = 1
    g = []
    seen = [0]*N
    i = 0
    while True:
        if seen[prev_p-1]:
            break
        seen[prev_p-1] = i
        g.append(A[prev_p-1])
        prev_p = g[-1]
        i += 1
    g_periodic = g[seen[prev_p-1]:]  
    g_before = g[:seen[prev_p-1]]

    if K <= len(g_before):
        print(g_before[K-1])
    else:
        K_new = (K - len(g_before)) % len(g_periodic)
        print(g_periodic[K_new-1])
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    prev_p = 1
    g = []
    while True:
        if g[:len(g)//2]==g[len(g)//2:] and len(g) > 0:
            break
        g.append(A[prev_p])
        prev_p = g[-1]  

    K = K % len(g)
    print(g[K-1])


if __name__ == '__main__':
    main()
Problem p02714 (python)

Fixed submission:
def main():
    n = int(input())
    S = input()
    r_inds = []
    g_inds = []
    b_inds = []
    for i in range(len(S)):
        if S[i] == "R":
            r_inds.append(i)
        elif S[i] == "G":
            g_inds.append(i)
        else:
            b_inds.append(i)

    total_comb = len(r_inds)*len(g_inds)*len(b_inds)
    ded = 0
    for i in r_inds:
        for j in g_inds:
            s_ind = min(i, j)
            b_ind = max(i, j)
            diff = b_ind - s_ind
            bigger_ind = b_ind + diff
            smaller_ind = s_ind - diff
            if bigger_ind < len(S) and bigger_ind in b_inds:
                ded += 1
            if smaller_ind >= 0 and smaller_ind in b_inds:
                ded += 1
            if diff % 2 == 0:
                mid_diff = diff // 2
                mid_ind = s_ind + mid_diff
                if mid_ind in b_inds:
                    ded += 1
    print(total_comb - ded)

            
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    S = input()
    '''
    r_inds = []
    g_inds = []
    b_inds = []
    for i in range(len(S)):
        if S[i] == "R":
            r_inds.append(i)
        elif S[i] == "G":
            g_inds.append(i)
        else:
            b_inds.append(i)

    total_comb = len(r_inds)*len(g_inds)*len(b_inds)
    ded = 0
    for i in r_inds:
        for j in g_inds:
            s_ind = min(i, j)
            b_ind = max(i, j)
            diff = b_ind - s_ind
            bigger_ind = b_ind + diff
            smaller_ind = s_ind - diff
            if bigger_ind < len(S) and bigger_ind in b_inds:
                ded += 1
            if smaller_ind >= 0 and smaller_ind in b_inds:
                ded += 1
            if diff % 2 == 0:
                mid_diff = diff // 2
                mid_ind = s_ind + mid_diff
                if mid_ind in b_inds:
                    ded += 1
    print(total_comb - ded)
    '''
    color_num = defaultdict(int)
    num_subst = 0

    for i in range(len(S) - 1):
        color_num[S[i]] += 1 
        for j in range(i + 1, len(S)):
            if S[i] != S[j]:
                diff = j - i
                idx = j + diff
                if idx < len(S) and S[idx] != S[i] and S[idx] != S[j]:
                    num_subst += 1
    color_num[S[len(S) - 1]] += 1 
    total_num_comb = color_num["R"] * color_num["G"] * color_num["B"]
    print(total_num_comb - num_subst)

if __name__ == "__main__":
    main()