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

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

rgb = defaultdict(list)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        rgb[2].append(i)

ans = len(rgb[0]) * len(rgb[1]) * len(rgb[2])

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in rgb[2]:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in rgb[2]:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in rgb[2]:
            ans -= 1

print(ans)


Fixed submission:
from collections import defaultdict

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

rgb = defaultdict(list)
blue = defaultdict(int)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        blue[i] = i

ans = len(rgb[0]) * len(rgb[1]) * len(blue)

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in blue:
            ans -= 1

print(ans)

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

if __name__ == "__main__":
    n = int(input())
    s = input()

    rgb = defaultdict(list)

    for i in range(n):
        if s[i] == 'R':
            rgb[0].append(i)
        elif s[i] == 'G':
            rgb[1].append(i)
        else:
            rgb[2].append(i)

    ans = len(rgb[0]) * len(rgb[1]) * len(rgb[2])

    for r in rgb[0]:
        for g in rgb[1]:
            tmp = sorted([r, g])
            if tmp[0] - (tmp[1]-tmp[0]) in rgb[2]:
                ans -= 1
            if tmp[1] + (tmp[1]-tmp[0]) in rgb[2]:
                ans -= 1
            if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in rgb[2]:
                ans -= 1

    print(ans)


Fixed submission:
from collections import defaultdict

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

rgb = defaultdict(list)
blue = defaultdict(int)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        blue[i] = i

ans = len(rgb[0]) * len(rgb[1]) * len(blue)

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in blue:
            ans -= 1

print(ans)

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

if __name__ == "__main__":
    n = int(input())
    s = input()

    rgb = defaultdict(list)

    for i in range(n):
        if s[i] == 'R':
            rgb[0].append(i)
        elif s[i] == 'G':
            rgb[1].append(i)
        else:
            rgb[2].append(i)

    ans = len(rgb[0]) * len(rgb[1]) * len(rgb[2])

    for r in rgb[0]:
        for g in rgb[1]:
            tmp = sorted([r, g])
            if tmp[0] - (tmp[1]-tmp[0]) in rgb[2]:
                ans -= 1
            if tmp[1] + (tmp[1]-tmp[0]) in rgb[2]:
                ans -= 1
            if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in rgb[2]:
                ans -= 1

    print(ans)


Fixed submission:
from collections import defaultdict

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

rgb = defaultdict(list)
blue = defaultdict(int)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        blue[i] = i

ans = len(rgb[0]) * len(rgb[1]) * len(blue)

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in blue:
            ans -= 1

print(ans)

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

if __name__ == "__main__":
    n = int(input())
    s = input()

    rgb = defaultdict(list)

    for i in range(n):
        if s[i] == 'R':
            rgb[0].append(i)
        elif s[i] == 'G':
            rgb[1].append(i)
        else:
            rgb[2].append(i)

    ans = 0
    for r in rgb[0]:
        for g in rgb[1]:
            for b in rgb[2]:
                tmp = sorted([r, g, b])
                if tmp[1] - tmp[0] != tmp[2] - tmp[1]:
                    ans += 1

    print(ans)


Fixed submission:
from collections import defaultdict

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

rgb = defaultdict(list)
blue = defaultdict(int)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        blue[i] = i

ans = len(rgb[0]) * len(rgb[1]) * len(blue)

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in blue:
            ans -= 1

print(ans)

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

if __name__ == "__main__":
    n = int(input())
    s = input()

    rgb = defaultdict(list)

    for i in range(n):
        if s[i] == 'R':
            rgb[0].append(i)
        elif s[i] == 'G':
            rgb[1].append(i)
        else:
            rgb[2].append(i)

    ans = 0
    for r in rgb[0]:
        for g in rgb[1]:
            for b in rgb[2]:
                tmp = sorted([r, g, b])
                if tmp[1] - tmp[0] != tmp[2] - tmp[1]:
                    ans += 1

    print(ans)


Fixed submission:
from collections import defaultdict

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

rgb = defaultdict(list)
blue = defaultdict(int)

for i in range(n):
    if s[i] == 'R':
        rgb[0].append(i)
    elif s[i] == 'G':
        rgb[1].append(i)
    else:
        blue[i] = i

ans = len(rgb[0]) * len(rgb[1]) * len(blue)

for r in rgb[0]:
    for g in rgb[1]:
        tmp = sorted([r, g])
        if tmp[0] - (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if tmp[1] + (tmp[1]-tmp[0]) in blue:
            ans -= 1
        if (tmp[1]+tmp[0]) % 2 == 0 and (tmp[1]+tmp[0])//2 in blue:
            ans -= 1

print(ans)