   program abc162dr
      implicit none
      integer::n
      character(len=4000)::s
      integer::i,j,k,ans
      integer::x(3)=0

         read *,n
         read *,s

         do i=1,n
            if (s(i:i)=='R') x(1)=x(1)+1
            if (s(i:i)=='G') x(2)=x(2)+1
            if (s(i:i)=='B') x(3)=x(3)+1
         end do

         ans=x(1)*x(2)*x(3)

         do i=1,n-2
           do j=i+1,n-1
              k=2*j-i
              if (k>n) cycle
              if ((s(i:i)/=s(j:j)) .and. (s(i:i)/=s(k:k)) &
                                  .and. (s(j:j)/=s(k:k))) then
                 ans=ans-1
              end if
           end do
         end do

         print *,ans

   end program abc162dr