Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[j] != S[i]:
            for k in range(j + 1, N):
                if j - i != k - j and S[k] != S[i] and S[k] != S[j]:
                    ans += 1
print(ans)


Fixed submission:
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()

ans = 0

for i in range(N - 2):
    #S_i = S[i]
    for j in range(i + 1, N - 1):
        if S[j] != S[i]:
            #S_j = S[j]
            for k in range(j + 1, N):
                if j - i != k - j and S[k] != S[i] and S[k] != S[j]:
                    ans += 1
print(ans)

Fixed submission:
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()

ans = 0

for i in range(N - 2):
    S_i = S[i]
    for j in range(i + 1, N - 1):
        if S[j] != S_i:
            S_j = S[j]
            for k in range(j + 1, N):
                if j - i != k - j and S[k] != S_i and S[k] != S_j:
                    ans += 1
print(ans)


Fixed submission:
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()

ans = 0

for i in range(N - 2):
    S_i = S[i]
    for j in range(i, N - 1):
        if S[j] != S_i:
            S_j = S[j]
            for k in range(j, N):
                if j - i != k - j and S[k] != S_i and S[k] != S_j:
                    ans += 1
print(ans)

Fixed submission:
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S = input()

ans = 0

for i in range(N - 2):
    S_i = S[i]
    for j in range(i, N - 1):
        if S[j] != S_i:
            S_j = S[j]
            for k in range(j, N):
                if j - i != k - j and S[k] != S_i and S[k] != S_j:
                    ans += 1
print(ans)

Fixed submission:
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()