Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



count = rcount * gcount * bcount

for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == "R" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1
            
        if S[i] == "R" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "G" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1

        if S[i] == "G" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

        if S[i] == "B" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "B" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

print(count)


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

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



count = rcount * gcount * bcount
k = 0
for i in range(N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k < N :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

rcount = 0
gcount = 0
bcount = 0

for i in range(N):
    if S[i] == "R":
        rcount += 1
    elif S[i] == "G":
        gcount += 1
    elif S[i] == "B":
        bcount += 1

count = rcount * gcount * bcount

for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == "R" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1
            
        if S[i] == "R" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "G" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1

        if S[i] == "G" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

        if S[i] == "B" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "B" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

print(count)

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

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



count = rcount * gcount * bcount
k = 0
for i in range(N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k < N :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N = int(input())
S = input()

dic = defaultdict(list)
for i in range(N):
    dic[S[i]].append(int(i))

'''count = 0
print(dic["R"])
print(dic["G"])
print(dic["B"])

for i in dic["R"]:
    for j in dic["G"]:
        for k in dic["B"]:
            if i < j and j < k and (j-i != k-j):
                count += 1

print(count)
'''
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == "R" and S[j] == "G":
            for k in dic["B"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "R" and S[j] == "B":
            for k in dic["G"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "G" and S[j] == "B":
            for k in dic["R"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "G" and S[j] == "R":
            for k in dic["B"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "B" and S[j] == "R":
            for k in dic["G"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "B" and S[j] == "G":
            for k in dic["R"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

print(count) 

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

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



count = rcount * gcount * bcount
k = 0
for i in range(N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k < N :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                count -= 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N = int(input())
S = input()

dic = defaultdict(list)
for i in range(N):
    dic[S[i]].append(int(i))

count = 0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == "R" and S[j] == "G":
            for k in dic["B"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "R" and S[j] == "B":
            for k in dic["G"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "G" and S[j] == "B":
            for k in dic["R"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "G" and S[j] == "R":
            for k in dic["B"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "B" and S[j] == "R":
            for k in dic["G"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

        elif S[i] == "B" and S[j] == "G":
            for k in dic["R"]:
                if i < j and j < k and (j-i != k-j):
                   count += 1

print(count)   

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

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



count = rcount * gcount * bcount
k = 0
for i in range(N-1):
    for j in range(i+1,N):
        k = 2*j-i
        if k < N :
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                count -= 1
print(count)