Playing with numbers

Given nn numbers, compute all the different results that can be obtained with the sum and product operators and adding parentheses at will. You cannot change the order of the given numbers. For instance, with 2, 1 and 3 we can get 5, 6, 8 or 9, but no other result. Some possible combinations are (21)+3=5(2 \cdot 1) + 3 = 5, 2(13)=62 \cdot (1 \cdot 3) = 6, 2(1+3)=82 \cdot (1 + 3) = 8, i (2+1)3=9(2 + 1) \cdot 3 = 9.

Input

Input consists of several cases, each with nn, followed by nn natural numbers between 1 and 9. Assume 1n91 \le n \le 9.

Output

For every case, print all the possible results in order.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:13:37.343Z

© Jutge.org, 2006–2026.
https://jutge.org