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


def main():
    N = int(input())
    S = input()

    ans = 0
    for ix_i, i in enumerate(S):
        for j in range(ix_i+1, N):
            if i == S[j]:
                continue
            else:
                if (i == "R") and (S[j] == "G"):
                    ans += S[j + 1:].count("B")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "B":
                            ans -= 1
                elif (i == "R") and (S[j] == "B"):
                    ans += S[j + 1:].count("G")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "G":
                            ans -= 1
                elif (i == "G") and (S[j] == "B"):
                    ans += S[j + 1:].count("R")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "R":
                            ans -= 1
                elif (i == "G") and (S[j] == "R"):
                    ans += S[j + 1:].count("B")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "B":
                            ans -= 1
                elif (i == "B") and (S[j] == "R"):
                    ans += S[j + 1:].count("G")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "G":
                            ans -= 1
                elif (i == "B") and (S[j] == "G"):
                    ans += S[j + 1:].count("R")
                    if j+(j-ix_i) < N:
                        if S[j + (j - ix_i)] == "R":
                            ans -= 1
    print(ans)
    return 0

if __name__ == '__main__':
    main()

Fixed submission:
import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

if __name__ == '__main__':
    main()

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


def main():
    N = int(input())
    S = input()

    ans = 0
    for ix_i, i in enumerate(S):
        for j in range(ix_i+1, N):
            if i == S[j]:
                continue
            for k in range(j+1, N):
                if (S[j] == S[k]) or (i == S[k]):
                    continue
                if (j-ix_i) == (k-j):
                    continue

                ans += 1

    print(ans)
    return 0

if __name__ == '__main__':
    main()

Fixed submission:
import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

if __name__ == '__main__':
    main()

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


def main():
    N = int(input())
    S = list(input())

    ans = 0
    for v in itertools.permutations(range(N), 3):
        if v[0] < v[1] < v[2]:
            if (v[2] - v[1]) != (v[1] - v[0]):
                if (S[v[0]] != S[v[1]]) and (S[v[1]] != S[v[2]]) and (S[v[0]] != S[v[2]]):
                    ans += 1
    print(ans)
    return 0

if __name__ == '__main__':
    main()

Fixed submission:
import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

if __name__ == '__main__':
    main()

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


def main():
    N = int(input())
    S = input()
    id_l = [i for i in range(N)]

    ans = 0
    for v in itertools.permutations(id_l, 3):
        if v[0] < v[1] < v[2]:
            if (v[2] - v[1]) != (v[1] - v[0]):
                if (S[v[0]] != S[v[1]]) and (S[v[1]] != S[v[2]]) and (S[v[0]] != S[v[2]]):
                    ans += 1
    print(ans)
    return 0

if __name__ == '__main__':
    main()

Fixed submission:
import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    S = input()
    id_l = [i for i in range(N)]

    ans = 0
    for v in itertools.permutations(id_l, 3):
        if v[0] < v[1] < v[2]:
            if (v[2] - v[1]) != (v[1] - v[0]):
                if (S[v[0]] != S[v[1]]) and (S[v[1]] != S[v[2]]) and (S[v[0]] != S[v[2]]):
                    ans += 1
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Fixed submission:
import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

if __name__ == '__main__':
    main()