program main
      implicit none
      integer(4) :: n, i, j, k
      integer(8) :: cnt
      character(4000) :: s

      read *, n
      read *, s

      cnt = 0
      do i = 1, n-2
        do j = i+1, n-1

          if ( s(i:i) /= s(j:j)) then
          else
            cycle
          end if

          do k = j+1, n
            if ( k == 2*j-i ) cycle

            if ( s(i:i) /= s(k:k) ) then
              if ( s(j:j) /= s(k:k) ) then
                cnt = cnt + 1
              end if
            end if
          end do
        end do
      end do

      print *, cnt

end program main
