Consider the following rules for a game, similar to those of a famous TV show: Six numbers are generated at random between 1 and 1000. A random number from 1 to is also generated. The goal is to get the number , or as close to it as possible. To do so, we may add, substract, multiply and divide the numbers of any non-empty subset of the six given numbers. No may be used more than once. Additionally, all intermediate results must be between 0 and . The divisions must be exact. Obviously, we cannot divide by zero.
Can you compute the result that is closest to ? For instance, if and we have the numbers , a possible solution (exact, in this case) is
Input consists of several cases, each with and .
For every case, print the result that is closest to . If there is a tie, choose the largest result.
Input
982 100 75 50 25 6 3 1000 10 10 10 10 10 10 1003 10 10 10 10 10 10 1 213 769 552 695 207 999 1000000 1 1 1 1 1 1 42 1000 42 867 999 600 235
Output
982 1000 1002 3 9 42