Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
S = list(input())
num = [i for i in range(0,N)]
C = list(itertools.combinations(num,3))
ans = 0
for c in C:
    if c[1]-c[0] == c[2]-c[1]:
        continue
    if S[c[0]] != S[c[1]] and S[c[1]] != S[c[2]] and S[c[0]] != S[c[2]]:
        ans += 1
print(ans)


Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] != S[j] and S[i] != 'R' and S[j] != 'R':
          ans += S[j:N].count('R')
          if j+(j-i) < N and S[j+(j-i)] == 'R':
            ans -= 1
        elif S[i] != S[j] and S[i] != 'G' and S[j] != 'G':
          ans += S[j:N].count('G')
          if j+(j-i) < N and S[j+(j-i)] == 'G':
            ans -= 1
        elif S[i] != S[j] and S[i] != 'B' and S[j] != 'B':
          ans += S[j:N].count('B')
          if j+(j-i) < N and S[j+(j-i)] == 'B':
            ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

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

Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

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

Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

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

Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

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

Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)

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


Fixed submission:
N = int(input())
S = list(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R*G*B
for i in range(N):
    for k in range(i+1,N):
        if (k+i)%2 == 1:
            continue
        else:
            j = (k+i)//2
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
print(ans)