Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
S = input()
R, G, B = S.count("R"), S.count("G"), S.count("B")
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Fixed submission:
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Fixed submission:
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = [], [], []
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R.append(i)
    elif p == "G":
        G.append(i)
    else:
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            if g - r != b - g and r < g < b:
                # L.append((r,g,b))
                ans += 1
    for b in B:
        for g in G:
            if b - r != g - b and r < b < g:
                # L.append((r,g,b))
                ans += 1
                
for g in G:
    for b in B:
        for r in R:
            if b - g != r - b and g < b < r:
                # L.append((r,g,b))
                ans += 1
    for r in R:
        for b in B:
            if r - g != b - r and g < r < b:
                # L.append((r,g,b))
                ans += 1

for b in B:
    for g in G:
        for r in R:
            if g - b != r - g and b < g < r:
                # L.append((r,g,b))
                ans += 1
    for r in R:
        for g in G:
            if r - b != g - r and b < r < g:
                # L.append((r,g,b))
                ans += 1
print(ans)

Fixed submission:
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = [], [], []
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R.append(i)
    elif p == "G":
        G.append(i)
    else:
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            if g - r != b - g and r < g < b:
                # L.append((r,g,b))
                ans += 1
    for b in B:
        for g in G:
            if b - r != g - b and r < b < g:
                # L.append((r,g,b))
                ans += 1
                
for g in G:
    for b in B:
        for r in R:
            if b - g != r - b and g < b < r:
                # L.append((r,g,b))
                ans += 1
    for r in R:
        for b in B:
            if r - g != b - r and g < r < b:
                # L.append((r,g,b))
                ans += 1

for b in B:
    for g in G:
        for r in R:
            if g - b != r - g and b < g < r:
                # L.append((r,g,b))
                ans += 1
    for r in R:
        for g in G:
            if r - b != g - r and b < r < g:
                # L.append((r,g,b))
                ans += 1
print(ans)

Fixed submission:
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from math import gcd
N = int(input())
S = input()

ans = 0
R, G, B = [], [], []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            if g - r != b - g and r < g < b:
                # L.append((r,g,b))
                ans += 1

for r in R:
    for b in B:
        for g in G:
            if b - r != g - b and r < b < g:
                # L.append((r,g,b))
                ans += 1
                
for g in G:
    for b in B:
        for r in R:
            if b - g != r - b and g < b < r:
                # L.append((r,g,b))
                ans += 1

for g in G:
    for r in R:
        for b in B:
            if r - g != b - r and g < r < b:
                # L.append((r,g,b))
                ans += 1

for b in B:
    for g in G:
        for r in R:
            if g - b != r - g and b < g < r:
                # L.append((r,g,b))
                ans += 1

for b in B:
    for r in R:
        for g in G:
            if r - b != g - r and b < r < g:
                # L.append((r,g,b))
                ans += 1
print(ans)

Fixed submission:
# coding: utf-8
from collections import deque
N = int(input())
S = input()
Sd = deque(S)
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
    p = Sd.popleft()
    if p == "R":
        R += 1
    elif p == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)