Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.
Problem hidden on 2013-03-18 18:50:01 by :D

SUMNOS - Sum of Numbers

Rajeev is a student of high school. He is weak in maths. Once his teacher gave him some digits and asks him to calculate the sum of all distinct 4 digit numbers that can be formed using these digits (if possible). Since he is weak in maths, he needs your help.

Input

First line contains an integer t, number of testcases. (t<10^9).

t lines follow each contain a sequence of digits.

Output

t lines each containing the expected sum if possible otherwise print "0".

Example

Input:
3
1 2 3 4
5 6 7 8 9
1 2 3

Output: 66660
933240
0

Added by:Shashank Tandon
Date:2013-03-18
Time limit:0.5s
Source limit:500B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2013-03-18 18:08:54 :D
I can help you with this new version I described. Please contact me via email and I'll write you a sample solution and help with generating test data.
2013-03-18 18:07:50 :D
I have a few issues with test data:

1) I don't believe T is almost equal to 10^9 and your program can solve it in 0.5s. Please put an actual limit there.

2) It's better to have a counter for number of digits than to rely on end-of-line. It's really less bug prone for both solutions and test files.

3) You don't specify if digits are distinct. It would really be much more interesting if they weren't.

4) I agree time limit should block brute force, but don't make it less than 1s. Instead of having 4-digit numbers, make it D-digit, where D is an input parameter. We could deal with bignums by requesting solution modulo some M.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.