program main
      implicit none
      integer(4) :: n, i, j, k, l
      integer(8) :: sumR, sumB, sumG
      integer(8) :: sum
      character(4000) :: s

      read *, n
      read *, s

      sumR = 0
      sumB = 0
      sumG = 0

      do i = 1, n
        if ( s(i:i) == 'R' ) sumR = sumR + 1
        if ( s(i:i) == 'B' ) sumB = sumB + 1
        if ( s(i:i) == 'G' ) sumG = sumG + 1
      end do
      sum = sumR*sumB*sumG

      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(j:j) /= s(k:k) ) .and. &
                ( s(i:i) /= s(k:k) ) ) then
                sum = sum - 1
          end if
        end do
      end do
      print *, sum

end program main
