#K15001. Character Frequency Score

    ID: 24259 Type: Default 1000ms 256MiB

Character Frequency Score

Character Frequency Score

You are given a string s consisting of lowercase alphabetic characters. For each unique character, its contribution to the score is the square of its frequency in the string. In mathematical notation, if a character c appears f(c) times, then its contribution is (f(c)^2). The total score of the string is given by:

[ Score = \sum_{c \in unique(s)} (f(c))^2 ]

Given multiple test cases, where each test case is represented by a single string, compute and output the score for each string.

inputFormat

The first line contains an integer T, representing the number of test cases. Each of the following T lines contains a string s consisting of lowercase alphabetic characters. Note that s may be empty.

outputFormat

Output T lines. The i-th line should contain a single integer representing the score of the i-th test case.## sample

3
aab
aaa
abc
5

9 3

</p>