# frozen_string_literal: true

_array_size = gets
strings = readlines.map(&:chomp)
sorted_string = strings.map do |string|
  string.chars.sort.join
end

puts sorted_string.group_by(&:itself).map { |_key, value| value.count }.inject(0) { |memo, e|
  case e
  when 1
    memo
  else
    memo + Array(1..(e - 1)).inject(&:+)
  end
}
