Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
R = 0
G = 0
B = 0
Z = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
    if S[i] == 'G':
        G += 1
    if S[i] == 'B':
        B += 1

for i in range(N-1):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N-1:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            Z += 1
print(R*G*B-Z)

Fixed submission:
N = int(input())
S = str(input())
R = 0
G = 0
B = 0
Z = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
    if S[i] == 'G':
        G += 1
    if S[i] == 'B':
        B += 1

for i in range(N-1):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N-1:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            Z += 1
print(R*G*B-Z)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
R = []
G = []
B = []
answer = 0
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            if abs(min(r, g)-b) != abs(max(r, g)-b) and abs(min(r, b)-g) != abs(max(r, b)-g) and abs(min(b,g)-r) != abs(max(g, b)-r):
                answer += 1
print(answer)

Fixed submission:
N = int(input())
S = str(input())
R = 0
G = 0
B = 0
Z = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
    if S[i] == 'G':
        G += 1
    if S[i] == 'B':
        B += 1

for i in range(N-1):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N-1:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            Z += 1
print(R*G*B-Z)

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

Fixed submission:
N = int(input())
S = str(input())
R = 0
G = 0
B = 0
Z = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
    if S[i] == 'G':
        G += 1
    if S[i] == 'B':
        B += 1

for i in range(N-1):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N-1:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            Z += 1
print(R*G*B-Z)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
R = []
G = []
B = []
answer = 0
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    if S[i] == 'G':
        G.append(i)
    if S[i] == 'B':
        B.append(i)
for r in R:
    for g in G:
        for b in B:
            X = [r, g, b]
            X.sort()
            if int(X[1]) - int(X[0]) != int(X[2]) - int(X[1]):
                answer += 1
print(answer)

Fixed submission:
N = int(input())
S = str(input())
R = 0
G = 0
B = 0
Z = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
    if S[i] == 'G':
        G += 1
    if S[i] == 'B':
        B += 1

for i in range(N-1):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N-1:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            Z += 1
print(R*G*B-Z)