Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
P = 0
JI = 0
RGB = 'R'
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if S[i] != S[j]:
            JI = j-i
            if S[i] != 'R' and S[j] != 'R':
                RGB = 'R'
            elif S[i] != 'G' and S[j] != 'G':
                RGB = 'G'
            else:
                RGB = 'B'
            for k in range(j+1,N):
                if JI != k-j:
                    if S[k] == RGB:
                        P += 1
print(P)

Fixed submission:
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)

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

Fixed submission:
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)

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

Fixed submission:
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)

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

Fixed submission:
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)

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

Fixed submission:
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)