Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

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

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

dist=[-1 for i in range(n)]
dist[0]=0

dq=deque()
dq.append(0)

while dq:
  x=dq.popleft()

  if x==n-1:
    if dist[x]==2:
      print('POSSIBLE')
    else:
      print('IMPOSSIBLE')

  for i in tree[x]:
    if dist[i]==-1:
      dist[i]=dist[x]+1
      dq.append(i)

Fixed submission:
s=input()
sl=len(s)

if sl==1:
  print(int(s))
  exit()

ans=0
for i in range(2**(sl-1)):
  l=['' for j in range(sl-1)]
  for k in range(sl-1):
    if (i>>k)&1:
      l[k]='+'

  t_ans=0
  t_s=s[0]

  for k in range(1,sl):
    if l[k-1]=='+':
      t_ans+=int(t_s)
      t_s=s[k]
    else:
      t_s+=s[k]

    if k==sl-1:
      t_ans+=int(t_s)

  ans+=t_ans

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

S_list = list(S)

answer = []
for S_num in range(S_list):
    if S_num == '0':
        answer.append('0')
    elif S_num == '1':
        answer.append('1')
    elif not answer:
        continue
    else:
        del answer[-1]

print(answer)

Fixed submission:
S = input()

S_list = list(S)

answer = []
for S_num in S_list:
    if S_num == '0':
        answer.append('0')
    elif S_num == '1':
        answer.append('1')
    elif not answer:
        continue
    else:
        del answer[-1]

answer_honmono = ''
answer_honmono = ''.join(answer)
print(answer_honmono)

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

S_list = list(S)
answer = []
for S_num in range(S_list):
    if S_num == '0':
        answer.append('0')
    elif S_num == '1':
        answer.append('1')
    else:
        del answer[-1]

print(answer)

Fixed submission:
S = input()

S_list = list(S)

answer = []
for S_num in S_list:
    if S_num == '0':
        answer.append('0')
    elif S_num == '1':
        answer.append('1')
    elif not answer:
        continue
    else:
        del answer[-1]

answer_honmono = ''
answer_honmono = ''.join(answer)
print(answer_honmono)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())

if A+B+C == 17 and A*B*C == 175:
    print('YES')
else:
    print('NO')

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

if A+B+C == 17 and A*B*C == 175:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import numpy as np


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c])


if __name__ == '__main__':
    main()

Fixed submission:
def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i,j):
	for t in r(30):b(p:=j+t-1);a(q:=j+t,n,q);[*map(b,r(q,j+29))];a(j+29,x,i+t,1);b(p);a(q,i+t,q)
p(3933)
a(0,1,n:=97)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
for t in r(59):a(2,2,2);[t-30<s<30<(a(5+t-s,36+s,98),a(n,98,99,1),a(2,99,2))for s in r(t+1)]

Fixed submission:
n=97
def c(i,j,k):print('<',i,j,k)
def a(i,j,k):print('+',i,j,k)
def m(i,j,k):
	for t in range(59):
		a(k,k,k)
		for s in range(t+1):
			if t-30<s<30:a(i+t-s,j+s,98);c(n,98,99);a(k,99,k)
def d(x,i,j):
	for t in range(30):
		a(j+t-1,j+t-1,j+t)
		a(j+t,n,j+t)
		for s in range(j+t,j+29):a(s,s,s+1)
		c(j+29,x,i+t)
		a(j+t-1,j+t-1,j+t)
		a(j+t,i+t,j+t)
print(3933)
a(0,1,n)
c(2,n,n)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
m(5,36,2)

Buggy python submission (verdict: Runtime Error):
n=97
def c(i,j,k):print('<',i,j,k)
def a(i,j,k):print('+',i,j,k)
def d(x,i,j):
	for t in range(30):
		a(j+t-1,j+t-1,j+t)
		a(j+t,n,j+t)
		for s in range(j+t,j+29):a(s,s,s+1)
		c(j+29,x,i+t)
		a(j+t-1,j+t-1,j+t)
		a(j+t,i+t,j+t)
