This problem is a programming version of Problem 93 from projecteuler.net
By using each of the digits from the set, , exactly once, and making use of the four arithmetic operations and brackets/parentheses, it is possible to form different positive integer targets.
For example,
Note that concatenations of the digits, like , are not allowed.
Using the set, , it is possible to obtain thirty-one different target numbers of which 36 is the maximum, and each of the numbers to can be obtained before encountering the first non-expressible number.
Given a set of distinct digits, , find the largest possible integer such that each integer from to is expressible using elements of and following the above rules. If is also not expressible, output instead.
Input Format
The first line contains .
The second line contains space separated integers, the elements of .
Constraints
Output Format
Output a single integer, the answer to the problem.
Sample Input
4
1 2 3 4
Sample Output
28
Explanation
Explained in the statement.