Submit | All submissions | Best solutions | Back to list |
ADADIGIT - Ada and Digits 2 |
Ada the Ladybug likes numbers. Her friends know it so they wanted to give her a number as a gift. Sadly, they bought the number in IKEA so Ada has to assemble the number by herself. Now she is in following situation - she has a few digits before herself and she is wondering what number she will create. As she doesn't understand the manual (it is in Swedish) she has possibility to assemble anything.
She is not sure yet, anyway her favourite options are to assemble number with the most divisors or the number with the biggest sum of divisors. Can you help her to find such?
NOTE: To assemble number from digits, simply choose any permutation of digits. Leading zeroes are perfectly OK but you have to use all the digits.
Input
The first line of each test-case will contain an integer 1 ≤ N ≤ 9, the number of digits to assemble.
The next line will contain N digits 0 ≤ di ≤ 9 .
Output
Output two integers - the number with the most divisors AND the number with biggest sum of divisors. In case there are multiple such numbers, choose the lesser one. As long as you would use leading zeroes, output the number without the leading zeroes.
Example Input
1 5
Example Output
5 5
Example Input
3 1 1 0
Example Output
110 110
Example Input
2 3 4
Example Output
34 34
Example Input
5 1 2 3 4 5
Example Output
43512 51324
Example Input
6 2 2 3 3 4 4
Example Output
432432 432432
Example Input
3 4 8 2
Example Output
248 824
Example Input
4 1 3 5 7
Example Output
7315 7315
Example Input
7 1 2 3 4 5 6 7
Example Output
3124576 7516432
Added by: | Morass |
Date: | 2017-10-08 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Tunisian Collegiate Training Contest - Round #01 |
hide comments
2020-06-10 09:02:38
how some people are getting AC in .16 sec without using extra memory, is there some trick or what??? |
|
2017-12-15 21:26:09
+1 Last edit: 2017-12-15 21:26:21 |
|
2017-10-10 11:03:20
@Sushovan Sen: Sure ^_^ Now you shall not be confused :)) |
|
2017-10-10 10:29:30 Sushovan Sen
There exists a different problem with same name in spoj. Better if you change the name to avoid confusion. |