Given a number and different coin values , compute in how many ways it is possible to achieve change by using each value at most twice. Here, two coins with the same value are considered equal.
For example, if and the available values are 1 and 2, then there are two ways to achieve it: and . As another example, if and the available values are 1, 2, 3, 4 and 5, then there are five ways: , , , and 5.
Input consists of several cases, with only integer numbers. Every case begins with and , followed by . Assume , , and that all are different.
For every case print the number of different ways to achieve change exactly by using each value at most twice.
A simply pruned backtracking should be enough.
Input
4 2 1 2 400 1 200 400 1 300 5 3 4 2 1 5 5 1 2 3 4 5
Output
2 1 0 2 5