Equal sums (3)

Write a program that, given a natural number ss and nn natural numbers x1,,xnx_1, \dots, x_n, prints all the subsets (maybe with repeated numbers, but using every xix_i at most once) whose sum is exactly ss.

Input

Input consists of a natural number ss, followed by a number n>0n > 0, followed by x1,,xnx_1, \dots, x_n.

Output

Print all the subsets whose sum is ss that can be made up with x1,,xnx_1, \dots, x_n.

Information about the checker

You can print in any order both the solutions and the elements inside each solution.

Hint

For this exercise, a very simple algorithm can be too slow.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T09:59:01.965Z

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