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
            if(S(i:i)==S(j:j)) goto 2
        	do k=j+1,N,1
                if(j-i==k-j) goto 1

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

        2 end do
    end do
              
    write(*,*) wa

end program example
