import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } // a^-1 (mod m) long modInv(long a, long m) in { assert(m > 0, "modInv: m > 0 must hold"); } do { long b = m, x = 1, y = 0, t; for (; ; ) { t = a / b; a -= t * b; if (a == 0) { assert(b == 1 || b == -1, "modInv: gcd(a, m) != 1"); if (b == -1) { y = -y; } return (y < 0) ? (y + m) : y; } x -= t * y; t = b / a; b -= t * a; if (b == 0) { assert(a == 1 || a == -1, "modInv: gcd(a, m) != 1"); if (a == -1) { x = -x; } return (x < 0) ? (x + m) : x; } y -= t * x; } } // Find the smallest x (>= 0) s.t. x == a[i] (mod m[i]), mod m0 // x = y[0] + m[0] y[1] + m[0] m[1] y[2] + ... + m[0] ... m[n - 1] y[n - 1] // m[i]'s must be coprime long garner(long[] a, long[] m, long m0) in { foreach (i; 0 .. m.length) { assert(0 < m[i] && m[i] <= 0x7fffffff, "garner: 0 < m < 2^31 must hold"); } } do { long t; auto y = new long[m.length]; foreach (i; 0 .. m.length) { y[i] = a[i] % m[i]; t = 1; foreach (j; 0 .. i) { (y[i] -= t * y[j]) %= m[i]; (t *= m[j]) %= m[i]; } if (((y[i] *= modInv(t, m[i])) %= m[i]) < 0) { y[i] += m[i]; } } long x = 0; t = 1; foreach (i; 0 .. m.length) { (x += t * y[i]) %= m0; (t *= m[i]) %= m0; } return x; } enum MOO = 100_000_000_000_000_007L; enum MOS = [17, 9920467, 592951213]; int N, M; int[] X; void main() { try { for (; ; ) { N = readInt() - 1; M = readInt(); X = new int[M]; foreach (m; 0 .. M) { X[m] = readInt(); } debug { auto brute = new long[N + 1]; brute[0] = 1; foreach (n; 1 .. N + 1) { foreach (x; X) { if (n >= x) { (brute[n] += brute[n - x]) %= MOO; } } } writeln("brute[N] = ", brute[N]); } /* 0 1 01 2 01 23 012 34 012 345 */ const lim = N / 2 + 1; int[] xs, ys; foreach (m; 0 .. M) { ((X[m] < lim) ? xs : ys) ~= X[m]; } auto anss = new long[MOS.length]; auto dp = new int[lim]; foreach (h, MO; MOS) { dp[] = 0; dp[0] = 1; foreach (n; 0 .. lim) { foreach (x; xs) { if (n >= x) { if ((dp[n] += dp[n - x]) >= MO) { dp[n] -= MO; } } } } foreach (y; ys) { foreach (n; 0 .. lim) { if (N - y >= n) { (anss[h] += cast(long)(dp[n]) * dp[N - y - n]) %= MO; } } } foreach (n; lim .. N + 1) { dp[n - lim] = 0; foreach (x; xs) { if (n >= x) { if ((dp[n - lim] += dp[(n - x < lim) ? (n - x) : (n - x - lim)]) >= MO) { dp[n - lim] -= MO; } } } } if ((anss[h] += dp[N - lim]) >= MO) { anss[h] -= MO; } } debug { writeln(anss); } const ans = garner(anss, MOS.to!(long[]), MOO); writeln(ans); } } catch (EOFException e) { } }