Buggy python submission (verdict: Runtime Error):
def main():
    from collections import Counter
    n, s = int(input()), input()
    c = Counter(s)
    d = list(c.values())

    ans = d[0] * d[1] * d[2]
    rgb = {"R", "G", "B"}
    for i in range(1, n // 2 + 1):
        for j in range(i):
            x = s[j::i]
            for a, b, c in zip(x, x[1:], x[2:]):
                g = {a, b, c}
                if g == rgb:
                    ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product
    n, s = int(input()), input()
    ans = 0
    rgb = {"R", "G", "B"}
    for c in range(1, n - 1):
        for l in range(0, c):
            for r in range(c + 1, n):
                f = (l - c) != (c - r)
                g = rgb == {s[c], s[r], s[l]}
                if f and g:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

    n, s = int(input()), tuple(input())
    m = {'R', 'G', 'B'} 
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            t = m - {s[i], s[j]}
            t = t.pop()
            d = j - i
            ans += s[j + 1:].count(t)
            if j + d < n and s[j + d] == t:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

    n, s = int(input()), input()
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            if s[i] == s[j]:
                continue
            t = {'R', 'G', 'B'} - {s[i], s[j]}
            t = t.pop()
            d = j - i
            ans += s[j + 1:].count(t)
            if j + d < n and s[j + d] == t:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

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


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

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


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

    n, s = int(input()), input()
    r, g, b = [], [], []
    for i, j in enumerate(s):
        if j == 'R':
            r.append(i)
        if j == 'G':
            g.append(i)
        if j == 'B':
            b.append(i)
    ans = 0
    for t in product(r, g, b):
        l = list(t)
        l.sort()
        if l[2] - l[1] != l[1] - l[0]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from itertools import product

    n, s = int(input()), input()
    r, g, b = [], [], []
    for i, j in enumerate(s):
        if j == 'R':
            r.append(i)
        if j == 'G':
            g.append(i)
        if j == 'B':
            b.append(i)
    ans = 0
    for t in product(r, g, b):
        l = list(t)
        l.sort()
        if l[2] - l[1] != l[1] - l[0]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()