Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
S = input()
L_r = []
L_g = []
L_b = []
ans = 0
for i in range(N):
    if S[i] == "R":
        L_r.append(i)
    elif S[i] == "G":
        L_g.append(i)
    else:
        L_b.append(i)
m = min(len(L_r),len(L_g),len(L_b))
if len(L_r) == m:
    for x in L_g:
        for y in L_b:
            ans += m
            if 2*x - y in L_r:
                ans -= 1
            if 2*y - x in L_r:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_r:
                ans -= 1
elif len(L_g) == m:
    for x in L_r:
        for y in L_b:
            ans += m
            if 2*x - y in L_g:
                ans -= 1
            if 2*y - x in L_g:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_g:
                ans -= 1
else:
    for x in L_r:
        for y in L_g:
            ans += m
            if 2*x - y in L_b:
                ans -= 1
            if 2*y - x in L_b:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_b:
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = 0
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans += r*g*b
m = 0
if N >= 3:
  for i in range(N-2):
    for j in range(i+1,N-1):
      k = 2*j-i
      if  k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        m += 1
print(ans-m)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
L_r = []
L_g = []
L_b = []
ans = 0
for i in range(N):
    if S[i] == "R":
        L_r.append(i)
    elif S[i] == "G":
        L_g.append(i)
    else:
        L_b.append(i)
m = max(len(L_r),len(L_g),len(L_b))
if len(L_r) == m:
    for x in L_g:
        for y in L_b:
            ans += m
            if 2*x - y in L_r:
                ans -= 1
            if 2*y - x in L_r:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_r:
                ans -= 1
elif len(L_g) == m:
    for x in L_r:
        for y in L_b:
            ans += m
            if 2*x - y in L_g:
                ans -= 1
            if 2*y - x in L_g:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_g:
                ans -= 1
else:
    for x in L_r:
        for y in L_g:
            ans += m
            if 2*x - y in L_b:
                ans -= 1
            if 2*y - x in L_b:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_b:
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = 0
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans += r*g*b
m = 0
if N >= 3:
  for i in range(N-2):
    for j in range(i+1,N-1):
      k = 2*j-i
      if  k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        m += 1
print(ans-m)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
L_r = []
L_g = []
L_b = []
ans = 0
for i in range(N):
    if S[i] == "R":
        L_r.append(i)
    elif S[i] == "G":
        L_g.append(i)
    else:
        L_b.append(i)
m = min(len(L_r),len(L_g),len(L_b))
if len(L_r) == m:
    for x in L_g:
        for y in L_b:
            ans += m
            if 2*x - y in L_r:
                ans -= 1
            if 2*y - x in L_r:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_r:
                ans -= 1
elif len(L_g) == m:
    for x in L_r:
        for y in L_b:
            ans += m
            if 2*x - y in L_g:
                ans -= 1
            if 2*y - x in L_g:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_g:
                ans -= 1
else:
    for x in L_r:
        for y in L_g:
            ans += m
            if 2*x - y in L_b:
                ans -= 1
            if 2*y - x in L_b:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_b:
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = 0
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans += r*g*b
m = 0
if N >= 3:
  for i in range(N-2):
    for j in range(i+1,N-1):
      k = 2*j-i
      if  k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        m += 1
print(ans-m)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
L_r = []
L_g = []
L_b = []
ans = 0
for i in range(N):
    if S[i] == "R":
        L_r.append(i)
    elif S[i] == "G":
        L_g.append(i)
    else:
        L_b.append(i)
m = min(len(L_r),len(L_g),len(L_b))
if len(L_r) == m:
    for x in L_g:
        for y in L_b:
            ans += m
            if 2*x - y in L_r:
                ans -= 1
            if 2*y - x in L_r:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_r:
                ans -= 1
elif len(L_g) == m:
    for x in L_r:
        for y in L_b:
            ans += m
            if 2*x - y in L_g:
                ans -= 1
            if 2*y - x in L_g:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_g:
                ans -= 1
else:
    for x in L_r:
        for y in L_g:
            ans += m
            if 2*x - y in L_b:
                ans -= 1
            if 2*y - x in L_b:
                ans -= 1
            if (x + y) % 2 == 0 and (x + y) // 2 in L_b:
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = 0
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans += r*g*b
m = 0
if N >= 3:
  for i in range(N-2):
    for j in range(i+1,N-1):
      k = 2*j-i
      if  k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        m += 1
print(ans-m)