program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64)::n,i,d,ans
    integer(int64)::nr(3)
    character(:),allocatable::s
    read*, n
    allocate(character(n):: s)
    read*, s
    nr(:) = 0
    do i=1,n
        if (s(i:i) == 'R') then
            nr(1)=nr(1)+1
        else if (s(i:i) == 'G') then
            nr(2)=nr(2)+1
        else
            nr(3)=nr(3)+1
        end if
    end do
    ans = product(nr)
    d=0

    do while(d < n)
        i=1
        do 
            if (i+2*d+2 > n) exit
            if (s(i:i) /= s(i+d+1:i+d+1) .and. s(i+d+1:i+d+1) /= s(i+2*d+2:i+2*d+2) .and. s(i+2*d+2:i+2*d+2) /= s(i:i)) then
                ans=ans-1
            end if
            i=i+1
        end do
        d=d+1
    end do

    print*, ans

end program name