Language: C

from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

## return prime factors of N as dictionary {prime p:power of p}
## within 2 sec for N = 2*10**20+7
def primeFactor(N):
    i,n=2,N
    ret={}
    d,sq=2,99
    while i<=sq:
        k=0
        while n%i==0:
            n,k,ret[i]=n//i,k+1,k+1
        if k>0 or i==97:
            sq=int(n**(1/2)+0.5)
        if i<4:
            i=i*2-1
        else:
            i,d=i+d,d^6
    if n>1:
        ret[n]=1
    return ret


## return the list of prime numbers in [2,N], using eratosthenes sieve
## within 2sec for N = 1.2*10**7
def PrimeNumSet(N):
    Max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList:
        if seachList[0] <= Max:
            break
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

## retrun LCM of numbers in list b
## within 2sec for no of B = 10*5  and  Bi < 10**6
def LCM(b,mo=10**9+7):
    prs=PrimeNumSet(max(b))
    M=dict(zip(prs,[0]*len(prs)))
    for i in b:
        dc=primeFactor(i)
        for j,k in dc.items():
            M[j]=max(M[j],k)
    
    r=1
    for j,k in M.items():
        if k!=0:
            r*=pow(j,k,mo)
            r%=mo
    return r

show_flg=False
show_flg=True

'''
#C
g=[[1]*201 for i in range(201)]
for a in range(1,201):
    for b in range(1,201):
        g[a][b]=math.gcd(a,b)

k=I()
ans=0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=g[a][g[b][c]]
         
print(ans)
'''


#D
n=I()
s=input()
A=[[0],[0],[0]]
for i in range(n):
    w=s[i]
    A[0].append(A[0][-1]+(w=='R'))
    A[1].append(A[1][-1]+(w=='G'))
    A[2].append(A[2][-1]+(w=='B'))

#show(A)
t='RGB'

a=0
for i in range(1,n-1):
    w=s[i]
    if w=='R':
        j,k=1,2
    elif w=='G':
        j,k=0,2
    elif w=='B':
        j,k=0,1

    a+=A[j][i]*(A[k][n]-A[k][i])
    a+=A[k][i]*(A[j][n]-A[j][i])
    for l in range(i):
        if i+i-l>=n:
            continue
        if set([s[l],s[i+i-l]])==set([t[j],t[k]]):
            a-=1

print(a)

Compiler output:
main.c:1:1: error: unknown type name 'from'
    1 | from heapq import heappush,heappop,heapify
      | ^~~~
main.c:1:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'import'
    1 | from heapq import heappush,heappop,heapify
      |            ^~~~~~
main.c:1:12: error: unknown type name 'import'
main.c:16:21: error: empty character constant
   16 | def LtoS(ls):return ''.join([chr(i+97) for i in ls])
      |                     ^~
main.c:18:16: warning: data definition has no type or storage class
   18 |     org_inp=[];g=[[] for i in range(n)]
      |                ^
main.c:18:16: error: type defaults to 'int' in declaration of 'g' [-Wimplicit-int]
main.c:18:18: error: expected expression before '[' token
   18 |     org_inp=[];g=[[] for i in range(n)]
      |                  ^
main.c:19:5: error: expected ',' or ';' before 'for'
   19 |     for i in range(E):
      |     ^~~
main.c:20:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
   20 |         inp=LI();org_inp.append(inp)
      |                         ^
main.c:21:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before '-=' token
   21 |         if index==0:inp[0]-=1;inp[1]-=1
      |                                     ^~
main.c:23:23: error: 'a' undeclared here (not in a function)
   23 |             a,b=inp;g[a].append(b)
      |                       ^
main.c:23:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
   23 |             a,b=inp;g[a].append(b)
      |                         ^
main.c:26:23: warning: data definition has no type or storage class
   26 |             a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
      |                       ^~
main.c:26:23: error: type defaults to 'int' in declaration of 'aa' [-Wimplicit-int]
main.c:26:27: error: 'inp' undeclared here (not in a function); did you mean 'int'?
   26 |             a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
      |                           ^~~
      |                           int
main.c:26:42: warning: data definition has no type or storage class
   26 |             a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
      |                                          ^~
