Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

def main():
    N = int(input())
    S = input()

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

    for i in range(N):
        if S[i] == 'R':
            R.append(i)
        if S[i] == 'G':
            G.append(i)
        if S[i] == 'B':
            B.append(i)

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

    cnt = 0
    for r in R:
        for g in G:
            for b in B:
                if abs(b-g) == abs(g-r) or abs(b-r) == abs(r-g) or abs(g-b) == abs(b-r) or abs(g-r) == abs(r-b) or abs(r-b) == abs(b-g) or abs(r-g) == abs(g-b):
                    cnt += 1



    print(base-cnt)  

if __name__ == "__main__":
    main() 

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k >= N or S[i] == S[j] or S[j] == S[k] or S[k] == S[i]:
            continue
        cnt += 1

print(base-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

def main():
    N = int(input())
    S = input()

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

    for i in range(N):
        if S[i] == 'R':
            R.append(i)
        if S[i] == 'G':
            G.append(i)
        if S[i] == 'B':
            B.append(i)

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

    cnt = 0
    for r in R:
        for g in G:
            for b in B:
                if abs(b-g) == abs(g-r) or abs(b-r) == abs(r-g) or abs(g-b) == abs(b-r) or abs(g-r) == abs(r-b) or abs(r-b) == abs(b-g) or abs(r-g) == abs(g-b):
                    cnt += 1



    print(base-cnt)  

if __name__ == "__main__":
    main() 

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k >= N or S[i] == S[j] or S[j] == S[k] or S[k] == S[i]:
            continue
        cnt += 1

print(base-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

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

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

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)

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

cnt = 0
for r in R:
    for g in G:
        for b in B:
            if abs(b-g) == abs(g-r) or abs(b-r) == abs(r-g) or abs(g-b) == abs(b-r) or abs(g-r) == abs(r-b) or abs(r-b) == abs(b-g) or abs(r-g) == abs(g-b):
                cnt += 1
print(base-cnt)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k >= N or S[i] == S[j] or S[j] == S[k] or S[k] == S[i]:
            continue
        cnt += 1

print(base-cnt)