Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets
import itertools 

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0
for r, g, b in itertools.product(R, G, B):
    mi = min(r, g, b)
    ma = max(r, g, b)
    if (r+g+b)==mi+ma+(mi+ma)/2:
        continue
    else:
        ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets
import itertools 

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0
for r, g, b in itertools.product(R, G, B):
    mi = min(r, g, b)
    ma = max(r, g, b)
    if (r+g+b)==mi+ma+(mi+ma)/2:
        continue
    else:
        ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0

for r in R:
    for g in G:
        for b in B:
            mi = min(r, g, b)
            ma = max(r, g, b)
            if (r+g+b)==mi+ma+(mi+ma)/2:
                continue
            else:
                ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0

for r in R:
    for g in G:
        for b in B:
            mi = min(r, g, b)
            ma = max(r, g, b)
            if (r+g+b)==mi+ma+(mi+ma)/2:
                continue
            else:
                ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets
import heapq

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0

for r in R:
    for g in G:
        for b in B:
            mi = min(r, g, b)
            ma = max(r, g, b)
            if (r+g+b)==mi+ma+(mi+ma)/2:
                continue
            else:
                ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets

n = int(input())
s = str(input())

R = [i for i, x in enumerate(s) if x=='R']
G = [i for i, x in enumerate(s) if x=='G']
B = [i for i, x in enumerate(s) if x=='B']

ans = 0
for r in R:
    for g in G:
        for b in B:
            tmp = [r, g, b]
            tmp.sort()
            if (tmp[1]-tmp[0])==(tmp[2]-tmp[1]):
                continue
            else:
                ans += 1

print(ans)

Fixed submission:
# D - RGB Triplets

n = int(input())
s = str(input())

r = len([i for i, x in enumerate(s) if x=='R'])
g = len([i for i, x in enumerate(s) if x=='G'])
b = len([i for i, x in enumerate(s) if x=='B'])

ans = r * g * b

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

print(ans)