program abc162d
   implicit none
   integer :: N, i, j, k
   character(4000) :: str
   character, allocatable :: S(:)
   integer :: count


   read(*,*) N
   read(*,*) str

   allocate(S(N))

   do i = 1, N
      S(i) = str(i:i)
   enddo

   print *, S(:)

   count = 0
   do k = 3, N
      do j = 2, k-1
         do i = 1, j-1
            if (S(i).ne.S(j) .and. S(i).ne.S(k) .and. S(j).ne.S(k)) then
               if (j-i .ne. k-j) count= count + 1
            endif
         enddo
      enddo
   enddo

   print *, count


end program abc162d
