404236: GYM101466 A Gaby And Addition
Description
Gaby is a little baby who loves playing with numbers. Recently she has learned how to add 2 numbers using the standard addition algorithm which we summarize in 3 steps:
- Line up the numbers vertically matching digits places.
- Add together the numbers that share the same place value from right to left.
- Carry if necessary.
it means when adding two numbers we will get something like this:
Unfortunately as Gaby is too young she doesn't know what the third step means so she just omitted this step using her own standard algorithm (Gaby's addition algorithm). When adding two numbers without carrying when necessary she gets something like the following:
Gaby loves playing with numbers so she wants to practice the algorithm she has just learned (in the way she learned it) with a list of numbers adding every possible pair looking for the pair which generates the largest value and the smallest one.
She needs to check if she is doing it correctly so she asks for your help to find the largest and the smallest value generated from the list of numbers using Gaby's addition algorithm.
InputThe input starts with an integer n (2 ≤ n ≤ 106) indicating the number of integers Gaby will be playing with. The next line contains n numbers ni (0 ≤ ni ≤ 1018) separated by a single space.
OutputOutput the smallest and the largest number you can get from adding two numbers from the list using Gaby's addition algorithm.
ExamplesInput6Output
17 5 11 0 42 99
0 99Input
7Output
506823119072235413 991096248449924896 204242310783332529 778958050378192979 384042493592684633 942496553147499866 410043616343857825
52990443860776502 972190360051424498Note
In the first sample input this is how you get the minimum and the maximum value