Problem:
Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.

Solution in Haskell (GHC 7.10.3) (judge verdict: Time Limit Exceeded)

{-# LANGUAGE BangPatterns #-}
module Main (main) where

import Control.Monad
-- import Control.Monad.Trans.State
import Data.ByteString (ByteString)
-- import qualified Data.ByteString.Unsafe as B
import qualified Data.ByteString.Char8 as C8
import Data.Bool
-- import Data.Bits
-- import Data.Char
import Data.List
import Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  xs <- replicateM n readStrings
  print . showAnswer . solve $ concat xs

type Output = Int

solve :: [String] -> Output
solve = g . map sort
  where
    g [] = 0
    g (x:xs) = length (filter (==x) xs) + g xs

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | ByteString ByteString
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)       = bool "No" "Yes"  b
  show (YESNO b)       = bool "NO" "YES"  b
  show (AB b)          = bool "B"  "A"    b
  show (Number i)      = show i
  show (String s)      = s
  show (ByteString bs) = C8.unpack bs
  show (Compare o)     = ordering "<" "=" ">" o
  show (Compare2 o)    = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

-- | k 番目の文字に関数 f を適用する
indexMapBS :: Int -> (Char -> Char) -> ByteString -> ByteString
indexMapBS k f s = C8.concat [s1, C8.singleton (f c), s3]
  where
    (s1, s2) = C8.splitAt (k-1) s
    c = C8.head s2
    s3 = C8.tail s2