program main
  
  implicit none
  integer :: n, i, j, nr, ng, nb
  integer :: ans
  character(4000) :: s
  
  read(*,*) n
  read(*,*) s
  
  nr = 0
  ng = 0
  nb = 0
  do i = 1, n
    if( s(i:i) == "R" ) then
      nr = nr + 1
    else if( s(i:i) == "G" ) then
      ng = ng + 1
    else
      nb = nb + 1
    end if
  end do
  ans = nr * ng * nb
  do i = 1, n-2
    do j = i+1, n-1
    if( s(i:i) == "R" ) then
      if( s(j:j) == "G" ) then
        if( s(2*j-i:2*j-i) == "B") ans = ans - 1
      end if
    end if
    if( s(i:i) == "R" ) then
      if( s(j:j) == "B" ) then
        if( s(2*j-i:2*j-i) == "G") ans = ans - 1
      end if
    end if
    if( s(i:i) == "G" ) then
      if( s(j:j) == "R" ) then
        if( s(2*j-i:2*j-i) == "B") ans = ans - 1
      end if
    end if
    if( s(i:i) == "G" ) then
      if( s(j:j) == "B" ) then
        if( s(2*j-i:2*j-i) == "R") ans = ans - 1
      end if
    end if
    if( s(i:i) == "B" ) then
      if( s(j:j) == "R" ) then
        if( s(2*j-i:2*j-i) == "G") ans = ans - 1
      end if
    end if
    if( s(i:i) == "B" ) then
      if( s(j:j) == "G" ) then
        if( s(2*j-i:2*j-i) == "R") ans = ans - 1
      end if
    end if
    end do
  end do

  print*, ans 

end program main
