Problem:
 Score : 400 points    Problem Statement 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 1 4
RRGB      Sample Output 1 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.       Sample Input 2 39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB      Sample Output 2 1800

Solution (Python):
N = int(input())
S = input()
s = list(S)
r = 0
g = 0
b = 0
for i in range(N):
    if s[i] == 'R':
        r = r + 1
    if s[i] == 'G':
        g = g + 1
    if s[i] == 'B':
        b = b + 1
p = 0
for i in range(N-1):
    for j in range(i+1,N):
        if 2*j-i < N:
            if s[2*j-i] == s[i] or s[2*j-i] == s[j] or s[i] == s[j]:
                p = p
            else:
                p = p+1
        else:
            break
print(r*g*b-p)

Solution (Python):
n = int(input())
s = input()

an = 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[i]!=s[k]):
                an -= 1

print(an)

Solution (Python):
import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

input = sys.stdin.readline


N = I()
S = input().rstrip()
R = S.count('R')
G = S.count('G')
B = N-R-G

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

Solution (Python):
n = int(input())
s = list(str(input()))


c = 0
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]:
            c = c+1
            
        

R = 0
G = 0
B = 0

for i in range(n):
    if s[i] == 'R':
        R = R+1
    elif s[i] == 'G':
        G = G+1
    elif s[i] == 'B':
        B = B+1

print(R*G*B-c)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
S = inputS()

r=0
g=0
b=0
for i in S:
  if i =="R":
    r+=1
  elif i =="G":
    g+=1
  else:
    b+=1

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

print(r*b*g-count)

Solution (Python):
n = int(input())
s = input()

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

minus = 0

for i in range(n):
    for j in range(i+1,n):
        k = 2*j - i
        if k >= n or j >= n:
            break
        if s[i] != s[j] and s[j]!= s[k] and s[i] != s[k]:
            minus += 1
            
            
print(r*g*b - minus)

Solution (Python):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Solution (Python):
n=int(input())
str=input()
count=str.count("R")*str.count("G")*str.count("B")
count0=0
for i in range(0,n-2):
    for j in range(i+1,int((n+i-1)/2)+1):
        k=2*j-i
        if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:
            count0=count0+1
print(count-count0)

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

Solution (Python):
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, i+(n-i-1)//2+1):
        k = 2*j-i
        if k < n and s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
            ans -= 1

print(ans)

Solution (Python):
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:
      break
    
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      ans -= 1
      
print(ans)

Solution (Python):
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):
    for j in range(i+1,N):
        k = 2*j - i
        if k >= N:
            break
        else:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
                ans -= 1

print(ans)

Solution (Python):
N = int(input())
S = input()

RGB = [list()] * 3
color = ['R', 'G', 'B']
RGB[0] = [i for i, s in enumerate(S) if s == color[0]]
RGB[1] = [i for i, s in enumerate(S) if s == color[1]]
RGB[2] = [i for i, s in enumerate(S) if s == color[2]]

order = sorted([0, 1, 2], key=lambda i: len(RGB[i]))
color = [color[i] for i in order]
RGB = [RGB[i] for i in order]


