module module_sort
   implicit none

contains
   subroutine sort(array)
      integer,intent(inout) :: array(1:10)
      integer :: i, j, memo

      do i = 1, 9
         do j = i+1, 10
            if (array(i) > array(j)) then
                memo = array(i)
                array(i) = array(j)
                array(j) = memo
            endif
         enddo
      enddo

   end subroutine sort

end module module_sort

program abc137c
   use module_sort

   implicit none
   character(len=10) :: foo, bar
   character(len=10), allocatable :: string(:)
   character(len=1), allocatable :: array(:,:)
   integer, allocatable :: ascii(:,:), sum_ascii(:)
   integer :: n, i, j, counter, memo(10)

   read(*,*) n
   allocate( string(n), array(n, 10), ascii(n,10), sum_ascii(n) )

   do i = 1, n
      read(*,fmt='(A10)') string(i)
   enddo


   do i = 1, 10
      do j = 1, n
         array(j, i) = string(j)(i:i)
         ascii(j, i) = iachar(array(j, i))
      enddo
   enddo

   counter = 0
   sum_ascii(:) =  sum(ascii(:,:), dim=2)   ! ASCII codeの合計値を出力
   do i = 1, n-1
      do j = i+1, n
         if (sum_ascii(i)==sum_ascii(j)) then
            ! call sort(ascii(i,:))
            ! call sort(ascii(j,:))
            ! if ( array_logical_conjunction(ascii(i,:), ascii(j,:)) )  then
            !    counter = counter + 1
            ! else
            !    cycle
            ! endif

            counter = counter + 1
         endif
      enddo
   enddo


   write(*,*) counter
   ! ! array test
   ! write(*, *) array(1, :)
   ! write(*, *) array(1, 4)

   ! ! read test
   ! write(*,*)
   ! do i = 1, n
   !    write(*, fmt='(A10)') string(i)
   ! enddo

contains

   logical function array_logical_conjunction(a1,a2) result(m)
      integer :: a1(:), a2(:)
      integer :: k
      logical :: flag = .true.

      do k = 1, 10
         if (a1(k) == a2(k)) then
            flag = .true. .and. flag
         else
            flag = .false.
            exit
         endif
      enddo

      m = flag
   end function array_logical_conjunction

end program
