Megumin loves magical explosions. Since you are Megumin's most trusted adviser, you want to help her to create the most spectacular explosion ever.
Megumin currently has magical components that must all be combined together to create an explosion. However, Megumin can combine the components in any order she wants, and the specific order which she does this will result in a differing size of the resulting explosion.
Each component has a potency value . There are only two known ways to combine two components and into a single component:
- Controlled combination: the two components will combine together to make a new component with potency .
- Unstable combination: the two components will combine together to make a new component with potency .
After Megumin applies operations times, the size of the resulting explosion is equal to the potency of the only remaining component. Since Megumin appreciates the beauty of both a small and intense and a large and flashy explosion, you would like to determine what the sizes of the smallest and largest explosions Megumin can possibly make are. Since these numbers may be very large, you should output the results modulo .
The first line of input will contain the integer .
The second line of input will contain integers, .
The first line of output should contain the smallest explosion Megumin can make.
The second line of output should contain the largest explosion Megumin can make.
For all subtasks,
[Subtask 1 - 20%]
[Subtask 2 - 35%]
At most values of will be equal to .
[Subtask 3 - 45%]
No additional constraints.
3 2 1 3
Explanation of Output for Sample Input
To make the smallest explosion, first Megumin should combine the components with potencies 2 and 3 with a controlled combinations and then combine the remaining components with unstable combinations.
To make the largest explosion, first Megumin should combine the components with potencies 1 and 2 with a controlled combination and then combine the remaining components with unstable combinations.