We have a string S of length N consisting of R, G, and B.
Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:
 - S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.
 - j - i \neq k - j.

-----Constraints-----
 - 1 \leq N \leq 4000
 - S is a string of length N consisting of R, G, and B.

-----Input-----
Input is given from Standard Input in the following format:
N
S

-----Output-----
Print the number of triplets in question.

-----Sample Input-----
4
RRGB

-----Sample Output-----
1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Difficulty: interview

Starter code:

Solutions:
N = int(input())
S =  input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
    r = S[i]
    for j in range(i+1,N-1):
        g = S[j]
        if r == g:
            continue
        k = 2*j - i
        if k >= N:
            continue
        b = S[k]
        if r != b and g != b:
            ans -= 1
print(ans)

from collections import Counter
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    ans = 0
    r, g, b = [0 for _ in range(N+1)], [0 for _ in range(N+1)], [0 for _ in range(N+1)]
    for i in range(N):
        r[i+1], g[i+1], b[i+1] = r[i], g[i], b[i]
        if S[i] == "R":
            r[i+1] += 1
        elif S[i] == "G":
            g[i+1] += 1
        else:
            b[i+1] += 1
    
    for i in range(1, N-1):
        if S[i] == "R":
            ans += g[i] * (b[N] - b[i+1]) + b[i] * (g[N] - g[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"G", "B"}:
                    ans -= 1
        
        elif S[i] == "G":
            ans += r[i] * (b[N] - b[i+1]) + b[i] * (r[N] - r[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"R", "B"}:
                    ans -= 1
        elif S[i] == "B":
            ans += g[i] * (r[N] - r[i+1]) + r[i] * (g[N] - g[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"G", "R"}:
                    ans -= 1
    print(ans)

main()

n = int(input())
s = list(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b
for i in range(n-2):
    for j in range(i+1,n-1):
        if (j - i) + j < n:
            k = (j - i) + j
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1
print(ans)                

n,s=int(input()),input()
c=s.count('R')*s.count('G')*s.count('B')
for i in range(n+1):
  for j in range(i,n+1):
    k=2*j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        c-=1
print(c)

n = int(input())
s = input()
ans = 0
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n - 2):
  for d in range(1, n):
    j = i + d
    k = j + d
    if k >= n:
      break
    else:       
      if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
        ans -= 1
print(ans)

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

uns = 0
for d in range(1, (N - 1) // 2 + 1):
    for i in range(N - 2 * d):
        s, t, u = S[i], S[i + d], S[i + 2 * d]
        if s != t and t != u and u != s:
            uns += 1

r = S.count('R')
g = S.count('G')
b = N - r - g # = S.count('B')

ans = r * g * b - uns
print(ans)

n=int(input())
s=input()

from collections import Counter

c=Counter(s)

# ans = 1
# for i in list(c.values()):
#     ans*=i

r=s.count('R')
g=s.count('G')
b=s.count('B')

cnt=0
for i in range(n):
    for j in range(i+1,n):
        k = j+(j-i)
        if k>=n:
            break
        else:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                cnt+=1

print((r*g*b)-cnt)

from collections import Counter as C
n=int(input())
S=list(input())
a=1
L=C(S).most_common(3)
for l in L:
  a*=l[1]
for i in range(1,n):
  for j in range(n-2*i):
    if len(set((S[j],S[j+i],S[j+2*i])))==3:
      a-=1
print(a if len(L)>2 else 0)

n=int(input())
s=input()
D={"R":[],"G":[],"B":[]}

for i in range(1,n+1):
	D[s[i-1]].append(i)
ans=len(D["R"])*len(D["G"])*len(D["B"])

count=0
for i in range(0,n): 
	for j in range(i+1,n):
		k=2*j-i
		if k >= n:
			break
		if s[i]!=s[j] and s[j]!=s[k] and s[i] != s[k]:
			count+=1

print(ans-count)

def main():
    n = int(input())
    s = input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r*g*b

    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j-i
            if 0 <= k < n:
                if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                    ans -= 1
    print(ans)

def __starting_point():
    main()
__starting_point()

n = int(input())
s = input()
total = 1
for c in 'RGB':
  total *= s.count(c)
for i in range(1, n - 1):
  for j in range(1, min(i + 1, n - i)):
    if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]:
      total -= 1
print(total)

from functools import reduce
from operator import mul

def solve():
  N = int(input())
  S = input()
  RGB_count = {'R':0,'G':0,'B':0} # R,G,B
  RGB_set = {'R','G','B'}
  ret = 0
  for s in S:
    ret += reduce(mul, [RGB_count[t] for t in RGB_set - {s}])
    RGB_count[s] = RGB_count[s] + 1

  # print(ret)
  RGB_mergin_len = 0
  # R.{l}G.{l}B
  while 3+RGB_mergin_len*2 <= N:
    for i in range(N-(3+RGB_mergin_len*2)+1):
      j = i+1+RGB_mergin_len
      k = i+2+2*RGB_mergin_len
      if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
        ret -= 1

      # print(i, j, k)
      # print(S[i], S[j], S[k], ret)
    RGB_mergin_len += 1

  print(ret)
  
solve()

n = int(input())
s = input()
r, g, b = s.count('R'), s.count('G'), s.count('B')
ans = r * g * b
for i in range(n-2):
    for j in range(i+1, n-1):
        k = 2 * j - i
        if 0 <= k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
print(ans)

def abc162d_rgb_triplets():
    n = int(input())
    s = input()
    r_cnt = 0
    g_cnt = 0
    b_cnt = 0
    for i in range(n - 1, -1, -1):
        if s[i] == 'R':
            r_cnt += 1
        elif s[i] == 'G':
            g_cnt += 1
        else:
            b_cnt += 1

    result = r_cnt * g_cnt * b_cnt
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = j + (j - i)
            if s[i] == s[j] or k >= n or s[i] == s[k] or s[j] == s[k]: continue
            result -= 1
    print(result)



abc162d_rgb_triplets()

n=int(input())
s = list(input())
count = s.count('R') * s.count('G') * s.count('B')

for i in range(n-2):
  for j in range(1, (n+1-i)//2):
    #print(sorted([s[i], s[i+j], s[i+2*j]]), txt)
    if sorted([s[i], s[i+j], s[i+2*j]]) == ['B', 'G', 'R']:
      count -= 1

print(count)

N=int(input())
S=input()
cnt=0
for i in range(N):
    left=i-1
    right=i+1
    while 0<=left and right<N:
        if S[i]!=S[left] and S[i]!=S[right] and S[left]!=S[right]:
            cnt+=1
        left-=1
        right+=1
x=S.count('R')
y=S.count('G')
z=S.count('B')
print((x*y*z-cnt))


n=int(input())
s=input()
R=[]
G=[]
B=[]
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())

from collections import Counter
def main():
    n=int(input())
    s=input()
    d=Counter(s)
    a=d["R"]*d["G"]*d["B"]
    for i in range(n):
        t=min(n-i-1, i)
        for j in range(t+1):
            if s[i-j] != s[i] and s[i-j] != s[i+j] and s[i] != s[i+j]:
                a-=1
    print(a)
    
def __starting_point():
    main()
__starting_point()

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

r = S.count('R')
g = S.count('G')
b = S.count('B')

cnt = 0
for i in range(N-3):
    if S[i] == 'R':
        r -= 1
        cnt += g * b 
        l = 1
        while (i + 2 * l < N):
            if (S[i+l] == 'G' and S[i+2*l] == 'B') or (S[i+l] == 'B' and S[i+2*l] == 'G'):
                cnt -= 1
            l += 1
    if S[i] == 'G':
        g -= 1
        cnt += r * b 
        l = 1
        while (i + 2 * l < N):
            if (S[i+l] == 'R' and S[i+2*l] == 'B') or (S[i+l] == 'B' and S[i+2*l] == 'R'):
                cnt -= 1
            l += 1
    if S[i] == 'B':
        b -= 1
        cnt += g * r
        l = 1
        while (i + 2 * l < N):
            if (S[i+l] == 'G' and S[i+2*l] == 'R') or (S[i+l] == 'R' and S[i+2*l] == 'G'):
                cnt -= 1
            l += 1
print(cnt)


n=int(input())
S=str(input())
r=S.count('R')
g=S.count('G')
b=S.count('B')
cnt=r*g*b

for j in range(2, n, 2):
    for i in range(0, n-j):
        k = (2 * i + j) // 2
        if S[i] != S[i+j] and S[i] != S[k] and S[k] != S[i+j]:
            cnt -= 1

print(cnt)

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
s=input()
c=Counter(s)

ans=c['R']*c['G']*c['B']

lim=n//2
for i in range(1,n//2+1):
  for j in range(i,n-i):
    l=s[j-i]
    m=s[j]
    r=s[j+i]
    if l!=m and m!=r and r!=l:
      ans-=1

print(ans)


def main():
    '''
    #このコードだと、tleになる
    n = int(input())
    s = input()
    cnt = 0
    for i in range(len(s)):
        x = s[i]
        for j in range(i+1, len(s)):
            y = s[j]
            if x == y:
                continue
            for k in range(j+1, len(s)):
                z = s[k]
                if z == x or z == y:
                    continue
                if j - i == k - j:
                    continue
                cnt += 1
                # print(f"{i} {j} {k}")
    print(cnt)
    '''
    n = int(input())
    s = input()
    cnt = [0]*3
    ans = 1
    for i in s:
        if i == 'R':cnt[0]+=1
        elif i == 'G':cnt[1]+=1
        else:cnt[2]+=1
    for i in cnt:
        ans *= i
    for i in range(n):
        for j in range(i+1,n):
            k = j + (j - i)
            if k < n:
                if s[i] == s[j]: continue
                if s[j] == s[k]: continue
                if s[k] == s[i]: continue
                ans -= 1
    print(ans)



def __starting_point():
    main()
__starting_point()

n = int(input())
s = input()

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n-2):
    for j in range(i+1, n-1):
        k = 2*j-i
        if k < n:
            if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
                ans -= 1
        else:
            break
print(ans)

import math
import sys
import os
from operator import mul
import bisect

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
S = list(_S())
ans = 0

r = []
g = []
b = []

for i,s in enumerate(S):
    if s == 'R':
        r.append(i)
    if s == 'G':
        g.append(i)
    if s == 'B':
        b.append(i)

# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)

# for i in r:
#     for j in g:
#         for k in b:
#             tmp = sorted([i,j,k])
#             if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
#                 ans += 1

ans = len(r)*len(g)*len(b)

for i in range(N):
    for j in range(i,N):
        k = j + (j-i)
        if k > N-1:
            break
        if S[i]==S[j]:
            continue
        if S[i]==S[k] or S[j]==S[k]:
            continue
        ans -= 1

print(ans)

# R G B
# R B G
# G B R
# G R B
# B G R
# B R G

# i   j   k
#  - != -

# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334

# B*3
# G*4

# GB系: (2,4), (4,5)
# RB系: (1,3),


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

n = int(input())
s = input()

tmp = 0
res = s.count("R") * s.count("G") * s.count("B")

for i in range(n - 2):
    for j in range(i + 1, floor((n + i + 1) / 2)):
        k = 2 * j - i
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            res -= 1

print(res)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    s = input()

    res = s.count('R') * s.count('G') * s.count('B')
    if res == 0:
        print((0))
        return
    for i1 in range(n):
        for i2 in range(i1+1, n):
            i3 = i2 * 2 - i1
            if i3 <= n - 1:
                res -= s[i1] != s[i2] and s[i1] != s[i3] and s[i2] != s[i3]
    print(res)

def __starting_point():
    main()

__starting_point()

N=int(input())
S=input()
c=S.count
x=c("R")*c("G")*c("B")
c=0
for i in range(N):
 for j in range(i+1,N):
  if S[i]!=S[j]:
   k=2*j-i
   if k<N and S[k]!=S[i] and S[k]!=S[j]:x-=1
print(x)

n = int(input())
s = list(input())

cnt = 0
for j in range(2, n, 2):
    for i in range(0, n-j):
        k = (2 * i + j) // 2
        if s[i] != s[i+j] and s[i] != s[k] and s[k] != s[i+j]:
            cnt += 1

r, g, b = 0, 0, 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1

print(r*g*b-cnt)

import math
from math import gcd,pi
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    s = s_input()

    r_cn = s.count("R")
    g_cn = s.count("G")
    b_cn = s.count("B")

    ans = r_cn*g_cn*b_cn

    for i in range(n):
        for d in range(n):
            j = i+d
            k = j+d
            if k >=n:
                break
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1
    print(ans)


def __starting_point():
    main()

__starting_point()

n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(n-1):
    for j in range(1, min(i+1, n-i)):
            if (s[i] != s[i-j]) and (s[i] != s[i+j]) and (s[i-j] != s[i+j]):
                cnt += 1
print(r*g*b-cnt)

N=int(input())
S=input()
SS=[]
for i in range(N):
  if S[i]=='R':SS.append(1)
  elif S[i]=='G':SS.append(2)
  else:SS.append(4)
s=0
for i in range(1,N-1):
  for j in range(1,min(i+1,N-i)):
    if SS[i-j]+SS[i]+SS[i+j]==7:
      s+=1
print(SS.count(1)*SS.count(2)*SS.count(4)-s)

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
S = ns()
d = {'R': 0, 'G': 0, 'B': 0}
for i in range(N):
    d[S[i]] += 1
ans = 1
for v in d.values():
    ans *= v
for i in range(N):
    for j in range(i+1, N):
        k = j + (j - i)
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(max(ans, 0))

import collections
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N=INT()
S=input()
if N<3:
  print(0)
  return
r=S.count("R")
g=S.count("G")
b=S.count("B")
ans=r*g*b
for i in range(N-2):
  for j in range(i+1,N-1):
    k=j*2-i
    if k>=N:
      continue
    if S[j]!=S[i] and S[k]!=S[i] and S[j]!=S[k]:
      ans-=1
print(ans)

N=int(input())
S=str(input())
ans=S.count('R')*S.count('G')*S.count('B')

for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i]==S[j]:
      continue
    if 2*j - i < N:
      if S[2*j - i] != S[i] and S[2*j - i] != S[j]:
        ans-=1
print(ans)


n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

N = int(input())
S = list(input())
r, g, b = 0, 0, 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

from collections import Counter
N = int(input())
S = input()
D = Counter(S)
ans = 1
for d in D.values():
    ans *= d

if len(D.values()) < 3:
    ans = 0

for i in range(N):
    for x in range(1, (N-i+1)//2):
        if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]:
            ans -= 1
print(ans)

N=int(input())
S=input()
x=S.count("R")*S.count("G")*S.count("B")
c=0
for i in range(N):
 for j in range(i+1,N):
  if S[i]!=S[j]:
   k=2*j-i
   if k<N and S[k]!=S[i] and S[k]!=S[j]:c+=1
print(x-c)

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

lenb = len(B)

cnt = 0
for r in R:
    for g in G:
        up = max(r, g)
        down = min(r, g)
        diff = up - down
        
        chk = 0
        if up + diff <= N:
            if S[up+diff-1] == 'B':
                chk += 1
        if down-diff >= 1:
            if S[down-diff-1] == 'B':
                chk += 1
        if diff%2 == 0:
            if S[int(up-diff/2-1)] == 'B':
                chk += 1
        cnt += lenb - chk

print(cnt)


import sys
from collections import Counter
N = int(input())
S = list(input())
Sc = Counter(S)
R = Sc["R"]
G = Sc["G"]
B = Sc["B"]
if R == 0 or G == 0 or B == 0:
    print((0))
    return
else:
    ans = R*G*B
for i in range(1, N//2+2):
    for j in range(N):
        if j+i+i >= N:
            break
        if S[j] == S[j+i]:
            continue
        if S[j] == S[j+i+i]:
            continue
        if S[j+i] == S[j+i+i]:
            continue
        ans -= 1
print(ans)


# -*- coding: utf-8 -*-
import sys
from collections import Counter


def main():
    N = int( sys.stdin.readline() )
    S = sys.stdin.readline().rstrip()

    cnt_dic = Counter(S)
    ans = cnt_dic["R"] * cnt_dic["G"] * cnt_dic["B"]

    for i in range(N):
        for j in range(i+1, N):
            k = 2*j - i

            if (k < len(S)) and (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
                ans -= 1


    print(ans)


def __starting_point():
    main()

__starting_point()

N = int(input())
S = input()
C = {"R", "G", "B"}
cumsum = {c:[0 for i in range(N)] for c in C}

for i in range(N):
  s = S[i]
  cumsum[s][i] = 1
for i in range(2, N+1):
  for c in C:
    cumsum[c][-i] = cumsum[c][-i] + cumsum[c][-(i-1)]
#print(cumsum)
ans = 0
for i in range(N-2):
  s = S[i]
  a, b = C - {s}
  ans += cumsum[a][i]*cumsum[b][i]

for i in range(1, (N-1)//2 + 1):
  for j in range(N-2*i):
    #print(j, j+i, j+2*i, S[j]+S[j+i]+S[j+2*i])
    if S[j] != S[j+i] and S[j+i] != S[j+2*i] and S[j] != S[j+2*i]:
      ans -= 1
print(ans)


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 d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)


N = int(input())
S = input()
lsS = list(S)
lscount = [lsS.count('R'),lsS.count('G'),lsS.count('B')]
ans = 1
for i in lscount:
    ans *= i
for i in range(N-2):
    for j in range(i+1,N-1):
        if lsS[i] == lsS[j]:
            continue
        if 2*j-i <= N-1:
            if lsS[i] != lsS[2*j-i] and lsS[j] != lsS[2*j-i]:
                ans -= 1
        else:
            break
print(ans)

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

all = S.count("R") * S.count("G") * S.count("B")

cnt = 0
for i in range(N):
    for j in range(i, N):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            cnt += 1
print(all - cnt)

import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
mod = 998244353

n = ri()
s = rs()
r_li, g_li, b_li = [], [], []
for i in s:
    if i == "R":
        r_li.append(i)
    if i == "G":
        g_li.append(i)
    if i == "B":
        b_li.append(i)
ans = len(r_li) * len(g_li) * len(b_li)
cnt=0
for res in range(1, n//2 + 1):
    for i in range(0, n):
        if i+2*res<=n-1:
            if s[i] != s[i+res] and s[i+res]!=s[i+res+res] and s[i+res+res]!=s[i]:
                cnt+=1
        else:
            break

print(ans-cnt)

from collections import *

N=int(input())
S=input()
c=Counter(S)

ans=c['R']*c['G']*c['B']

for i in range(1,N//2+1):
  for j in range(i,N-i):
    if S[j-i]!=S[j] and S[j]!=S[j+i] and S[j+i]!=S[j-i]:
      ans-=1

print(ans)


n = int(input())
s = input()
r,g,b = 0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    elif s[i]=="B":
        b+=1
ans = r*g*b

for i in range(n):
    for j in range(i+1,n):
        k = j + j-i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans -= 1
print(ans)

n=int(input())
S=str(input())
r=S.count('R')
g=S.count('G')
b=S.count('B')
cnt=r*g*b
for i in range(n):
    for a in range(1,n):
        j=i+a
        k=j+a
        if k>=n:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            cnt-=1

print(cnt)

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(i+1,n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if k >= n or s[k] == s[i] or s[k] == s[j]:
            continue
        ans -= 1
        
print(ans)


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

ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]

all = len(ris) * len(gis) * len(bis)

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                cnt += 1

ans = all - cnt


print(ans)


n=int(input())
s='*'+input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(1,n+1):
    for j in range(i,n+1):
        k=2*j-i
        if k>n:
            continue
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            cnt+=1
print(r*g*b-cnt)

n = int(input())
s = input()
r, g, b = [], [], []
cnt = 1
for i in s:
    if i == 'R':
        r.append(cnt)
    elif i == 'G':
        g.append(cnt)
    else:
        b.append(cnt)
    cnt += 1
rd = set(map(lambda x: x * 2, r)) #以下2つ目の条件を満たさないもの(j - i = k - j)の数え上げ
gd = set(map(lambda x: x * 2, g))
bd = set(map(lambda x: x * 2, b))
ddc = 0
for i in r:
    for j in g:
        if i + j in bd:
            ddc += 1
for j in g:
    for k in b:
        if j + k in rd:
            ddc += 1
for i in r:
    for k in b:
        if i + k in gd:
            ddc += 1
print(len(r) * len(g) * len(b) - ddc) #1つ目の条件を満たすモノから2つ目の条件を満たさないものを引く

N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
  for j in range(i+1,N):
    k = 2*j-i
    if k<N and S[i]!=S[j]!=S[k]!=S[i]:
      ans-=1

print(ans)

def main() -> None:
    n = int(input())
    s = input()

    answer = s.count('R') * s.count('G') * s.count('B')
    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j - i
            if k<n and s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                answer -= 1
    print(answer)
    return


def __starting_point():
    main()

__starting_point()

N=int(input());S=input();C=set("RGB");L=[{c:0for c in C}];M=L[:];z=-sum(C==set(S[j]+S[j+r]+S[j+2*r])for r in range(1,(N+1)//2)for j in range(N-2*r))
for c in S:L+=[L[-1].copy()];L[-1][c]+=1
for c in reversed(S):M+=[M[-1].copy()];M[-1][c]+=1
for c,l,m in zip(S,L,reversed(M[:-1])):a,b=C-set(c);z+=l[a]*m[b]+l[b]*m[a]
print(z)

N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')

ans=cntR*cntG*cntB

for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]!=S[j]:
            k=2*j-i
            if k<N and S[k]!=S[i] and S[k]!=S[j]:
                ans-=1

print(ans)

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

from collections import Counter
x=list(Counter(S).values())

if len(x)<3:
    print(0)
    return

c=0
for i in range(N):
 j=i+1
 for j in range(i+1,N):
  if S[i]!=S[j]:
   k=2*j-i
   if k<N and (S[k]!=S[i] and S[k]!=S[j]):c+=1
print(x[0]*x[1]*x[2]-c)

n = int(input())
s = input()
r, g, b = [], [], []
cnt = 1
for i in s:
    if i == 'R':
        r.append(cnt)
    elif i == 'G':
        g.append(cnt)
    else:
        b.append(cnt)
    cnt += 1
rd = set(map(lambda x: x * 2, r))
gd = set(map(lambda x: x * 2, g))
bd = set(map(lambda x: x * 2, b))
ddc = 0
for i in r:
    for j in g:
        if i + j in bd:
            ddc += 1
for j in g:
    for k in b:
        if j + k in rd:
            ddc += 1
for i in r:
    for k in b:
        if i + k in gd:
            ddc += 1
print(len(r) * len(g) * len(b) - ddc)

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    s = input()

    res = s.count('R') * s.count('G') * s.count('B')
    if res == 0:
        print(0)
        return
    for i1 in range(n):
        for i2 in range(i1+1, n):
            i3 = i2 * 2 - i1
            if i3 <= n - 1:
                if s[i1] != s[i2] and s[i1] != s[i3] and s[i2] != s[i3]:
                    res -= 1
    print(res)

def __starting_point():
    main()
__starting_point()

def main():
    n=int(input())
    s=input()
    sm=s.count("R")*s.count("G")*s.count("B")
    for i in range(1,(n-1)//2+1):
        for j in range(n-2*i):
            if len(set(s[j]+s[j+i]+s[j+2*i]))==3 : sm-=1
    print(sm)

main() 

n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

res = r*g*b

for i in range(n):
    for j in range(n):
        jj = i+j
        k = jj+j
        if k >= n: break
        if s[i]!=s[jj] and s[jj]!=s[k] and s[k]!=s[i]:
            res-=1

print(res)


N = int(input())
S = input()
lsS = list(S)
lscount = [lsS.count('R'),lsS.count('G'),lsS.count('B')]
ans = 1
f = False
for i in lscount:
    ans *= i
for i in range(N-2):
    for j in range(i+1,N-1):
        if lsS[i] == lsS[j]:
            continue
        if 2*j-i <= N-1:
            if lsS[i] != lsS[2*j-i] and lsS[j] != lsS[2*j-i]:
                ans -= 1
        else:
            f = True
            break
print(ans)

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 - 2):
    interval = 1
    while i + 2 * interval < n:
        if s[i] != s[i + interval] and s[i] != s[i + 2 * interval] and s[i + interval] != s[i + 2 * interval]:
            ans -= 1
        interval += 1

print(ans)

N = int(input())
S = list(input())
R = []
G = []
for i in range(N):
  if S[i] == "R":
    R.append(i)
  elif S[i] == "G":
    G.append(i)
r = len(R)
g = len(G)
ans = r * g * (N - r - g)
for i in R:
  for j in G:
    a = 2 * i - j
    b = 2 * j - i
    c = i + j
    if 0 <= a < N and S[a] == "B":
      ans -= 1
    if 0 <= b < N and S[b] == "B":
      ans -= 1
    if c % 2 == 0 and S[c//2] == "B":
      ans -= 1
print(ans)

def main():
    n = int(input())
    s = input()
    ans = s.count('R') * s.count('G') * s.count('B')
    for i in range(n-2):
      for j in range(i+1, n-1):
        if j - i > n - j - 1:
          break
        if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]:
          ans -= 1
    print(ans)


def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
S = list(input())

ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j * 2 - i
        if k >= N:
            break

        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1

print(ans)

n=int(input())
s,rem=input(),0
ans = s.count('R') * s.count('B') * s.count('G')

for i in range(1, (n-1) // 2 + 1):
  for j in range(i*2, n):
    if s[j]+s[j-i]+s[j-2*i] in ("RGB","RBG","GRB","GBR","BGR","BRG"):
      rem += 1
    
print(ans - rem)

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    s = input()

    res = s.count('R') * s.count('G') * s.count('B')
    if res == 0:
        print(0)
        return
    for i1 in range(n):
        for i2 in range(i1+1, n):
            if i2 * 2 - i1 <= n - 1:
                if s[i1] != s[i2]:
                    res -= s[i1] != s[i2*2 - i1] and s[i2] != s[i2*2 - i1]
    print(res)

def __starting_point():
    main()
__starting_point()


def __starting_point():

    n = int(input())
    s = list(input())

    #それぞれの組み合わせ数を求める
    R = s.count("R")
    G = s.count("G")
    B = s.count("B")
    
    sm = R*G*B
    #print("組み合わせ数="+str(sm))
    
    #cond2の条件から
    #j-i = k-jの時のkを求める
    # k = 2j - i なので
    for i in range(n):
        for j in range(i+1,n):
            k = 2*j - i
            if k < n:
                #print(s[i],s[j],s[k])
                #等間隔の場合はsmから-1する
                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                    sm -= 1
    print(sm)

__starting_point()

# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 01:23:04 2020

@author: liang
"""

N = int(input())
S = input()
R_list = list()
G_list = list()
B_list = list()

for i in range(N):
    if S[i] == 'R':
        R_list.append(i)
    elif S[i] == 'G':
        G_list.append(i)
    else:
        B_list.append(i)
#print(R_list, G_list, B_list)
ans = len(R_list)*len(G_list)*len(B_list)
"""
set1 = set()
for r in R_list:
    for g in G_list:
        # r < g
        if r > g:
           # print(r,g)
            r, g = g, r ##ダメ
           
            【rは絶対書き換えたらダメ】
            gのfor文中 rの値は固定して考えているので、
            外側ループの変数を書き換えるような演算をしてはいけない
              => for文内で別の変数（コピー）を用意し、そのコピーについて演算を行うこと
           
            #print(r,g)
        if 2*g - r < N and S[2*g-r] == 'B':
            set1.add((r,g))
            ans -= 1
        if 2*r - g >= 0 and S[2*r-g] == 'B':
            set1.add((r,g))
            ans -= 1
        if (r+g)%2 == 0 and S[(r+g)//2] =='B':
            set1.add((r,g))
            ans -= 1   
#ans = len(R_list)*len(G_list)*len(B_list)         
"""
for r in R_list:
    for g in G_list:
        up = max(r,g)
        down = min(r,g)
        diff = up - down
        if up + diff < N and S[up+diff] == 'B':
            ans -= 1
        if down - diff >= 0 and S[down - diff] == 'B':
            ans -= 1
        if diff%2 == 0 and S[down + diff//2] =='B':
            ans -= 1

print(ans)


'''
Created on 2020/09/07

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  S=pin()[:-1]
  r=0
  g=0
  b=0
  cnt=0
  for i in range(N):
    if S[i]=="R":
      r+=1
    elif S[i]=="G":
      g+=1
    elif S[i]=="B":
      b+=1
    for j in range(i+1,N):
      k=2*j-i
      if k>=N:
        continue 
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
        cnt+=1
  print(r*g*b-cnt)
  return 
main()

from functools import reduce
from operator import mul
from collections import Counter

def solve():
  N = int(input())
  S = input()
  ret = 0
  RGB_ = {'R':0, 'G':0, 'B':0}
  counter = Counter(S)
  for k,v in counter.items(): RGB_[k] += v
  ret = reduce(mul, RGB_.values())

  # print(ret)
  RGB_mergin_len = 0
  # R.{l}G.{l}B を引く
  while 3+RGB_mergin_len*2 <= N:
    for i in range(N-(3+RGB_mergin_len*2)+1):
      j = i+1+RGB_mergin_len
      k = i+2+2*RGB_mergin_len
      if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
        ret -= 1

      # print(i, j, k)
      # print(S[i], S[j], S[k], ret)
    RGB_mergin_len += 1

  print(ret)
  
solve()

n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(min(1,n//3),((n-1)//2)+1):
    for j in range(n-(i*2)):
        if s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j+i+i]!=s[j]:
            ans-=1
print(ans)


n=int(input())
s=list(input())


ans=(s.count("R"))*(s.count("G"))*(s.count("B"))

for i in range(n) :
    a=s[i]
    for j in range(i+1,n) :
        b=s[j]
        if 2*j-i>n-1 :
            break
        c=s[2*j-i]
        if (a!=b) and (b!=c) and (c!=a) :
            ans-=1

print(ans)

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

i = 1
count = 0
while i * 2 < N:
    n = 0
    while n + i * 2 < N:
        if (S[n] != S[n+i]) and (S[n+i] != S[n+2*i]) and (S[n] != S[n+i*2]):
            count += 1
            #print(S[n], S[n+i], S[n+2*i])
        n += 1
    i += 1

print(S.count('G') * S.count('R') * S.count('B') - count)

N,S=int(input()),input()
r,g,b=0,0,0
for i in list(S):
    if i=='R':r+=1
    if i=='G':g+=1
    if i=='B':b+=1
ans=r*g*b
for i in range(N-2):
    for j in range(i+1,N-1):
        if j-i>N-j-1:break
        if S[i]!=S[j]and S[j]!=S[2*j-i]and S[2*j-i]!=S[i]:
            ans-=1
print(ans)

def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print((S.count("R") * S.count("B") * S.count("G") - cnt))

def __starting_point():
    main()

__starting_point()

from collections import *

N=int(input())
S=input()
c=Counter(S)

ans=c['R']*c['G']*c['B']

for i in range(N):
  for j in range(i+1,N):
    if S[i]==S[j]:
      continue
    k=j*2-i
    if k>=N or S[k]==S[i] or S[k]==S[j]:
      continue
    ans-=1

print(ans)


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-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

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

ans = S.count("R") * S.count("G") * S.count("B")

for i in range(1,N-1):
  for j in range(i+1,N):
    k = 2 * j - i
    if k > N:
      break
    if S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[k-1] != S[i-1]:
      ans -= 1
      
print(ans)

n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")
rgb = r*g*b

for i in range(n-1):
  for j in range(i+1,n):
    k = 2*j-i
    if k > n-1 or s[i] == s[j] or s[i] == s[k] or s[j] == s[k]: continue
    rgb -= 1
print(rgb)

N = int(input())
S = input()
r, g, b =[], [], []
for idx, w in enumerate(S):
  if w == "R":
    r.append(idx+1)
  elif w=="G":
    g.append(idx+1)
  elif w=="B":
    b.append(idx+1)
if len(r)>=len(b) and len(r)>=len(g):
  L, M, S = r, g, b
elif len(b)>=len(r) and len(b)>=len(g):
  L, M, S = b, g, r
elif len(g)>=len(r) and len(g)>=len(b):
  L, M, S = g, r, b
L = set(L)
ans = len(S)*len(L)*len(M)
for s in S:
  for m in M:
    tmp = sorted([s, m])
    if (tmp[0] - (tmp[1]-tmp[0])) in L:
      ans -= 1
    if (tmp[1] + (tmp[1]-tmp[0])) in L:
      ans -= 1
    if (sum(tmp)/2) in L:
      ans -= 1
print(ans)

from collections import Counter

n=int(input())
s=input()
c=Counter(s)

ans=c['R']*c['G']*c['B']

lim=n//2
for i in range(1,n//2+1):
  for j in range(i,n-i):
    l=s[j-i]
    m=s[j]
    r=s[j+i]
    if l!=m and m!=r and r!=l:
      ans-=1

print(ans)

def main():
    n = int(input())
    s = input()
    # 条件1:全パターンはr*g*b
    r = s.count('R')
    g = s.count('G')
    b = s.count('B')
    # i, j, kの差が一致するもので条件1を満たすものを後から引く 
    cnt = 0
    # len(s)
    for i in range(n):
        for j in range(i+1, n):
                k = j + j - i
                if k >= n:
                    break
                if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                    cnt += 1
    ans = r*g*b - cnt
    print(ans)
    
def __starting_point():
    main()
__starting_point()

def main():
	N = int(input())
	S = list(input())
	R = []
	G = []
	B = []
	cnt = 0
	for i in range(len(S)):
		if S[i] == "R":
			R.append(i)
		elif S[i] == "G":
			G.append(i)
		elif S[i] == "B":
			B.append(i)
	l = len(B)
	for i in range(len(R)):
		r = R[i]
		for j in range(len(G)):
			g = G[j]
			cnt += l
			if g > r:
				M = g
				m = r
			elif r > g:
				M = r
				m = g
			d = M - m
			if (M + d) < N and S[M + d] == "B":
				cnt -= 1
			if (m - d) >= 0 and S[m - d] == "B":
				cnt -= 1
			if (M + m) % 2 == 0 and S[int((M + m) / 2)] == "B":
				cnt -= 1
	print(cnt)

main()

n=int(input())
S=list(input())
ans = S.count("R")*S.count("G")*S.count("B")
for i in range(n-2):
  for j in range(i+1,(n+i+1)//2):
    if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
      ans -= 1
print(ans)

def main():
    N = int(input())
    S = input()
    RGBdict = {"R":0,"G":0,"B":0}
    for i in range(N):
        RGBdict[S[i]] += 1

    if N%2 == 0:
        maxsa = (N//2) -1
    else:
        maxsa = N//2

    tmp = N - 2
    cnt = 0
    for j in range(maxsa+1):
        num = tmp-(j*2)
        for k in range( num ):
            if (S[N-num+k] != S[N-num+k-j-1]) and (S[N-num+k] != S[N-num+k-2*j-2]) and (S[N-num+k-j-1] != S[N-num+k-2*j-2]):
                cnt += 1

    ans = RGBdict["R"]*RGBdict["G"]*RGBdict["B"]
    ans -= cnt
    return ans

print((main()))


n = int(input())
s = input()

ans = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
print(ans)

def __starting_point():

    n = int(input())
    s = list(input())

    #それぞれの組み合わせ数を求める
    R = s.count("R")
    G = s.count("G")
    B = s.count("B")
    
    sm = R*G*B
    #print("組み合わせ数="+str(sm))
    
    #cond2の条件から
    #j-i = k-jの時のkを求める
    # k = 2j - i なので
    for i in range(n):
        for j in range(i+1,n):
            k = 2*j - i
            if k < n:
                #print(s[i],s[j],s[k])
                #等間隔の場合はsmから-1する
                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                    sm -= 1
    print(sm)

__starting_point()

N = int(input())
S = input()
r = 0
g = 0
b = 0
for i in range(N):
    if S[i] == "R":
        r += 1
    elif S[i] == "G":
        g += 1
    else:
        b += 1

ms = (N-3)//2
t = 0
for i in range(ms + 1):
    for j in range(N - (2*i + 3) + 1):
        if S[j] != S[j + i + 1] and S[j] != S[j + 2*i + 2] and S[j + i + 1] != S[j + 2*i + 2]:
            t += 1

print(r * g * b - t)

from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

n = int(input())
s = input()
r,g,b = [], [], []

for i in range(n):
    if s[i]=="R":
        r.append(i)
    elif s[i]=="G":
        g.append(i)
    elif s[i]=="B":
        b.append(i)
ans = len(r)*len(g)*len(b)

for i in range(n):
    for j in range(i+1,n):
        k = j + j-i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans -= 1
print(ans)

n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
  for j in range(i+1, n-1):
    if j - i > n - j - 1:
      break
    if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]:
      ans -= 1
print(ans)

def main():
    N = int(input())
    S = input()
    dict = {'R':0, 'B':0, 'G':0}
    for i in range(N):
        dict[S[i]] += 1
    ans = dict['R']*dict['B']*dict['G']
    for i in range(N-2):
        if (N-i)%2 == 0:
            tmp = int((N-i)/2)-1
        else:
            tmp = (N-i)//2
        for j in range(1,tmp+1):
            if S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
                ans = ans - 1

    return ans

print((main()))  


n = int(input())
s = input()
r = 0
g = 0
b = 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    else:
        b += 1
ans = r * g * b

for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if k >= n or s[k] == s[i] or s[k] == s[j]:
            continue
        ans -= 1
        
print(ans)

n=int(input())
S=list(input())
ans = S.count("R")*S.count("G")*S.count("B")
for i in range(n-2):
  for j in range(i+1,(n+i+1)//2):
    if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
      ans -= 1
print(ans)

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

r = S.count('R')
g = S.count('G')
b = S.count('B')

ans = r * g * b
for j in range(1, N):
    t = 1
    while j - t >= 0 and j + t <= N - 1:
        if S[j - t] != S[j] and S[j] != S[j + t] and S[j + t] != S[j - t]:
            ans -= 1
        t += 1

print(ans)
return