#include #include #include #include using namespace std; const int MOD = 1e9 + 7; struct mint { int n; mint(int n_ = 0) : n(n_) {} }; mint operator-(mint a) { return a.n == 0 ? 0 : MOD - a.n; } mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; } mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } ostream &operator<<(ostream &o, mint a) { return o << a.n; } mint modpow(mint a, long long b) { mint res = 1; while (b > 0) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } mint modinv(mint a) { return modpow(a, MOD - 2); } template struct FFT { complex rots[N]; FFT() { const double pi = acos(-1); for (int i = 0; i < N / 2; i++) { rots[i + N / 2].real(cos(2 * pi / N * i)); rots[i + N / 2].imag(sin(2 * pi / N * i)); } for (int i = N / 2 - 1; i >= 1; i--) { rots[i] = rots[i * 2]; } } inline complex mul(complex a, complex b) { return complex( a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real() ); } void fft(vector> &a, bool rev) { const int n = a.size(); int i = 0; for (int j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1); if (j < i) { swap(a[i], a[j]); } } for (int i = 1; i < n; i *= 2) { for (int j = 0; j < n; j += i * 2) { for (int k = 0; k < i; k++) { auto s = a[j + k + 0]; auto t = mul(a[j + k + i], rots[i + k]); a[j + k + 0] = s + t; a[j + k + i] = s - t; } } } if (rev) { reverse(a.begin() + 1, a.end()); for (int i = 0; i < n; i++) { a[i] *= 1.0 / n; } } } vector convolution(vector a, vector b) { int t = 1; while (t < a.size() + b.size() - 1) t *= 2; vector> z(t); for (int i = 0; i < a.size(); i++) z[i].real(a[i]); for (int i = 0; i < b.size(); i++) z[i].imag(b[i]); fft(z, false); vector> w(t); for (int i = 0; i < t; i++) { auto p = (z[i] + conj(z[(t - i) % t])) * complex(0.5, 0); auto q = (z[i] - conj(z[(t - i) % t])) * complex(0, -0.5); w[i] = p * q; } fft(w, true); vector ans(a.size() + b.size() - 1); for (int i = 0; i < ans.size(); i++) { ans[i] = round(w[i].real()); } return ans; } vector convolution(vector a, vector b) { int t = 1; while (t < a.size() + b.size() - 1) t *= 2; vector> A(t), B(t); for (int i = 0; i < a.size(); i++) A[i] = complex(a[i].n & 0x7fff, a[i].n >> 15); for (int i = 0; i < b.size(); i++) B[i] = complex(b[i].n & 0x7fff, b[i].n >> 15); fft(A, false); fft(B, false); vector> C(t), D(t); for (int i = 0; i < t; i++) { int j = (t - i) % t; auto AL = (A[i] + conj(A[j])) * complex(0.5, 0); auto AH = (A[i] - conj(A[j])) * complex(0, -0.5); auto BL = (B[i] + conj(B[j])) * complex(0.5, 0); auto BH = (B[i] - conj(B[j])) * complex(0, -0.5); C[i] = AL * BL + AH * BL * complex(0, 1); D[i] = AL * BH + AH * BH * complex(0, 1); } fft(C, true); fft(D, true); vector ans(a.size() + b.size() - 1); for (int i = 0; i < ans.size(); i++) { long long l = (long long)round(C[i].real()) % MOD; long long m = ((long long)round(C[i].imag()) + (long long)round(D[i].real())) % MOD; long long h = (long long)round(D[i].imag()) % MOD; ans[i] = (l + (m << 15) + (h << 30)) % MOD; } return ans; } }; FFT<1 << 20> fft; typedef vector poly; poly operator-(poly a) { for (int i = 0; i < a.size(); i++) { a[i] = -a[i]; } return a; } poly operator+(poly a, poly b) { for (int i = 0; i < a.size(); i++) { a[i] += b[i]; } return a; } poly operator-(poly a, poly b) { for (int i = 0; i < a.size(); i++) { a[i] -= b[i]; } return a; } poly operator*(poly a, poly b) { return fft.convolution(a, b); } poly &operator+=(poly &a, poly b) { return a = a + b; } poly &operator-=(poly &a, poly b) { return a = a - b; } poly pinv(poly a) { const int n = a.size(); poly x = {modinv(a[0])}; for (int i = 1; i < n; i *= 2) { vector tmp(min(i * 2, n)); for (int j = 0; j < tmp.size(); j++) { tmp[j] = a[j]; } auto e = -fft.convolution(tmp, x); e[0] += 2; x = fft.convolution(x, e); x.resize(i * 2); } x.resize(n); return x; } poly plog(poly a) { const int n = a.size(); vector b(n); for (int i = 1; i < n; i++) { b[i - 1] = i * a[i]; } a = fft.convolution(pinv(a), b); for (int i = n - 1; i >= 1; i--) { a[i] = modinv(i) * a[i - 1]; } a[0] = 0; a.resize(n); return a; } poly pexp(poly a) { const int n = a.size(); poly x = {1}; for (int i = 1; i < n; i *= 2) { auto e = -plog(x); e[0] += 1; e.resize(min(i * 2, n)); for (int j = 0; j < e.size(); j++) { e[j] += a[j]; } x = fft.convolution(x, e); x.resize(i * 2); } x.resize(n); return x; } poly quot(poly a, poly b) { if (a.size() < b.size()) return a; while (!a.empty() && a.back().n == 0) a.pop_back(); while (!b.empty() && b.back().n == 0) b.pop_back(); reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); int n = a.size(); int m = b.size(); a = a * b; a.resize(n - m + 1); reverse(a.begin(), a.end()); return a; } poly rem(poly a, poly b) { // return a - quot(a, b) * b; int n = a.size(); int m = b.size() - 1; for (int i = n - 1; i >= m; i--) { for (int j = 0; j < m; j++) { a[i - m + j] -= a[i] * b[j]; } } a.resize(m); return a; } int main() { int K, N; cin >> K >> N; const int U = 1 << 17; vector A(N); for (int i = 0; i < N; i++) { scanf("%d", &A[i]); } poly Y(A.back() + 1); Y[A.back()] = 1; for (int i = 0; i < N; i++) { Y[A.back() - A[i]] = MOD - 1; } poly X(A.back() - 1 + K + 1); X[A.back() - 1 + K] = 1; X = rem(X, Y); cout << X[A.back()-1].n << '\n'; }