ans = len(RGB[0]) * len(RGB[1]) * len(RGB[2])
for c1 in RGB[0]:
    for c2 in RGB[1]:
        p = c1 * 2 - c2
        if 0 <= p and p < N and S[p] == color[2]:
            
            ans -= 1

        p = c2 * 2 - c1
        if 0 <= p and p < N and S[p] == color[2]:
            
            ans -= 1

        if (c1 + c2) % 2 == 0 and S[(c1 + c2) // 2] == color[2]:
            
            ans -= 1

print(ans)

Solution (Python):
n = int(input())
s = input()
c = s.count


ans = c("R")*c("G")*c("B")

for a in range(n-2):  
    for j in range((n-a+1)//2):  
        
        
        
        if s[a] != s[a+j] and s[a+j] != s[a+2*j] and s[a+2*j] != s[a]:
            ans -= 1
print(ans)

Solution (Python):
n = int(input())
s = list(input())
Rcount = 0
Gcount = 0
Bcount = 0
cnt = 0
for i in range(len(s)):
         if s[i] == "R":
                  Rcount += 1
         elif s[i] == "G":
                  Gcount += 1
         elif s[i] == "B":
                  Bcount += 1
RGB = Rcount * Gcount * Bcount
for i in range(1,(len(s)//2)+2):
         for j in range(len(s)):
                  if i * 2 + j >= len(s):
                           break
                  else:
                           if s[j] != s[j+i] and s[j+i] != s[j+i+i] and s[j+i+i] != s[j]:
                                    cnt += 1
print(RGB - cnt)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1
print(len(r) * len(g) * len(b) - count)

Solution (Python):
def D():
    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)
        else: b.append(i)
    ans = len(r)*len(g)*len(b)
    for i in range(n):
        for j in range(i,n):
            if j + (j-i) >= n: continue
            if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
    print(ans)

D()

Solution (Python):
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

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

print(ans)

Solution (Python):
N = int(input())
S = input()
r = 0
g = 0
b = 0
for s in S:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

ret = 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[j] != S[k] and S[k] != S[i]:
            ret -= 1

print(ret)

Solution (Python):
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B') 
for i in range(n): 
    if s[i]=='R':
        s[i]=1
    elif s[i]=='G':
        s[i] = 2
    elif s[i]=='B':
        s[i]=4
for i in range(n): 
    for j in range(i+1,n):
        k=2*j-i
        if k>=n: 
            continue
        if s[i]+s[j]+s[k]==7: 
            ans-=1
print(ans)

Solution (Python):
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, i+(n-i-1)//2+1):
        k = 2*j-i
        if k < n and s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
            ans -= 1

print(ans)

Solution (Python):
def main():
    import collections
    import sys
    sys.setrecursionlimit(5000000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        if len(c)<3:
            print(0)

        else:

            list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
            list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
            list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
            list23=[]

        
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = input()
rcnt = S.count('R')
gcnt = S.count('G')
bcnt = S.count('B')
ans = rcnt * gcnt * bcnt

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

Solution (Python):
N = int(input())
S = input()
rcnt = S.count('R')
gcnt = S.count('G')
bcnt = S.count('B')
ans = rcnt * gcnt * bcnt

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = str(sys.stdin.readline().rstrip())

R,G,B = 0,0,0

for c in S:
    if c == 'R':
        R+=1
    elif c == 'G':
        G+=1
    else:
        B+=1

ans = R*G*B

for j in range(N):
    for i in range(N):
        if j-i < 0 or j+i >= N:
            break
        elif S[j-i] != S[j] and S[j+i] != S[j] and S[j+i] != S[j-i]:
            ans-=1

print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = str(sys.stdin.readline().rstrip())

R,G,B = 0,0,0

for c in S:
    if c == 'R':
        R+=1
    elif c == 'G':
        G+=1
    else:
        B+=1

ans = R*G*B

for j in range(N):
    for i in range(N):
        if j-i < 0 or j+i >= N:
            break
        elif S[j-i] != S[j] and S[j+i] != S[j] and S[j+i] != S[j-i]:
            ans-=1

print(ans)

Solution (Python):
N = int(input())
S = input()

R = S.count('R')
G = S.count('G')
B = S.count('B')

A = 0
if R == 0 or G == 0 or B == 0 :
    print(A)
else:
    A = R*G*B
    for i in range((N-3)//2 +1):
        for j in range(N-3-2*i +1):
            if S[j] != S[j+i+1] and S[j+i+1] != S[j+2*i+2] and S[j+2*i+2] != S[j]:
                A -= 1
    print(A)

Solution (Python):
n = int(input())
s = list(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:
            continue

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

print(ans)

Solution (Python):
n = int(input())
s = list(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:
            continue

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

print(ans)

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

Solution (Python):
n = int(input())
s = list(input())

r, g, b = 0, 0, 0

for i in list(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):
        k = 2 * j - i

        if k >= n:
            continue

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

print(ans)

Solution (Python):
N = int(input())
S = input()
count = [0, 0, 0]

for s in S:
    if s == 'R': count[0] += 1
    elif s == 'G': count[1] += 1
    else: count[2] += 1

ans = count[0] * count[1] * count[2]

for j in range(N):
    for i in range(j):
        k = j + j-i
        
        if k < N:
            if S[i] == S[j]: continue
            if S[i] == S[k]: continue
            if S[k] == S[j]: continue
            ans -= 1
            
print(ans)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *




























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()
	S = input()
	S = S[:-1]

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

	for i,val in enumerate(S):
		if val == "R":
			R.append(i)
		elif val == "G":
			G.append(i)
		else:
			B.append(i)

	maxs = len(R) * len(G) * len(B)

	tmp = 0
	for i in range(N):
		for skip in range(0, -(-N // 2)):
			if i+skip+skip >= len(S):
				break
			I = S[i]
			J = S[i+skip]
			K = S[i+skip+skip]

			if I != J and I != K and J != K:
				tmp += 1

	print(maxs-tmp)
	





def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Solution (Python):
N = int(input())
S = input()

if N == 1 or N == 2:
    ans = 0
else:
    R = S.count('R')
    G = S.count('G')
    B = S.count('B')
    rgb = R * G * B

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

print(ans)

Solution (Python):
n = int(input())
if n < 3:
  print(0)
else:
  s = str(input())
  r = 0
  g = 0
  b = 0
  for i in 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 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)

Solution (Python):
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

ans = r * g * b

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

print(ans)

Solution (Python):
N = int(input()) 
S = list(input())

R_index = list()
G_index = list()
B_index = list()

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








ans = len(R_index)*len(G_index)*len(B_index) 
B_set = set(B_index)


for R in R_index:
    for G in G_index:
        
        
        if (R+G)/2 in B_set:
            ans -= 1
        if 2*G-R in B_set:
            ans -= 1
        if  2*R-G in B_set:
            ans -= 1
        
print(ans)

Solution (Python):
N = int(input()) 
S = list(input())

R_index = list()
G_index = list()
B_index = list()

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








ans = len(R_index)*len(G_index)*len(B_index) 
B_set = set(B_index)


for R in R_index:
    for G in G_index:
        
        
        if (R+G)/2 in B_set:
            ans -= 1
        if 2*G-R in B_set:
            ans -= 1
        if  2*R-G in B_set:
            ans -= 1
        
print(ans)

Solution (Python):
n = int(input())
s = input()

a = [0] * n
for i in range(n):
    if s[i] == 'R': a[i] = 0
    if s[i] == 'G': a[i] = 1
    if s[i] == 'B': a[i] = 2

cnt = [0] * 3
for i in range(n):
    cnt[a[i]] += 1
    
ans = 1
for i in range(3):
    ans *= cnt[i]


for j in range(n):
    for i in range(j):
        k = j + (j - i)
        if k < n:
            if a[i] == a[j]: continue
            if a[i] == a[k]: continue
            if a[k] == a[j]: continue
            ans -= 1
            
print(ans)

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

Solution (Python):
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 = i + 2*d
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1
print(len(r) * len(g) * len(b) - count)

Solution (Python):
from numba import njit
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = np.array(list(readline().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    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[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit

MOD = 10**9 + 7

N = int(readline())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))

@njit
def f(S):
    N = len(S)
    ret = 0
    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[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret

answer = R * B * G - f(S)
print(answer)

Solution (Python):
n = int(input())
s = input()

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

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

Solution (Python):
import copy
import collections
def f(s):
    h = {('R','G'): 'B', ('B','G'): 'R', ('R','B'): 'G',('R','G')[::-1]: 'B', ('B','G')[::-1]: 'R', ('R','B')[::-1]: 'G', }
    c = collections.Counter()
    cc = [None] * (len(s)+1)
    cc[-1] = copy.deepcopy(c)
    for jj in range(len(s)-1,-1,-1):
        c[s[jj]]+=1
        cc[jj] = copy.deepcopy(c)


    res = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if s[j] != s[i]:
                res += cc[j+1][h[(s[i],s[j])]] 
                
                k = j + (j - i)
                if k < len(s) and s[k] == h[(s[i],s[j])]:
                    res -=1
    return res
raw_input()
print f(raw_input())

Solution (Python):

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

c = collections.Counter(s)
total = c['R'] * c['G'] * c['B']
tmp = 0

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

Solution (Python):


import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

n = int(readline())
s = list(readline().rstrip())

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

count = r * g * b
for i in range(n):
    for j in range(1, min(i + 1, n - i)):
        if s[i - j] != s[i] and s[i] != s[i + j] and s[i - j] != s[i + j]:
            count -= 1

print(count)

Solution (Python):


import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

n = int(readline())
s = list(readline().rstrip())

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

count = r * g * b
for i in range(n):
    for j in range(1, min(i + 1, n - i)):
        if s[i - j] != s[i] and s[i] != s[i + j] and s[i - j] != s[i + j]:
            count -= 1

print(count)

Solution (Python):
n=int(input())
S=list(input())
C=[0]*3
for i in range(n):
  if S[i]=="R":
    C[0]+=1
  elif S[i]=="G":
    C[1]+=1
  else:
    C[2]+=1
b=C[0]*C[1]*C[2]
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j*2-i
    if k>=n:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      a=a+1
print(b-a)

Solution (Python):
n, s = int(input()), input()
a = ["R", "G", "B"]
cnt = [0, 0, 0]
for i in s:
    cnt[a.index(i)] += 1
c = cnt[0] * cnt[1] * cnt[2]
for i in range(1, n-1):
    for j in range(i+1, n):
        k = 2 * j - i
        if j-1 < k-1 < n:
            if s[i-1] != s[j-1] and s[j-1] != s[k-1] and s[k-1] != s[i-1]:
                c -= 1

print(c)

Solution (Python):
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(1,(n+1)//2):
    j = 0
    while j + 2*i <= n-1:
        if len(set(s[j]+s[j+i]+s[j+2*i])) == 3:
            ans -= 1
        j += 1
print(ans)

Solution (Python):

def resolve():
    N=int(input())
    S=input()
    RGB=[0,0,0]
    subcnt=0
    for i,c in enumerate(S):
        if c=="R":RGB[0]+=1
        if c=="G":RGB[1]+=1
        if c=="B":RGB[2]+=1
            
        for j in range(i+1,N):
            s=S[j]
            k=j*2-i
            if k<N :
                x=S[k]
                if   x!=s and s!=c and x!=c :
                    
                    
                    subcnt+=1
            else:break

    
    A=RGB[0]*RGB[1]*RGB[2]
    print(A-subcnt)
            

resolve()

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

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

print(sum)

Solution (Python):
N = int(input())
S = input()
counter = {'R':0, 'G':0, 'B':0}
for s in S:
    counter[s] += 1

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

Solution (Python):
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  if s[i] =="R":
    s[i]=1
  elif s[i] =="G":
    s[i]=2
  elif s[i] =="B":
    s[i]=4
for i in range(n):
  for j in range(i+1,n):

    k=2*j-i
    if k>= n:
      continue
    if s[i]+s[j]+s[k]==7:
      ans -=1
print (ans)

Solution (Python):
from math import floor
n=int(input())
s=input()
r=0
g=0
b=0
for i in range (len(s)):
  if s[i]=='R':
    r+=1
  elif s[i]=='B':
    b+=1
  else:
    g+=1
c=0
for i in range(n - 2):
    for k in range(i + 2, n):
        if ( i + k ) % 2 != 0:
            continue
        j = ( i + k ) // 2
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            c += 1
 
      
ans=r*g*b-c;
print(ans)

Solution (Python):
n = int(input())
s = str(input())
r = []
g = []
def right(r,g):
    return (max(r,g)+(abs(r-g)))
def left(r,g):
    return (min(r,g)-(abs(r-g)))
def half(r,g):
    return ((r+g)//2)
for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
ans = len(r)*len(g)*(n-(len(r)+len(g)))
for i in range(len(r)):
    for j in range(len(g)):
        t = left(r[i],g[j])
        f = right(r[i],g[j])
        h = half(r[i],g[j])
        if f < n:
            if s[f] == "B":
                ans -= 1
        if 0 <= t:
            if s[t] == "B":
                ans -= 1
        if abs(r[i]-g[j])%2 == 0:
            if s[h] == "B":
                ans -= 1
print(ans)

Solution (Python):
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        Rsize+=1
    elif S[i] == "G":
        Gsize+=1
    elif S[i] == "B":
        Bsize+=1
counter = Rsize*Gsize*Bsize
for i in range(0,N-1,1):
    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[i]!=S[k]:
                counter -=1
print(counter)

Solution (Python):
n = int( input() )
s = list( 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) 

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

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

Solution (Python):
N = int(input())
string = input()
 
result = string.count('R')*string.count('G')*string.count('B')
 
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j-i
    if k>=N:
      break
    if string[i] != string[j] and string[j] != string[k] and string[i] != string[k]:
      result -= 1
print(result)

Solution (Python):
N = int(input())
S = input()

U = 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:
            break
        elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            U -= 1
print(U)