program dm
    implicit none
    integer::N
    character(4000)::S
    
    integer(16)::ANS=0

    integer::i,j
    logical,allocatable,dimension(:)::R,G,B
    integer(16)::cntR=0,cntG=0,cntB=0
    read*,N
    read*,S
    allocate(R(N),G(N),B(N))

    R=.false.
    G=.false.
    B=.false.

    do i=1,N
        if(S(i:i)=="R")then
            R(i)=.true.;cntR=cntR+1
        endif
        if(S(i:i)=="G")then
            G(i)=.true.;cntG=cntG+1
        endif
        if(S(i:i)=="B")then
            B(i)=.true.;cntB=cntB+1
        endif
    end do
    !RGB
    do i=1,N
        if(R(i))then
            do j=i+1,N
                if(G(j))then
                    if(2*j-i<=N)then
                        if(B(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do
    !RBG
    do i=1,N
        if(R(i))then
            do j=i+1,N
                if(B(j))then
                    if(2*j-i<=N)then
                        if(G(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do
    !GRB
    do i=1,N
        if(G(i))then
            do j=i+1,N
                if(R(j))then
                    if(2*j-i<=N)then
                        if(B(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do
    !GBR
    do i=1,N
        if(G(i))then
            do j=i+1,N
                if(B(j))then
                    if(2*j-i<=N)then
                        if(R(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do

    do i=1,N
        if(B(i))then
            do j=i+1,N
                if(R(j))then
                    if(2*j-i<=N)then
                        if(G(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do
    do i=1,N
        if(B(i))then
            do j=i+1,N
                if(G(j))then
                    if(2*j-i<=N)then
                        if(R(2*j-i))then
                            ANS=ANS+1
                        endif
                    endif
                endif
            end do
        endif
    end do
    print"(i0)",cntR*cntG*cntB-ANS
contains
end program dm