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 testcase will contain an integer 1 ≤ N ≤ 9, the number of digits to assemble.
The next line will contain N digits 0 ≤ d_{i} ≤ 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
hide comments
sas1905:
20171013 11:51:54
Last edit: 20171013 12:24:02 

morass:
20171010 11:03:20
@Sushovan Sen: Sure ^_^ Now you shall not be confused :)) 

Sushovan Sen:
20171010 10:29:30
There exists a different problem with same name in spoj. Better if you change the name to avoid confusion. 

swapnil_007:
20171008 13:58:42
Last edit: 20171008 14:14:11 

[Rampage] Blue.Mary:
20171008 05:26:57
Last edit: 20171008 05:27:21 
Added by:  Morass 
Date:  20171008 
Time limit:  3s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Tunisian Collegiate Training Contest  Round #01 