Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            count=count+s[j+1:].count(s3)
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            for k in range(j+1,n):
                if j-i!=k-j: 
                    if s1!=s[k]: 
                        if s2!=s[k]:
                            count=count+1
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(0,n-2):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            for k in range(j+1,n):
                if j-i!=k-j: 
                    if s1!=s[k]: 
                        if s2!=s[k]:
                            count=count+1
print(count)


Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(0,n-2):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            for k in range(j+1,n):
                if j-i!=k-j and s1!=s[k] and s2!=s[k]:
                    count=count+1
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=0
for i in range(0,n-2):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            for k in range(j+1,n):
                if j-i!=k-j and s1!=s[k] and s2!=s[k]:
                    count=count+1
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
count=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 j-i!=k-j and s[j]!=s[k] and s[i]!=s[k]:
                    count=count+1
print(count)

Fixed submission:
n=int(input())
s=input()
count=0
A=[[0,0,0]for i in range(n)]
for i in range(0,n):
    if s[n-i-1]=="R":
        A[n-i-2][0]=A[n-i-1][0]+1
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="G":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]+1
        A[n-i-2][2]=A[n-i-1][2]
    if s[n-i-1]=="B":
        A[n-i-2][0]=A[n-i-1][0]
        A[n-i-2][1]=A[n-i-1][1]
        A[n-i-2][2]=A[n-i-1][2]+1
for i in range(0,n-3):
    s1=s[i]
    for j in range(i+1,n-1):
        s2=s[j]
        if s1!=s2:
            if s1=="R" and s2=="G":
                s3="B"
            elif s1=="G" and s2=="R":
                s3="B"
            elif s1=="R" and s2=="B":
                s3="G"
            elif s1=="B" and s2=="R":
                s3="G"
            elif s1=="B" and s2=="G":
                s3="R"
            elif s1=="G" and s2=="B":
                s3="R"
            if s3=="R":
                s4=0
            if s3=="G":
                s4=1
            if s3=="B":
                s4=2
            count=count+A[j][s4]
            if j+j-i+1<=n: 
                if s[j+j-i]==s3:
                    count=count-1
print(count)