Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
R=[]
G=[]
B=[]

def binary_search(A,n):
    find=False
    start=0
    end=len(A)
    if len(A)==1 and A[0]==n:
        find=True
    elif A[0]==n:
        find=True
    else:
        while find==False and start<end-1:
            middle=(start+end)//2
            if n>A[middle]:
                start=middle
            elif n<A[middle]:
                end=middle
            else:
                find=True
    return find

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

EVERY=len(R)*len(G)*len(B)

REMOVE=0
for r in R:
    for g in G:
        if (r+g)%2==0:
            candidate=[2*r-g,(r+g)//2,2*g-r]
        else:
            candidate=[2*r-g,2*g-r]
        
        for e in candidate:
            if binary_search(B,e)==True:
                REMOVE+=1

print(EVERY-REMOVE)

Fixed submission:
N=int(input())
S=input()
R=[]
G=[]
B=[]

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

ANS=len(R)*len(G)*len(B)

for i in range(N-2):
    for j in range(i+1,N-1):
        k=2*j-i
        if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ANS-=1


print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=[]
G=[]
B=[]

def binary_search(A,n):
    find=False
    start=0
    end=len(A)
    if len(A)==1 and A[0]==n:
        find=True
    elif A[0]==n:
        find=True
    else:
        while find==False and start<end-1:
            middle=(start+end)//2
            if n>A[middle]:
                start=middle
            elif n<A[middle]:
                end=middle
            else:
                find=True
    return find

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

EVERY=len(R)*len(G)*len(B)

REMOVE=0
for r in R:
    for g in G:
        if (r+g)%2==0:
            candidate=[2*r-g,(r+g)//2,2*g-r]
        else:
            candidate=[2*r-g,2*g-r]
        
        for e in candidate:
            #if binary_search(B,e)==True:
            if e in B:
                REMOVE+=1

print(EVERY-REMOVE)

Fixed submission:
N=int(input())
S=input()
R=[]
G=[]
B=[]

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

ANS=len(R)*len(G)*len(B)

for i in range(N-2):
    for j in range(i+1,N-1):
        k=2*j-i
        if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ANS-=1


print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=[]
G=[]
B=[]
for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

x=0
for r in R:
    for g in G:
        for b in B:
            l=[r,g,b]
            if sum(l)/3 in l:
                pass
            else:
                x+=1

print(x)

Fixed submission:
N=int(input())
S=input()
R=[]
G=[]
B=[]

for n in range(N):
    if S[n]=="R":
        R.append(n)
    elif S[n]=="G":
        G.append(n)
    else:
        B.append(n)

ANS=len(R)*len(G)*len(B)

for i in range(N-2):
    for j in range(i+1,N-1):
        k=2*j-i
        if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ANS-=1


print(ANS)