Lord of the Ring
Frodo knows all pairwise distances between bushes placed along one straight road, but not their positions. For each data set, reconstruct a valid placement and compute P, the product of the distances between consecutive bushes.
Input
The input contains data sets until end of file. Each begins with the number m of pairwise distances, followed by those m distances in nondecreasing order. Whitespace may occur freely. There are between 2 and 1000 bushes, and a valid product never exceeds 10^9.
Output
For each data set, print P. If the distances do not describe a valid placement, print No solution.
Example
Input:
6
1 2 2 3 3 5
3
1 2 2
Output:
4
No solution
Submit solution
Sign in to submit a solution.