      PROGRAM piyo
      IMPLICIT NONE
      character(4000) :: s
      integer(16) :: numR(1:4000)=0,numG(1:4000)=0,numB(1:4000)=0
      integer(16) :: rgb(3)=0,i,j,n,ans=0,notK
      
      read*,n
      read*,s(1:n)
      
      if( s(1:1)=='R' )then
          numR(1) = 1
      else if( s(1:1)=='G' )then
          numG(1) = 1
      else
          numB(1) = 1
      endif
      
      rgb(1:3) = 0
      do i = 2,n
        if( s(i:i)=='R' )then
          rgb(1) = 1
        else if( s(i:i)=='G' )then
          rgb(2) = 1
        else
          rgb(3) = 1
        end if
        
        numR(i) = numR(i-1) + rgb(1)
        numG(i) = numG(i-1) + rgb(2)
        numB(i) = numB(i-1) + rgb(3)
        rgb = 0
      end do
      
      ans = numR(n) * numG(n) * numB(n)
      
      do i = 1,n-2
        do j = i+1,n-1
          
          notK = 2*j-i
          if( notK>n ) cycle
          
          if( s(i:i)/=s(j:j) .and. s(j:j)/=s(notK:notK) .and. &
              s(i:i)/=s(notK:notK) )then
            ans = ans - 1
          end if
          
        end do
      end do
      
      
      print*,ans
      
      !debugg
  !    print*,numR(1:n)
  !    print*,numG(1:n)
  !    print*,numB(1:n)
      
      
      END PROGRAM