Buggy python submission (verdict: Time Limit Exceeded):
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)


Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)


Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
from numba import jit
if __name__ == '__main__':


    @jit
    def solve():
        input = sys.stdin.readline
        n = int(input())
        s = list(input())
        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 = 0
        for i in range(n):
            for j in range(i, n):
                if s[i] == s[j]:
                    continue
                if s[i] == "R" and s[j] == "G":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(b, j)
                    t = len(b) - tmp
                    ans += (t - 1) if out in b[tmp:] else t

                elif s[i] == "R" and s[j] == "B":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(g, j)
                    t = len(g) - tmp
                    ans += (t - 1) if out in g[tmp:] else t

                elif s[i] == "G" and s[j] == "B":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(r, j)
                    t = len(r) - tmp
                    ans += (t - 1) if out in r[tmp:] else t

                elif s[i] == "G" and s[j] == "R":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(b, j)
                    t = len(b) - tmp
                    ans += (t - 1) if out in b[tmp:] else t

                elif s[i] == "B" and s[j] == "R":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(g, j)
                    t = len(g) - tmp
                    ans += (t - 1) if out in g[tmp:] else t

                elif s[i] == "B" and s[j] == "G":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(r, j)
                    t = len(r) - tmp
                    ans += (t - 1) if out in r[tmp:] else t

        print(ans)
    solve()

Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    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)
    x = len(b)
    ans = 0
    for i in range(n):
        for j in range(i, n):
            if s[i] == s[j]:
                continue
            if s[i] == "R" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "R" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "G" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

            elif s[i] == "G" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "B" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "B" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

    print(ans)


Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

if __name__ == '__main__':
    n = int(input())
    s = list(input())
    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)
    x = len(b)
    ans = 0
    for i in range(n):
        for j in range(i, n):
            if s[i] == s[j]:
                continue
            if s[i] == "R" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "R" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "G" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

            elif s[i] == "G" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "B" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "B" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

    print(ans)


Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

if __name__ == '__main__':
    n = int(input())
    s = list(input())
    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)
    x = len(b)
    ans = 0
    for i in range(n):
        for j in range(i, n):
            if s[i] == s[j]:
                continue
            if s[i] == "R" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "R" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "G" and s[j] == "B":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

            elif s[i] == "G" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(b, j)
                t = len(b) - tmp
                ans += (t - 1) if out in b[tmp:] else t

            elif s[i] == "B" and s[j] == "R":
                out = j * 2 - i
                tmp = bisect.bisect_left(g, j)
                t = len(g) - tmp
                ans += (t - 1) if out in g[tmp:] else t

            elif s[i] == "B" and s[j] == "G":
                out = j * 2 - i
                tmp = bisect.bisect_left(r, j)
                t = len(r) - tmp
                ans += (t - 1) if out in r[tmp:] else t

    print(ans)


Fixed submission:
import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)