main.c:26:42: error: type defaults to 'int' in declaration of 'bb' [-Wimplicit-int]
main.c:26:65: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
   26 |             a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
      |                                                                 ^
main.c:29:79: error: expected identifier or '(' before ')' token
   29 | def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
      |                                                                               ^
main.c:30:2: error: invalid preprocessing directive #h
   30 | #h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
      |  ^
main.c:31:25: warning: data definition has no type or storage class
   31 |     mp=[boundary]*(w+2);found={}
      |                         ^~~~~
main.c:31:25: error: type defaults to 'int' in declaration of 'found' [-Wimplicit-int]
main.c:32:5: error: expected ',' or ';' before 'for'
   32 |     for i in range(h):
      |     ^~~
main.c:48:5: warning: multi-character character constant [-Wmultichar]
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |     ^~~~~
main.c:48:11: warning: multi-character character constant [-Wmultichar]
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |           ^~~~
main.c:48:17: warning: data definition has no type or storage class
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |                 ^~
main.c:48:17: error: type defaults to 'int' in declaration of 'Yn' [-Wimplicit-int]
main.c:48:20: error: expected expression before '[' token
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |                    ^
main.c:48:21: warning: multi-character character constant [-Wmultichar]
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |                     ^~~~~
main.c:48:27: warning: multi-character character constant [-Wmultichar]
   48 | YN=['YES','NO'];Yn=['Yes','No']
      |                           ^~~~
main.c:50:11: warning: multi-character character constant [-Wmultichar]
   50 | inf=float('inf')
      |           ^~~~~
main.c:52:2: error: invalid preprocessing directive #sys
   52 | #sys.setrecursionlimit(10**7)
      |  ^~~
main.c:55:1: error: stray '##' in program
   55 | ## return prime factors of N as dictionary {prime p:power of p}
      | ^~
main.c:56:1: error: stray '##' in program
   56 | ## within 2 sec for N = 2*10**20+7
      | ^~
main.c:56:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before numeric constant
   56 | ## within 2 sec for N = 2*10**20+7
      |           ^
main.c:60:5: warning: data definition has no type or storage class
   60 |     d,sq=2,99
      |     ^
main.c:60:5: error: type defaults to 'int' in declaration of 'd' [-Wimplicit-int]
main.c:60:7: error: type defaults to 'int' in declaration of 'sq' [-Wimplicit-int]
   60 |     d,sq=2,99
      |       ^~
main.c:60:12: error: expected identifier or '(' before numeric constant
   60 |     d,sq=2,99
      |            ^~
main.c:76:1: error: stray '##' in program
   76 | ## return the list of prime numbers in [2,N], using eratosthenes sieve
      | ^~
main.c:77:1: error: stray '##' in program
   77 | ## within 2sec for N = 1.2*10**7
      | ^~
main.c:77:11: error: invalid suffix "sec" on integer constant
   77 | ## within 2sec for N = 1.2*10**7
      |           ^~~~
main.c:91:1: error: stray '##' in program
   91 | ## retrun LCM of numbers in list b
      | ^~
main.c:92:1: error: stray '##' in program
   92 | ## within 2sec for no of B = 10*5  and  Bi < 10**6
      | ^~
main.c:92:11: error: invalid suffix "sec" on integer constant
   92 | ## within 2sec for no of B = 10*5  and  Bi < 10**6
      |           ^~~~
main.c:111:1: error: empty character constant
  111 | '''
      | ^~
main.c:111:3: warning: missing terminating ' character
  111 | '''
      |   ^
main.c:111:3: error: missing terminating ' character
main.c:112:2: error: invalid preprocessing directive #C
  112 | #C
      |  ^
main.c:126:1: error: empty character constant
  126 | '''
      | ^~
main.c:126:3: warning: missing terminating ' character
  126 | '''
      |   ^
main.c:126:3: error: missing terminating ' character
main.c:129:2: error: invalid preprocessing directive #D
  129 | #D
      |  ^
main.c:139:2: error: invalid preprocessing directive #show
  139 | #show(A)
      |  ^~~~
main.c:140:3: warning: multi-character character constant [-Wmultichar]
  140 | t='RGB'
      |   ^~~~~