Buggy python submission (verdict: Time Limit Exceeded):
A=[['R','G','B'],['R','B','G'],['B','R','G'],['B','G','R'],['G','R','B'],['G','B','R']]
m=int(input())
N=input()
cnt=0
for i in range(6):
  for j in range(m):
    if N[j]==A[i][0]:
      for k in range(j+1,m):
        if N[k]==A[i][1]:
          for l in range(k+1,m):
            if N[l] == A[i][2]:
              if l-k != k-j:
                cnt+=1
print(cnt)
              

Fixed submission:
m=int(input())
N=input()
cnt=N.count('R')*N.count('G')*N.count('B')
#print(cnt)
for i in range(m-2):
  #print(i,'*',int((m+i)/2))
  for j in range(i+1,int((m+i-1)/2)+1):
    k=2*j-i
    #print(i,j,k)
    if N[k] != N[j] and N[j] != N[i] and N[i] != N[k]:
      #print(i,j,k)
      cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
A=[['R','G','B'],['R','B','G'],['B','R','G'],['B','G','R'],['G','R','B'],['G','B','R']]
m=int(input())
N=input()
cnt=0
for i in range(6):
  for j in range(m):
    if N[j]==A[i][0]:
      for k in range(j+1,m):
        if N[k]==A[i][1]:
          for l in range(k+1,m):
            if N[l] == A[i][2]:
              if l-k != k-j:
                cnt+=1
print(cnt)
              

Fixed submission:
m=int(input())
N=input()
cnt=N.count('R')*N.count('G')*N.count('B')
#print(cnt)
for i in range(m-2):
  #print(i,'*',int((m+i)/2))
  for j in range(i+1,int((m+i-1)/2)+1):
    k=2*j-i
    #print(i,j,k)
    if N[k] != N[j] and N[j] != N[i] and N[i] != N[k]:
      #print(i,j,k)
      cnt-=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
str=input()

cnt=0
for i in range(N):
    if str[i] == 'R':
        for j in range(i+1,N):
            if str[j] == 'G':
                for k in range(j+1,N):
                    if str[k] == 'B':
                        if j-i != k-j:
                            cnt+=1

for i in range(N):
    if str[i] == 'R':
        for j in range(i+1,N):
            if str[j] == 'B':
                for k in range(j+1,N):
                    if str[k] == 'G':
                        if j-i != k-j:
                            cnt+=1

for i in range(N):
    if str[i] == 'G':
        for j in range(i+1,N):
            if str[j] == 'R':
                for k in range(j+1,N):
                    if str[k] == 'B':
                        if j-i != k-j:
                            cnt+=1

for i in range(N):
    if str[i] == 'G':
        for j in range(i+1,N):
            if str[j] == 'B':
                for k in range(j+1,N):
                    if str[k] == 'R':
                        if j-i != k-j:
                            cnt+=1

for i in range(N):
    if str[i] == 'B':
        for j in range(i+1,N):
            if str[j] == 'G':
                for k in range(j+1,N):
                    if str[k] == 'R':
                        if j-i != k-j:
                            cnt+=1

for i in range(N):
    if str[i] == 'B':
        for j in range(i+1,N):
            if str[j] == 'R':
                for k in range(j+1,N):
                    if str[k] == 'G':
                        if j-i != k-j:
                            cnt+=1

print(cnt)

Fixed submission:
m=int(input())
N=input()
cnt=N.count('R')*N.count('G')*N.count('B')
#print(cnt)
for i in range(m-2):
  #print(i,'*',int((m+i)/2))
  for j in range(i+1,int((m+i-1)/2)+1):
    k=2*j-i
    #print(i,j,k)
    if N[k] != N[j] and N[j] != N[i] and N[i] != N[k]:
      #print(i,j,k)
      cnt-=1
print(cnt)