program main
    implicit none
    integer n, i, j, k
    integer :: count = 0
    character(:), allocatable :: s

    read *, n
    allocate( character(n) :: s)

    read *, s

    do i=1, n-3
        do j=i+1, n-1
            do k=j+1, n
                if ( s(i:i) /= s(j:j) .and. s(i:i) /= s(k:k) .and. s(j:j) /= s(k:k) .and. j-i /= k-j) then
                    count = count + 1
                endif
            enddo
        enddo
    enddo
    print *, count
    end program main
