Time limit
2s
Memory limit
128 MB
You are given an array A of size N, filled with integers from 1 to 30 inclusive. Use every element exactly once, together with any number of +, -, *, /, and parentheses, to build one expression. Among all values that can be made, find the smallest prime and the largest prime.
Values in A may repeat.
For example, if A = {1, 2, 3}, the smallest prime is 3 - 2 + 1 = 2, and the largest prime is 3 * 2 + 1 = 7.
A division operation may be used only when both operands are positive integers and the division is exact; its result is the integer quotient.
The first line contains the size N of array A. The second line contains the N elements of A, separated by spaces.
Print the smallest prime that can be made on the first line, and the largest prime on the second line. If no prime can be made, print only -1.