Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
r=[]
g=[]
b=[]
for i in range(n):
    tmp=s[i]
    if tmp=="R":
        r.append(i)
    elif tmp=="G":
        g.append(i)
    else:
        b.append(i)
for i in r:
    for j in g:
        for k in b:
            if (i<j and j<k):
                if j-i!=k-j:
                    ans+=1
            elif (i<k and k<j):
                if k-i!=j-k:
                    ans+=1
            elif (j<i and i<k):
                if i-j!=k-i:
                    ans+=1
            elif (j<k and k<i):
                if k-j!=i-k:
                    ans+=1
            elif (k<i and i<j):
                if i-k!=j-i:
                    ans+=1
            elif (k<j and j<i):
                if j-k!=i-j:
                    ans+=1
print(ans)

Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
r=[]
g=[]
b=[]
for i in range(n):
    tmp=s[i]
    if tmp=="R":
        r.append(i+1)
    elif tmp=="G":
        g.append(i+1)
    else:
        b.append(i+1)
for i in r:
    for j in g:
        for k in b:
            if (i<j and j<k):
                if j-i!=k-j:
                    ans+=1
            elif (i<k and k<j):
                if k-i!=j-k:
                    ans+=1
            elif (j<i and i<k):
                if i-j!=k-i:
                    ans+=1
            elif (j<k and k<i):
                if k-j!=i-k:
                    ans+=1
            elif (k<i and i<j):
                if i-k!=j-i:
                    ans+=1
            elif (k<j and j<i):
                if j-k!=i-j:
                    ans+=1
print(ans)


Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
r=[]
g=[]
b=[]
for i in range(n):
    tmp=s[i]
    if tmp=="R":
        r.append(i+1)
    elif tmp=="G":
        g.append(i+1)
    else:
        b.append(i+1)
for i in r:
    for j in g:
        for k in b:
            if (i<j and j<k):
                if j-i!=k-j:
                    ans+=1
            elif (i<k and k<j):
                if k-i!=j-k:
                    ans+=1
            elif (j<i and i<k):
                if i-j!=k-i:
                    ans+=1
            elif (j<k and k<i):
                if k-j!=i-k:
                    ans+=1
            elif (k<i and i<j):
                if i-k!=j-i:
                    ans+=1
            elif (k<j and j<i):
                if j-k!=i-j:
                    ans+=1
print(ans)

Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
for i in range(n):
    si=s[i]
    for j in range(i+1,n):
        sj=s[j]
        tmp=j-i
        if si==sj:
            continue
        for k in range(j+1,n):
            sk=s[k]
            if tmp==k-j:
                continue
            if sk==si or sk==sj:
                continue
            ans+=1
print(ans)


Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
for i in range(n):
    si=s[i]
    for j in range(i+1,n):
        sj=s[j]
        tmp=j-i
        if si==sj:
            pass
        else:
            for k in range(j+1,n):
                sk=s[k]
                if tmp==k-j:
                    continue
                if sk==si or sk==sj:
                    continue
                ans+=1
print(ans)


Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
for i in range(n):
    si=s[i]
    for j in range(i+1,n):
        sj=s[j]
        if si==sj:
            pass
        else:
            for k in range(j+1,n):
                sk=s[k]
                if sk==si or sk==sj:
                    continue
                if j-i==k-j:
                    continue
                ans+=1
print(ans)

Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(n):
        if i+j+j>=n:
            break
        s1=s[i]
        s2=s[i+j]
        s3=s[i+j*2]
        if s1!=s2 and s2!=s3 and s1!=s3:
            ans-=1
print(ans)