program main
    implicit none
    integer(8) N, i, ans, k, j
    integer(8) :: r = 0, b = 0, g = 0
    character S * 4000
    read(*, *) N, S
    do i = 1, N
        if (S(i:i) == "R") then
            r = r + 1
        else if (S(i:i) == "B") then
            b = b + 1
        else
            g = g + 1
        end if
    end do
    ans = r * b * g
    do i = 1, N - 2
        do j = i + 1, N - 1
            if (S(i:i) /= S(j:j)) then
                k = 2 * j - i
                if (k <= N .and. S(i:i) /= S(k:k) .and. S(j:j) /= S(k:k)) then
                    ans = ans - 1
                end if
            end if
        end do
    end do
    write(*, '(I0)') ans
    stop
contains
end program main