import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=foldr(+)0$map(f.length).group.sort.scanr(+)0$as
f i=i*(i-1)`div`2