UVa 11076 - Add Again

Summary
Summation of sequence of integers is always a common problem in Computer Science. Rather than computing blindly, some intelligent techniques make the task simpler. Here you have to find the summation of a sequence of integers. The sequence is an interesting one and it is the all possible permutations of a given set of digits. For example, if the digits are, then six possible permutations are ,, , , , and the sum of them is 1332.

Explanation
http://pavelsimo.blogspot.com/2012/11/uva-11076-add-again.html

Gotchas
Brute Force Approach will fail with TLE.

Implementations
Notes/Hints on actual implementation here.

Optimizations
Optimizations here.

Input
3 1 2 3 3 1 1 2 0

Output
1332 444