Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections

def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for i in R:
        for j in G:
            if max(i,j)+abs(i-j) in B:
                cnt-=1
            if min(i,j)-abs(i-j) in B:
                cnt-=1
            if (i+j)%2==0 and (i+j)//2 in B:
                cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=len(R)*len(G)*len(B)
    for i in R:
        for j in G:
            if max(i,j)+abs(i-j) in B:
                cnt-=1
            if min(i,j)-abs(i-j) in B:
                cnt-=1
            if (i+j)%2==0 and (i+j)//2 in B:
                cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    for i in R:
        for j in G:
            
            for k in B:
                if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                    cnt+=1

    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    if len(R)==max(len(R),len(G),len(B))
        for i in B:
            for j in G:
                for k in R:
                    if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                        cnt+=1

        print(cnt)
    if len(G) == max(len(R), len(G), len(B))
        for i in B:
            for j in R:
                for k in G:
                    if max(i, j, k) - (i + j + k - max(i, j, k) - min(i, j, k)) != (
                            i + j + k - max(i, j, k) - min(i, j, k)) - min(i, j, k):
                        cnt += 1

        print(cnt)
    if len(B) == max(len(R), len(G), len(B))
        for i in R:
            for j in G:
                for k in B:
                    if max(i, j, k) - (i + j + k - max(i, j, k) - min(i, j, k)) != (
                            i + j + k - max(i, j, k) - min(i, j, k)) - min(i, j, k):
                        cnt += 1

        print(cnt)



if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    for i in R:
        for j in G:
            for k in B:
                if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                    cnt+=1

    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    for i in R:
        for j in G:
            for k in B:
                if abs(i-j)!=abs(j-k) and abs(j-k)!=abs(k-i) and abs(j-i)!=abs(i-k):
                    cnt+=1
    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=0
    for i in R:
        for j in G:
            for k in B:
                if abs(i-j)!=abs(j-k) and abs(j-k)!=abs(k-i) and abs(j-i)!=abs(i-k):
                    cnt+=1
    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
N=int(input())
Tr=list(input())
R=[]
G=[]
B=[]
for i in range(N):
   if Tr[i]=="R":
       R.append(i)
   if Tr[i]=="G":
       G.append(i)
   if Tr[i]=="B":
       B.append(i)
cnt=0
for i in R:
    for j in G:
        for k in B:
            if abs(i-j)!=abs(j-k) and abs(j-k)!=abs(k-i) and abs(j-i)!=abs(i-k):
                cnt+=1
print(cnt)


Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import collections
N=int(input())
Tr=list(input())
R=[]
G=[]
B=[]
for i in range(N):
   if Tr[i]=="R":
       R.append(i)
   if Tr[i]=="G":
       G.append(i)
   if Tr[i]=="B":
       B.append(i)
cnt=0
for i in R:
    for j in G:
        for k in B:
            if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                cnt+=1
print(cnt)


Fixed submission:
import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()