Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(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)

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


for i in R:
    for j in G:
        k = j + (j - i)
        if k in B:
            ans -= 1
        k = i + (i - j)
        if k in B:
            ans -= 1
        k = (i+j)/2
        if k in B:
            ans -= 1

print(ans)

Fixed submission:
n = int(input())
s = list(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)

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


for i in range(0,n-2):
    for j in range(i+1,n-1):
        k = j + ( j -i )
        if k < n:
            if s[i] != s[j] and s[k] != s[j] and s[i] != s[k]:
                ans -= 1


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(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)

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


for i in R:
    for j in G:
        k = j + (j - i)
        if k in B:
            ans -= 1
        k = i + (i - j)
        if k in B:
            ans -= 1
        k = (i+j)/2
        if k in B:
            ans -= 1

print(ans)

Fixed submission:
n = int(input())
s = list(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)

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


for i in range(0,n-2):
    for j in range(i+1,n-1):
        k = j + ( j -i )
        if k < n:
            if s[i] != s[j] and s[k] != s[j] and s[i] != s[k]:
                ans -= 1


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(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 i in R:
    for j in G:
        for k in B:
            a = [i,j,k]
            a.sort()
            if a[2] - a[1] == a[1] - a[0]:
                continue
            ans += 1

print(ans)

Fixed submission:
n = int(input())
s = list(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)

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


for i in range(0,n-2):
    for j in range(i+1,n-1):
        k = j + ( j -i )
        if k < n:
            if s[i] != s[j] and s[k] != s[j] and s[i] != s[k]:
                ans -= 1


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0

for i in range(0,n-2):
    for j in range(i,n-1):
        if s[i] ==s[j]:
            continue
        for k in range(j,n):
            if s[i] == s[k] or s[j] == s[k]:
                continue
            if j-i == k-j:
                continue
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s = list(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)

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


for i in range(0,n-2):
    for j in range(i+1,n-1):
        k = j + ( j -i )
        if k < n:
            if s[i] != s[j] and s[k] != s[j] and s[i] != s[k]:
                ans -= 1


print(ans)