program ABC162_D
  character(4000)::S
  integer::R=0,G=0,B=0,A
  read(*,*)N
  read(*,*)S
  do i=1,N
     if(S(i:i)=='R') R=R+1
     if(S(i:i)=='G') G=G+1
     if(S(i:i)=='B') B=B+1
  end do
  A=R*G*B
  do i=1,N
     do j=1,N
        if(i+2*j>N) cycle
        if(S(i:i)/=S(i+j:i+j) .and. S(i+j:i+j)/=S(i+2*j:i+2*j) .and. S(i+2*j:i+2*j)/=S(i:i)) A=A-1
     end do
  end do
  write(*,*)A
end program ABC162_D