Two coins of each kind (2)

Given a natural number xx and nn different coin values c1cnc_1 \ldots c_n, compute in how many ways it is possible to achieve change xx by using each value at most twice. Here, two coins with the same value are considered different.

For example, if x=4x = 4 and the available values are 11 and 22, then there are three ways to achieve it: 1+1+21 + 1' + 2, 1+1+21 + 1' + 2', and also 2+22 + 2'.

Input

Input consists of several cases. Every case begins with xx and nn, followed by c1cnc_1 \ldots c_n. Assume 1n10001 \le n \le 1000, 1cix10001 \le c_i \le x \le 1000, and that all cic_i are different.

Output

For every case, print the number of ways to exactly achieve change xx by using each value at most twice. Since the result can be huge, make the computations modulo 108+710^8 + 7.

Problem information

Author: Unknown
Translator: Albert Atserias

Generation: 2026-01-25T11:08:48.164Z

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