#K89177. Sum of Integers with the Same Digit Set

    ID: 37473 Type: Default 1000ms 256MiB

Sum of Integers with the Same Digit Set

Sum of Integers with the Same Digit Set

You are given a list of non-negative integers. For each integer in the list, you need to compute the sum of all integers in the list that have exactly the same set of digits in their decimal representation (order does not matter). For example, the numbers 123, 321, and 213 all share the same set of digits, so for each of them, you will output their total sum.

More formally, for each number \(a_i\) in the list, define its digit key as the sorted string of its digits. Then, the answer for \(a_i\) is the sum of all \(a_j\) such that the digit key of \(a_j\) is equal to the digit key of \(a_i\).

Input Example: 4 123 321 213 456 Output: 657 657 657 456

Your task is to compute and print the desired output for each number.

inputFormat

The first line of input contains a single integer \(n\) which denotes the number of integers.

The second line contains \(n\) space-separated integers.

outputFormat

Output \(n\) lines, each containing the result corresponding to the input integer in the same order as the input. Each result is the sum of all numbers that share the same set of digits in their decimal representation.

## sample
4
123 321 213 456
657

657 657 456

</p>