Playing with numbers

Given n 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 (2 ⋅ 1) + 3 = 5, 2 ⋅ (1 ⋅ 3) = 6, 2 ⋅ (1 + 3) = 8, i
(2 + 1) ⋅ 3 = 9.

Input

Input consists of several cases, each with n, followed by n natural
numbers between 1 and 9. Assume 1 ≤ n ≤ 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
