Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N=int(input())
S=input()

retval=0

Rs=[0]
Gs=[0]
Bs=[0]
for s in S[::-1]:
    if s=='R':
        Rs.append(Rs[-1]+1)
        Gs.append(Gs[-1])
        Bs.append(Bs[-1])
    elif s=='G':
        Rs.append(Rs[-1])
        Gs.append(Gs[-1]+1)
        Bs.append(Bs[-1])
    else:
        Rs.append(Rs[-1])
        Gs.append(Gs[-1])
        Bs.append(Bs[-1]+1)



for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            continue

        rest=list(set(['R','G','B'])-set([S[i],S[j]]))[0]

        if rest=='R':
            retval+=Rs[N-j]
        elif rest=='G':
            retval+=Gs[N-j]
        else:
            retval+=Bs[N-j]
        if 2*j-i<N and S[j+(j-i)]==rest:
            retval-=1

print(retval)


Fixed submission:
from collections import Counter

N=int(input())
S=input()

dup=0
RGB=set(('R','G','B'))

for width in range(N//2+10):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==RGB:
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N=int(input())
S=input()

retval=0

for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            continue

        rest=list(set(['R','G','B'])-set([S[i],S[j]]))[0]
        for k in range(j+1,N):
            if S[k]==rest and k-j!=j-i:
                retval+=1

print(retval)


Fixed submission:
from collections import Counter

N=int(input())
S=input()

dup=0
RGB=set(('R','G','B'))

for width in range(N//2+10):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==RGB:
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N=int(input())
S=input()

dup=0

for width in range(2010):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==set(('R','G','B')):
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)


Fixed submission:
from collections import Counter

N=int(input())
S=input()

dup=0
RGB=set(('R','G','B'))

for width in range(N//2+10):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==RGB:
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N=int(input())
S=input()

dup=0

for width in range(2000):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==set(('R','G','B')):
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)


Fixed submission:
from collections import Counter

N=int(input())
S=input()

dup=0
RGB=set(('R','G','B'))

for width in range(N//2+10):
    for i in range(N):
        try:
            if set((S[i],S[i+width],S[i+width*2]))==RGB:
                dup+=1
        except IndexError:
            break

c=Counter(S)
retval=c['R']*c['G']*c['B']-dup
print(retval)