program main
  implicit none
  integer(8) :: n, i, j, kng, cr(0:4000), cb(0:4000), cg(0:4000)
  integer(8) :: res
  character(4000) :: s
  character(2) :: sij
  character(1) :: cng

  read *, n
  read *, s
  cr = 0
  cb = 0
  cg = 0
  do i = 1, n
    cr(i) = cr(i - 1)
    cb(i) = cb(i - 1)
    cg(i) = cg(i - 1)
    if (s(i:i) == "R") then
      cr(i) = cr(i) + 1
    else if (s(i:i) == "G") then
      cg(i) = cg(i) + 1
    else
      cb(i) = cb(i) + 1
    end if
  end do
  res = 0
  do i = 1, n - 2
    do j = i + 1, n - 1
      if (s(i:i) == s(j:j)) cycle
      sij = s(i:i) // s(j:j)
      kng = j + j - i
      if (sij == "RG" .or. sij == "GR") then
        res = res + cb(n) - cb(j)
        cng = "B"
      else if (sij == "RB" .or. sij == "BR") then
        res = res + cg(n) - cg(j)
        cng = "G"
      else
        res = res + cr(n) - cr(j)
        cng = "R"
      end if
      if (kng <= n) then
        if (s(kng:kng) == cng) res = res - 1
      end if
    end do
  end do
  print "(i0)", res
end program main
