program main
    implicit none
    integer n
    integer, dimension(4000) :: r, g, b
    integer i, j, k, ir, ig, ib
    integer nr, ng, nb, d1, d2
    integer c, d
    character s*4000
    read(*,*) n
    read(*,*) s

    do i = 1,4000
        r(i) = 0
        g(i) = 0
        b(i) = 0
    end do

    ir = 1
    ig = 1
    ib = 1

    do i = 1,n
        if(s(i:i) == "R") then
            r(ir) = i
            ir = ir + 1
        else if(s(i:i) == "G") then
            g(ig) = i
            ig = ig + 1
        else if(s(i:i) == "B") then
            b(ib) = i
            ib = ib + 1
        end if
    end do
    
    nr = ir - 1
    ng = ig - 1
    nb = ib - 1
    c = 0
    d = 0

    do ir = 1, nr
        do ig = 1, ng
            do ib = 1, nb
                i = min(r(ir),g(ig),b(ib))
                k = max(r(ir),g(ig),b(ib))
                j = r(ir) + g(ig) + b(ib) - i - k
                if((j-i) == (k-j)) then
                    d = d + 1
                end if
            end do
        end do
    end do
    write(*,*) nr*ng*nb - d

end program