program example
	implicit none

	integer(8) ::N,i,j,k,wa=0
    character(4000) S
    
    read(*,*) N
    read(*,*) S
    
    do i=1,N,1
    
    	do j=i+1,N,1
        
        	do k=j+1,N,1
                if(j-i==k-j) goto 1

            	if(S(i:i)/=S(j:j) .and. S(i:i)/=S(k:k) .and. S(k:k)/=S(j:j)) then
                	wa=wa+1
                end if
            1 end do

        end do
    end do
              
    write(*,*) wa

end program example
