Buggy python submission (verdict: Time Limit Exceeded):
count=0
n=int(input())
l=list(map(str,input()))
i=0
while i<=n-3:
    j=i+1
    while i+1<=j and j<=n-2:
        if l[i]==l[j]:
            j+=1
        else:
            k=j+1
            while j+1<=k and k<=n-1:
                if l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k] and k-j!=j-i:
                    count+=1
                    k+=1
                else:
                    k+=1
            j+=1
    i+=1
print(count)

Fixed submission:
n=int(input())
l=input()
a=l.count('R')
b=l.count('G')
c=l.count('B')
d=a*b*c
i=0
count=0
lis=list(l)
while i<=n-3:
    j=i+1
    while i+2*(j-i)<=n-1:
        if lis[i]!=lis[j] and lis[j]!=lis[i+2*(j-i)] and lis[i]!=lis[i+2*(j-i)]:
            count+=1
            j+=1
        else:
            j+=1
    i+=1
print(d-count)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(str,input()))
i=0
while 0<=i and i<=n-3:
    
    if l[i]=='R':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    if l[i]=='G':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='G':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
    if l[i]=='B':
        j=i+1
        while i+1<=j and j<=n-2:
            if l[j]=='B':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n-1 and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                        k+=1
                    else:
                        k+=1
                j+=1
        i+=1
print(count)

Fixed submission:
n=int(input())
l=input()
a=l.count('R')
b=l.count('G')
c=l.count('B')
d=a*b*c
i=0
count=0
lis=list(l)
while i<=n-3:
    j=i+1
    while i+2*(j-i)<=n-1:
        if lis[i]!=lis[j] and lis[j]!=lis[i+2*(j-i)] and lis[i]!=lis[i+2*(j-i)]:
            count+=1
            j+=1
        else:
            j+=1
    i+=1
print(d-count)

Buggy python submission (verdict: Runtime Error):
count=0

n=int(input())
l=list(map(str,input()))
for i in range(n-3):
    if list[0]=='R':
        j=i+1
        while i+1<=j and j<=n-1:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1
    if list[0]=='G':
        j=i+1
        while i+1<=j and j<=n-1:
            if l[j]=='G':
                j+=1
            else:
                k+=1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1    
    if list[0]=='B':
        j+=1
        while i+1<=j and j<=n-1:
            if l[j]=='B':
                j+=1
            else:
                k+=1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1
print(count)

Fixed submission:
n=int(input())
l=input()
a=l.count('R')
b=l.count('G')
c=l.count('B')
d=a*b*c
i=0
count=0
lis=list(l)
while i<=n-3:
    j=i+1
    while i+2*(j-i)<=n-1:
        if lis[i]!=lis[j] and lis[j]!=lis[i+2*(j-i)] and lis[i]!=lis[i+2*(j-i)]:
            count+=1
            j+=1
        else:
            j+=1
    i+=1
print(d-count)