Buggy python submission (verdict: Time Limit Exceeded):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
S = S()

def check(i, j, k):
    return j-i != k-j

chars = list(S)

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if not check(i, j, k):
                continue
            if chars[i] == chars[j] or chars[j] == chars[k]:
                continue
            if chars[i] != chars[j] and chars[i] != chars[k] and chars[j] != chars[k]:
                cnt += 1

print(cnt)

Fixed submission:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
S = S()


def check(i, j, k):
    return j-i != k-j

chars = list(S)
cnts = Counter(chars)

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k > N-1:
            continue
        if chars[i] != chars[j] and chars[i] != chars[k] and chars[j] != chars[k]:
                cnt += 1

print(cnts["R"] * cnts["G"] * cnts["B"] - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
S = S()

def check(i, j, k):
    return j-i != k-j

chars = list(S)

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if not check(i, j, k):
                continue
            if chars[i] != chars[j] and chars[i] != chars[k] and chars[j] != chars[k]:
                cnt += 1

print(cnt)

Fixed submission:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
S = S()


def check(i, j, k):
    return j-i != k-j

chars = list(S)
cnts = Counter(chars)

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k > N-1:
            continue
        if chars[i] != chars[j] and chars[i] != chars[k] and chars[j] != chars[k]:
                cnt += 1

print(cnts["R"] * cnts["G"] * cnts["B"] - cnt)