program rgb_triplets
  implicit none
  integer :: n, i, j, a(4000) = 0, p, q
  integer(8) :: c(3) = 0_8, x = 0_8
  character(4000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, n
    if (s(i:i) == "R") then
      a(i) = 1
    else if (s(i:i) == "G") then
      a(i) = 2
    else
      a(i) = 3
    end if
    c(a(i)) = c(a(i))+1_8
  end do
  x = c(1)*c(2)*c(3)
  do j = 1, n
    do i = 1, n
      p = i+j
      q = p+j
      if (q > n) exit
      if (a(i) == a(p) .or. a(p) == a(q) .or. a(q) == a(i)) cycle
      x = x-1_8
    end do
  end do
  write(*,'(i0)') x
end program rgb_triplets