program test

integer :: n,i,j,k,ans=0,rgb(3,5000)=0,hoge=0,big=0,small=0
character(len=5000) :: s



read(*,*) n
read(*,*) s

do i=1,n
  if(s(i:i)=='R')then
    rgb(1,i:n) = rgb(1,i:n) + 1
  else if(s(i:i)=='G')then
    rgb(2,i:n) = rgb(2,i:n) + 1
  else if(s(i:i)=='B')then
    rgb(3,i:n) = rgb(3,i:n) + 1
  endif
enddo


if(n<=2)then
  ans = 0
else
  
  do j=2,n-1
    if(s(j:j) == 'R') then
      ans = ans + rgb(2,j-1)*(rgb(3,n)-rgb(3,j))
      ans = ans + rgb(3,j-1)*(rgb(2,n)-rgb(2,j))
      
      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='G' .and. s(big:big)=='B') .or. (s(small:small)=='B' .and. s(big:big)=='G')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo
      
    endif

    if(s(j:j) == 'G') then
      ans = ans + rgb(1,j-1)*(rgb(3,n)-rgb(3,j))
      ans = ans + rgb(3,j-1)*(rgb(1,n)-rgb(1,j))

      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='R' .and. s(big:big)=='B') .or. (s(small:small)=='B' .and. s(big:big)=='R')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo

    endif

    if(s(j:j) == 'B') then
      ans = ans + rgb(1,j-1)*(rgb(2,n)-rgb(2,j))
      ans = ans + rgb(2,j-1)*(rgb(1,n)-rgb(1,j))

      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='R' .and. s(big:big)=='G') .or. (s(small:small)=='G' .and. s(big:big)=='R')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo

    endif
    
  enddo
  
endif

write(*,*) ans

end