
program main

implicit none

integer:: i, j, k, n, idx, pair, ierr
integer, allocatable:: counts(:,:)
logical:: flag
character(1):: c

read *, n
allocate( counts(1:26,1:n) )
counts(:,:)= 0

do i= 1, n
  do while( .true. )
    read(*,'(a1)',advance='no',iostat=ierr) c
    if( ierr/=0 ) exit
    idx= ichar(c) - 96
    counts(idx,i)= counts(idx,i) + 1
  end do
end do

pair= 0
do i= 1, n
  do j= i+1, n
     flag= .true.
     do k= 1, 26
       if( counts(k,i)/=counts(k,j) ) then
         flag = .false.
         exit
       end if
     end do
     if( flag ) pair= pair + 1
  end do
end do
print '(i0)', pair

end program
