Summing up coins

Given n coins of some value, you are asked to find out all the possible sums you can obtain with those coins.


The first line of the input contains two integers n (1 ≤ n ≤ 100).
The next line contains n space-separated integers (1 ≤ ≤ 1000) the coin values.


The program should first print the number of possible sums one can obtain with those coins on the first line. While the second line of the output should contain all the possible sums in increasing order separated by a space.


4 2 5 4 2
9 2 4 5 6 7 8 9 11 13


Time limit: 4.8 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in