module a
  integer(8), allocatable :: anr(:), ang(:), anb(:)
end module a

program main
  use a
  
  implicit none
  integer :: n, i, j
  integer(8) :: ans ,nr, ng, nb
  character(4000) :: s
  
  read(*,*) n
  allocate( anr(n) )
  allocate( ang(n) )
  allocate( anb(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
  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
    anr(i) = nr
    ang(i) = ng
    anb(i) = nb
  end do
  ans = 0
  do i = 1, n-2
    do j = i+1, n-1
    if( s(i:i) == "R" ) then
      if( s(j:j) == "G" ) then
        ans = ans + anb(j) 
        if( 2*j-i > n ) cycle
        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
        ans = ans + ang(j) 
        if( 2*j-i > n ) cycle
        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
        ans = ans + anb(j) 
        if( 2*j-i > n ) cycle
        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
        ans = ans + anr(j) 
        if( 2*j-i > n ) cycle
        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
        ans = ans + ang(j) 
        if( 2*j-i > n ) cycle
        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
        ans = ans + anr(j) 
        if( 2*j-i > n ) cycle
        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

