program ABC162D
    implicit none
    integer(8)::N,i,j,k,ans
    character(4000)::S
    read*,N,S
    ans=0

    do i=1,N-2
        do j=i+1,N-1
            do k=j+1,N
                if(S(i:i)/=S(j:j).and.S(j:j)/=S(k:k).and.S(i:i)/=S(k:k))then
                    if(j-i/=k-j)ans=ans+1
                end if
            end do
        end do
    end do

    print'(i0)',ans
end program ABC162D