Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()
dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        dum.append([S[i], S[i+d+1], S[i+2*(d+1)]])
    d += 1
dum_n = len([x for x in dum if len(set(x)) == 3])

RGB_Counter = Counter(S)
print(RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B'] -dum_n)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i+1)
    elif s == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = len(R)*len(G)*len(B)
# (RG)B
for a in R:
    for b in G:
        if b > a:
            if b + (b-a) in B:
                ans -= 1
        else:
            if a + (a-b) in B:
                ans -= 1
# (RB)G
for a in R:
    for b in B:
        if b > a:
            if b + (b-a) in G:
                ans -= 1
        else:
            if a + (a-b) in G:
                ans -= 1
# (BG)R
for a in B:
    for b in G:
        if b > a:
            if b + (b-a) in R:
                ans -= 1
        else:
            if a + (a-b) in R:
                ans -= 1
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i+1)
    elif s == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = len(R)*len(G)*len(B)
# RGB
for a in R:
    for b in [b for b in G if b > a]:
        if b + (b-a) in B:
            ans -= 1
# RBG
for a in R:
    for b in [b for b in B if b > a]:
        if b + (b-a) in G:
            ans -= 1
# BRG
for a in B:
    for b in [b for b in R if b > a]:
        if b + (b-a) in G:
            ans -= 1
# BGR
for a in B:
    for b in [b for b in G if b > a]:
        if b + (b-a) in R:
            ans -= 1
# GRB
for a in G:
    for b in [b for b in R if b > a]:
        if b + (b-a) in B:
            ans -= 1
# GBR
for a in G:
    for b in [b for b in B if b > a]:
        if b + (b-a) in R:
            ans -= 1
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i+1)
    elif s == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
res = [sorted([r, g, b]) for r in R for g in G for b in B]
print(len([x for x in res if x[1] - x[0] != x[2] - x[1]]))

Fixed submission:
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i+1)
    elif s == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
res = []
# RGB
for a in R:
    for b in [b for b in G if b > a]:
        for c in [c for c in B if c > b]:
            res.append([a, b, c])
# RBG
for a in R:
    for b in [b for b in B if b > a]:
        for c in [c for c in G if c > b]:
            res.append([a, b, c])
# BRG
for a in B:
    for b in [b for b in R if b > a]:
        for c in [c for c in G if c > b]:
            res.append([a, b, c])
# BGR
for a in B:
    for b in [b for b in G if b > a]:
        for c in [c for c in R if c > b]:
            res.append([a, b, c])
# GRB
for a in G:
    for b in [b for b in R if b > a]:
        for c in [c for c in B if c > b]:
            res.append([a, b, c])
# GBR
for a in G:
    for b in [b for b in B if b > a]:
        for c in [c for c in R if c > b]:
            res.append([a, b, c])
print(len([x for x in res if x[1] - x[0] != x[2] - x[1]]))

Fixed submission:
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)