print(3932)
a(0,1,n)
c(2,n,n)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
m(5,36,2)
for t in range(59):
	a(2,2,2)
	for s in range(t+1):
		if t-30<s<30:a(5+t-s,36+s,98);c(n,98,99);a(2,99,2)

Fixed submission:
n=97
def c(i,j,k):print('<',i,j,k)
def a(i,j,k):print('+',i,j,k)
def m(i,j,k):
	for t in range(59):
		a(k,k,k)
		for s in range(t+1):
			if t-30<s<30:a(i+t-s,j+s,98);c(n,98,99);a(k,99,k)
def d(x,i,j):
	for t in range(30):
		a(j+t-1,j+t-1,j+t)
		a(j+t,n,j+t)
		for s in range(j+t,j+29):a(s,s,s+1)
		c(j+29,x,i+t)
		a(j+t-1,j+t-1,j+t)
		a(j+t,i+t,j+t)
print(3933)
a(0,1,n)
c(2,n,n)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
m(5,36,2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
l = 0
r = n - 1
ans = 0
while l < r:
    while l < r && s[l] == 'R':
        l += 1
    while l < r && s[r] == 'W':
        r -= 1
    ans += 1
    l += 1
    r -= 1

print(ans)

Fixed submission:
n = int(input())
s = input()
l = 0
r = n - 1
ans = 0

while l < r:
    while l < r and s[l] == 'R':
        l += 1
    while l < r and s[r] == 'W':
        r -= 1
    if l >= r:
        break
    ans += 1
    l += 1
    r -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

@njit
def main():
    N = int(input())
    Answer = 0

    for i in range(1,N+1):
        cnt = N // i
        num = cnt * (cnt + 1) >> 1
        num *= i
        Answer += num

print(Answer)
main()

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
Answer = 0

for i in range(1,N+1):
    cnt = N // i
    num = cnt * (cnt + 1) >> 1
    num *= i
    Answer += num

print(Answer)
Buggy python submission (verdict: Runtime Error):
# 制約が小さいので全探索
def main():
  a, b = int(input().split())
  for i in range(1100):
    if int(i * 0.08) == a and int(i * 0.1) == b:
      print(i)
      return
  print(-1)

main()

Fixed submission:
# 制約が小さいので全探索
def main():
  a, b = map(int, input().split())
  for i in range(1100):
    if int(i * 0.08) == a and int(i * 0.1) == b:
      print(i)
      return
  print(-1)

main()
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
a = int(input())
b = int(input())
print(a * b // gcd(a, b))

Fixed submission:
from fractions import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
a = int(input())
b = int(input())
print(a * b / gcd(a, b))

Fixed submission:
from fractions import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 0
s = []
for i in range(len(a)):
    m += a[i]
    s.append(abs(sum(a) - m * 2))
print(min(s))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 0
s = []
suma = sum(a)
for i in range(len(a)):
    m += a[i]
    s.append(abs(suma - m * 2))
print(min(s))
Buggy python submission (verdict: Time Limit Exceeded):
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Fixed submission:
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        while l[i] >l[i+1]:
            l[i+1]+=1
            count+=1

print(count)

Fixed submission:
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    while l[i] >l[i+1]:
        l[i+1]+=1
        count+=1
print(count)

Fixed submission:
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    while l[i] >l[i+1]:
        l[i+1]+=1
        count+=1
print(count)

Fixed submission:
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = map(int, input().split())
l = list(map(int, input().split()))
count=0
for i in range(len(l)-1):
    while l[i] >l[i+1]:
        l[i+1]+=1
        count+=1
print(count)

Fixed submission:
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
mylist = input().split()
mylist.sort()
c = 0
for i in range(b-1):
    c = c + int(mylist[i-1])
print(c)

Fixed submission:
a = str(input())
b = a.upper()
c = a.lower()
if b == a :
    print("A")
if c == a :
    print("a")
Buggy python submission (verdict: Runtime Error):
X, Y = map(int,input().split)
ans = "No"
for a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = "Yes"
print(ans)

Fixed submission:
X, Y = list(map(int, input().split()))
ans = "No"
for a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = "Yes"
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
s = 10
N = n % s
if N == 0 :
    print("pon")
if N == 1 :
    print("pon")
if N == 2 :
    print("hon")
if N == 3 :
    print("bon")
if N == 4 :
    print("hon")
if N == 5 :
    print("hon")
if N == 6 :
    print("pon")
if N == 7 :
    print("hon")
if N == 8 :
    print("pon")
if N == 9 :
    print("hon")

Fixed submission:
a = int(input())
b = a % 10
if b == 0 :
    print("pon")
if b == 1 :
    print("pon")
if b == 2 :
    print("hon")
if b == 3 :
    print("bon")
if b == 4 :
    print("hon")
if b == 5 :
    print("hon")
if b == 6 :
    print("pon")
if b == 7 :
    print("hon")
if b == 8 :
    print("pon")
if b == 9 :
    print("hon")
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
A = ""
if K < len(S):
	for i in range(K):
    	A = A + S[i]
    A = A + "..."
else:
	A = S
print(A)

Fixed submission:
K = int(input())
S = input()
if K < len(S):
    A = ""
    for i in range(K):
        A = str(A) + S[i]
    A = str(A) + "..."
    S = A
print(S)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b, c = int(list(map(int, input().split())))
d = b//a
e = c//a
if d == e:
    print("Yes")
else:
    print("No")

Fixed submission:
K = int(input())
A, B = list(map(int,input().split()))
S = 0
for i in range(A,B+1):
	if i % K == 0:
		S = 1
		break
if S == 1:
	print("OK")
else:
	print("NG")
Buggy python submission (verdict: Runtime Error):
S, W = list(map(int, input().split()))
if S < W :
    print(unsafe)
if S > W :
    print(safe)

Fixed submission:
S, W = list(map(int, input().split()))
if S <= W :
    print("unsafe")
if S > W :
    print("safe")
Buggy python submission (verdict: Runtime Error):
coffee = str(input())
iff3 = coffee[3]
iff4 = coffee[4]
iff5 = coffee[5]
iff6 = coffee[6]
if iff3 == iff4 :
    if iff5 == iff6 :
        print("Yes")
    if iff5 != iff6 :
        print("No")
if iff3 != iff4:
    print("No")

Fixed submission:
a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
    if iff5 == iff6 :
        print("Yes")
    else :
        print("No")
else :
    print("No")
Buggy python submission (verdict: Runtime Error):
b, c = list(map(int, input().split()))
if 500 * b => c :
    print("Yes")
else:
    print("No")

Fixed submission:
b, c = list(map(int, input().split()))
if 500 * b >= c :
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
A, W = list(map(str, input().split()))
output = W + A
print(output)

Fixed submission:
A, W = list(map(str, input().split()))
output = W + A
print(output)
Buggy python submission (verdict: Runtime Error):
import math
a = int(input())
b = a / 2
d = 0
c = 1
b = math.ceil(b)
for i in range(b):
    c = c * a
    a = a - 2
c = str(c)
for e in range(len(c)):
    if len(c) - c[e] == "0":
        d = d + 1
    else:
        break
print(d)

Fixed submission:
a = int(input())
b = int(input())
if a == 1 :
    if b == 2 :
        print("3")
    if b == 3 :
        print("2")
if a == 2 :
    if b == 1 :
        print("3")
    if b == 3 :
        print("1")
if a == 3 :
    if b == 2 :
        print("1")
    if b == 1 :
        print("2")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(str,input().split())
print(upper(a[0] + b[0] + c[0]))

Fixed submission:
a, b, c = map(str,input().split())
print((a[0] + b[0] + c[0]).upper())
Buggy python submission (verdict: Time Limit Exceeded):
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()

# print(n)
# print(a)
l = []
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

for i in range(n-1):
    for j in range(i+1,n):
        b = (a[i] * a[j]) % (10**9+7)
        l.append(b)
# print(l)

ans = sum(l) % (10**9+7)

print(ans)


Fixed submission:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()

# print(n)
# print(a)
b = 0
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

for i in range(n-1):
    b += a[i]
    ans += a[i+1] * b

ans %= (10**9+7)

print(ans)
Buggy python submission (verdict: Runtime Error):
def readInt():
    return list(map(int, input().split()))

n, m = readInt()

root = [-1] * n

def r(x):
    # print("root[x]=",root[x])
    if root[x] < 0:
        # print("r(x)=",x)
        return x
    else:
        root[x] = r(root[x])
        # print(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
    # print(root)

def size(x):
    x = r(x)
    # print(x, root[x])
    return -root[x]

for i in range(m):
    x, y = readInt()
    x -= 1
    y -= 1
    unite(x, y)

max_size = 0

for i in range(n):
    max_size = max(max_size, size(i))

print(max_size)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def readInt():
    return list(map(int, input().split()))

n, m = readInt()

root = [-1] * n

def r(x):
    # print("root[x]=",root[x])
    if root[x] < 0:
        # print("r(x)=",x)
        return x
    else:
        root[x] = r(root[x])
        # print(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
    # print(root)

def size(x):
    x = r(x)
    # print(x, root[x])
    return -root[x]

for i in range(m):
    x, y = readInt()
    x -= 1
    y -= 1
    unite(x, y)

max_size = 0

for i in range(n):
    max_size = max(max_size, size(i))

print(max_size)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dig_sum = 0
while n != 0:
    dig_sum += n % 10 
    n = n // 10
# print(dig_sum)
if dig_sum % 9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

n = int(input())
d_s = digitSum(n)
# print(d_s)
if d_s % 9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    # print(i, ".")
    c_l = list(itertools.combinations(np.mod(l,10**9+7),i))
    a = []
    for j in range(len(c_l)):
        # print(sum(c_l[j]))
        a.append(sum(c_l[j]))
        # print(a)
    # print(a)
    # print(set(a))
    # print(c_l)
    ans += np.mod(len(set(a)),10**9+7)
print(ans)

Fixed submission:
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
# l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    smallest = (i-1)*i /2
    largest = n*(n+1)/2 - (n-i)*(n-i+1)/2
    ans += int(largest - smallest + 1)
    ans %= 10**9 + 7
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    # print(i, ".")
    c_l = list(itertools.combinations(l,i))
    a = []
    for j in range(len(c_l)):
        # print(sum(c_l[j]))
        a.append(sum(c_l[j]))
        # print(a)
    # print(a)
    # print(set(a))
    # print(c_l)
    ans += len(set(a))
print(ans)

Fixed submission:
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
# l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    smallest = (i-1)*i /2
    largest = n*(n+1)/2 - (n-i)*(n-i+1)/2
    ans += int(largest - smallest + 1)
    ans %= 10**9 + 7
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, math.gcd(j,k))

print(ans)

Fixed submission:
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, math.gcd(j,k))

print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += fractions.gcd(i, gcd(j,k))

print(ans)

Fixed submission:
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, math.gcd(j,k))

print(ans)

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, gcd(j,k))

print(ans)

Fixed submission:
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, math.gcd(j,k))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i] and j-i != k-j:
          	    ans += 1
            	
print(ans)


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

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

# print(r_cnt, g_cnt, b_cnt)
ans = r_cnt * g_cnt * b_cnt
# print(ans)

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        # print(i,j,k)
        if k >= n: 
            # print('/')
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i] and j-i != k-j:
                ans += 1

print(ans)


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

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

# print(r_cnt, g_cnt, b_cnt)
ans = r_cnt * g_cnt * b_cnt
# print(ans)

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        # print(i,j,k)
        if k >= n: 
            # print('/')
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i] and j-i != k-j:
                ans += 1

print(ans)

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

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

# print(r_cnt, g_cnt, b_cnt)
ans = r_cnt * g_cnt * b_cnt
# print(ans)

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        # print(i,j,k)
        if k >= n: 
            # print('/')
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)