
class Integer
  def factorial
    (1..self).inject(1,:*)
  end
  alias :! :factorial
end

h = Hash.new do |hash, key|
  hash[key] = 0 
end

a = gets.to_i
a.times do
  s = gets.chomp
  s = s.chars.sort.join

  h[s] += 1
end

ans = 0
h.each_pair do |key, value|
  if value > 0
    ans += (value.! / (2 * (value - 2).!))
    p key , value, ans
  end
end

p ans 
