Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = list(input())

    ans = 0

    for i in range(N):
        for ii in range(i + 1, N):
            for iii in range(ii + 1, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (S[i] != S[ii] and S[ii] != S[iii] and S[i] != S[iii]):
                    ans += 1

    print(ans)


resolve()

Fixed submission:
from collections import Counter


def resolve():
    n = int(input())
    s = input()
    cnt = Counter(s)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(n - 1):
        for j in range(i + 1, n):
            ken = j * 2 - i
            if (ken >= n):
                continue
            if (s[i] != s[j] and s[j] != s[ken] and s[i] != s[ken]):
                ans -= 1

    print(ans)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = list(input())

    ans = 0

    for i in range(N):
        for ii in range(i, N):
            for iii in range(ii, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (S[i] != S[ii] and S[ii] != S[iii] and S[i] != S[iii]):
                    ans += 1

    print(ans)


resolve()

Fixed submission:
from collections import Counter


def resolve():
    n = int(input())
    s = input()
    cnt = Counter(s)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(n - 1):
        for j in range(i + 1, n):
            ken = j * 2 - i
            if (ken >= n):
                continue
            if (s[i] != s[j] and s[j] != s[ken] and s[i] != s[ken]):
                ans -= 1

    print(ans)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = list(input())

    ans = 0

    for i in range(N):
        for ii in range(i, N):
            for iii in range(ii, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (len(set([S[i], S[ii], S[iii]])) == 3):
                    ans += 1

    print(ans)


resolve()

Fixed submission:
from collections import Counter


def resolve():
    n = int(input())
    s = input()
    cnt = Counter(s)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(n - 1):
        for j in range(i + 1, n):
            ken = j * 2 - i
            if (ken >= n):
                continue
            if (s[i] != s[j] and s[j] != s[ken] and s[i] != s[ken]):
                ans -= 1

    print(ans)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = list(input())

    ans = 0

    for i in range(N):
        for ii in range(i, N):
            for iii in range(ii, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (len(set([S[i], S[ii], S[iii]])) == 3):
                    ans += 1

    print(ans)


resolve()

Fixed submission:
from collections import Counter


def resolve():
    n = int(input())
    s = input()
    cnt = Counter(s)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(n - 1):
        for j in range(i + 1, n):
            ken = j * 2 - i
            if (ken >= n):
                continue
            if (s[i] != s[j] and s[j] != s[ken] and s[i] != s[ken]):
                ans -= 1

    print(ans)

resolve()