#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include using namespace std; #if __has_include() #include using namespace atcoder; #endif template struct BIT2{ public: vector> data; long long H,W; long long fidx=0; BIT2(long long H,long long W,long long first_index=0):data(H),H(H),W(W),fidx(first_index){} T sum(const long long x,const long long y){ T ret=0; long long i=x,j=y; //if (fidx==0){i++;j++;} while (i>0){ long long k=j; while (k>0){ ret+=this->data[i][k]; k -= k&-k; } i -= i& -i; } return ret; } void add(const long long x,const long long y,const T &delta){ long long i=x,j=y; //if (fidx==0){i+=1;j+=1;} while (i<=H){ long long k = j; while (k<=W){ this->data[i][k]+=delta; k += k&-k; } i += i& -i; } } T range_sum(long long x0,long long x1,long long y0, long long y1){ /*x0-=fidx; x1-=fidx; y0-=fidx; y1-=fidx;*/ return this->sum(x1, y1) - this->sum(x1, y0) - this->sum(x0, y1) + this->sum(x0, y0); } T get(long long x, long long y){ return this->range_sum(x,x+1,y,y+1); } }; template struct matrix { std::valarray value; size_t N; matrix(size_t size, T init) : value(init, size * size), N(size) {} matrix(size_t size) : value(size * size), N(size) {} matrix(matrix *M) : value(M->value), N(M->N) {} matrix(valarray v, size_t size) : value(v), N(size) {} public: matrix &operator=(const matrix &B) { this->value = std::valarray(B.value); return *this; } /*const std::valarray& operator [](const size_t i)const{ return *std::valarray(value[std::slice(N*i,N,1)]); } std::valarray& operator [](const size_t i){ //書き込み用 return *(value[std::slice(N*i,N,1)]); }*/ const matrix operator+(const matrix &B) const { return matrix(value + B.value, N); } const matrix operator-(const matrix &B) const { return matrix(value - B.value, N); } const matrix operator*(const matrix &B) const { std::valarray ret(N * N); for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < N; j++) { ret[N * i + j] = (T)(value[std::slice(N * i, N, 1)] * (B.value[std::slice(j, N, N)])).sum(); } } return matrix(ret, N); } matrix &operator+=(const matrix &B) { value += B.value; return *this; } matrix &operator-=(const matrix &B) { value -= B.value; return *this; } matrix &operator*=(const matrix &B) { *this = (*this) * B; return *this; } matrix &operator=(const T &v) { std::valarray ret(N * N); for (size_t i = 0; i < N * N; i += N + 1) ret[i] = v; value = ret; return *this; } const matrix operator+(const T &v) const { std::valarray delta(N * N); for (size_t i = 0; i < N * N; i += N + 1) delta[i] = v; return matrix(value + delta, N); } const matrix operator-(const T &v) const { std::valarray delta(N * N); for (size_t i = 0; i < N * N; i += N + 1) delta[i] = v; return matrix(value - delta, N); } const matrix operator*(const T &v) const { return matrix(value * v, N); } const matrix operator/(const T &v) const { return matrix(value / v, N); } const matrix operator^(long long n) const { assert(n >= 0); matrix a(N), ret(N); ret = (T)1; a.value = this->value; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return matrix(ret.value, N); } matrix &operator^=(long long n) { *(this) = *(this) ^ n; return *this; } const matrix Transpose() const { std::valarray ret(N * N); for (size_t i = 0; i < N; i++) for (size_t j = 0; j < N; j++) ret[N * i + j] = value[j * N + i]; return matrix(ret, N); } }; #pragma region Macros // rep macro #define overload4(_1, _2, _3, _4, name, ...) name #define overload3(_1, _2, _3, name, ...) name #define rep1(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, a, b) for (ll i = a; i < b; ++i) #define rep3(i, a, b, c) for (ll i = a, _bb = b; (a <= i && i < _bb) or (a >= i && i > _bb); i += c) #define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define each1(i, a) for (auto &&i : a) #define each2(x, y, a) for (auto &&[x, y] : a) #define each3(x, y, z, a) for (auto &&[x, y, z] : a) #define each(...) overload4(__VA_ARGS__, each3, each2, each1)(__VA_ARGS__) #define extrep(v, ...) for (auto v : __MAKE_MAT__({__VA_ARGS__})) vector> __MAKE_MAT__(vector v) { if (v.empty()) return vector>(1, vector()); long long n = v.back(); v.pop_back(); vector> ret; vector> tmp = __MAKE_MAT__(v); for (auto e : tmp) for (long long i = 0; i < n; ++i) { ret.push_back(e); ret.back().push_back(i); } return ret; } //extrep(v,3,4,5)->v=[0,3)x[0,4)x[0,5) #define vep(i, v) for (auto(i) = std::begin(v); std::distance(std::begin(i), (std::end(v))) > 0; ++(i)) // name macro #define all(v) std::begin(v), std::end(v) #define rall(v) std::rbegin(v), std::rend(v) template using V = std::vector; template using VV = std::vector>; template using pqup = std::priority_queue, std::greater>; using ld = long double; using int128 = __int128_t; using pii = std::pair; using pll = std::pair; using ll = long long; using Int = long long; #define eb emplace_back #define pb push_back //py macro #define elif else if #define Sum(...) accumulate(all(__VA_ARGS__), 0LL) template int bisect_left(const std::vector &a, const T x) { return std::distance(std::begin(a), std::lower_bound(std::begin(a), std::end(a), (x))); } template int bl(const std::vector &a, const T x) { return std::distance(std::begin(a), std::lower_bound(std::begin(a), std::end(a), (x))); } template int bisect_right(const std::vector &a, const T x) { return std::distance(std::begin(a), std::upper_bound(std::begin(a), std::end(a), (x))); } template int br(const std::vector &a, const T x) { return std::distance(std::begin(a), std::upper_bound(std::begin(a), std::end(a), (x))); } #define Sort(x) sort(std::begin(x), std::end(x)) #define Reverse(x) reverse(std::begin(x), std::end(x)) #define len(x) (ll) x.size() #define popcnt(x) __builtin_popcountll(x) // input macro template std::istream &operator>>(std::istream &is, std::pair &p) { is >> p.first >> p.second; return is; } template std::istream &operator>>(std::istream &is, std::vector &v) { for (T &i : v) is >> i; return is; } template std::istream &operator>>(std::istream &is, std::valarray &v) { for (T &i : v) is >> i; return is; } template std::istream &operator>>(std::istream &is, matrix &v) { for (T &i : v.value) is >> i; return is; } std::istream &operator>>(std::istream &is, __int128_t &a) { std::string s; is >> s; __int128_t ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0'; a = ret * (s[0] == '-' ? -1 : 1); return is; } #if __has_include() std::istream &operator>>(std::istream &is, atcoder::modint998244353 &a) { long long v; is >> v; a = v; return is; } std::istream &operator>>(std::istream &is, atcoder::modint1000000007 &a) { long long v; is >> v; a = v; return is; } template std::istream &operator>>(std::istream &is, atcoder::static_modint &a) { long long v; is >> v; a = v; return is; } template std::istream &operator>>(std::istream &is, atcoder::dynamic_modint &a) { long long v; is >> v; a = v; return is; } #endif namespace scanner { void scan(int &a) { std::cin >> a; } void scan(long long &a) { std::cin >> a; } void scan(std::string &a) { std::cin >> a; } void scan(char &a) { std::cin >> a; } void scan(char a[]) { std::scanf("%s", a); } void scan(double &a) { std::cin >> a; } void scan(long double &a) { std::cin >> a; } template void scan(std::pair &p) { std::cin >> p; } template void scan(std::vector &a) { std::cin >> a; } template void scan(std::valarray &a) { std::cin >> a; } template void scan(matrix &a) { std::cin >> a; } void INPUT() {} template void INPUT(Head &head, Tail &...tail) { scan(head); INPUT(tail...); } } // namespace scanner #define VEC(type, name, size) \ std::vector name(size); \ scanner::INPUT(name) #define VAL(type, name, size) \ std::valarray name(size); \ scanner::INPUT(name) #define VVEC(type, name, h, w) \ std::vector> name(h, std::vector(w)); \ scanner::INPUT(name) #define MAT(type, name, n) \ matrix name(n); \ scanner::INPUT(name) #define INT(...) \ int __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define STR(...) \ std::string __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LD(...) \ long double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) struct input { input(){}; template operator T() { T t; cin >> t; return t; } }; // output-macro template std::ostream &operator<<(std::ostream &os, const std::pair &p) { os << p.first << " " << p.second; return os; } template std::ostream &operator<<(std::ostream &os, const std::vector &a) { for (int i = 0; i < int(a.size()); ++i) { if (i) os << " "; os << a[i]; } return os; } template std::ostream &operator<<(std::ostream &os, const std::valarray &a) { for (int i = 0; i < int(a.size()); ++i) { if (i) os << " "; os << a[i]; } return os; } std::ostream &operator<<(std::ostream &dest, __int128_t &value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } #if __has_include() std::ostream &operator<<(std::ostream &os, const atcoder::modint998244353 &a) { return os << a.val(); } std::ostream &operator<<(std::ostream &os, const atcoder::modint1000000007 &a) { return os << a.val(); } template std::ostream &operator<<(std::ostream &os, const atcoder::static_modint &a) { return os << a.val(); } template std::ostream &operator<<(std::ostream &os, const atcoder::dynamic_modint &a) { return os << a.val(); } #endif template void print(const T a) { std::cout << a << '\n'; } template void print(Head H, Tail... T) { std::cout << H << ' '; print(T...); } template void printel(const T a) { std::cout << a << '\n'; } template void printel(const std::vector &a) { for (const auto &v : a) std::cout << v << '\n'; } template void printel(Head H, Tail... T) { std::cout << H << '\n'; printel(T...); } inline void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); } inline void No() { std::cout << "No\n"; } inline void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); } inline void NO() { std::cout << "NO\n"; } inline void err(const bool b = true) { if (b) std::cout << "-1\n", exit(0); } inline void First(const bool b = true) { std::cout << (b ? "First\n" : "Second\n"); } inline void first(const bool b = true) { std::cout << (b ? "first\n" : "second\n"); } template inline void Case(const long long &number, T ans) { printf("Case #%d: ", number); cout << ans << "\n"; } //debug macro namespace debugger { template void view(const std::vector &a) { std::cerr << "{ "; for (const auto &v : a) { std::cerr << v << ", "; } std::cerr << "\b\b }"; } template void view(const std::valarray &a) { std::cerr << "{ "; for (const auto &v : a) { std::cerr << v << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector> &a) { std::cerr << "{\n"; for (const auto &v : a) { std::cerr << "\t"; view(v); std::cerr << "\n"; } std::cerr << "}"; } template void view(const matrix &a) { std::cerr << "{\n"; for (int i = 0; i < a.N; i++) { std::cerr << "\t"; valarray inner = a.value[std::slice(i * a.N, a.N, 1)]; view(inner); std::cerr << "\n"; } std::cerr << "}"; } template void view(const std::vector> &a) { std::cerr << "{\n"; for (const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n"; std::cerr << "}"; } template void view(const std::map &m) { std::cerr << "{\n"; for (const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n"; std::cerr << "}"; } template void view(const std::pair &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; } template void view(const std::set &s) { std::cerr << "{ "; for (auto &v : s) { view(v); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const T &e) { std::cerr << e; } } // namespace debugger #ifdef LOCAL void debug_out() { } template void debug_out(Head H, Tail... T) { debugger::view(H); std::cerr << ", "; debug_out(T...); } #define debug(...) \ do \ { \ std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \ debug_out(__VA_ARGS__); \ std::cerr << "\b\b]\n"; \ } while (false) #else #define debug(...) (void(0)) #endif // vector macro template void uniq(std::vector &a) { std::sort(std::begin(a), std::end(a)); a.erase(std::unique(std::begin(a), std::end(a)), std::end(a)); } template std::vector press(std::vector &a) { auto res = a; UNIQUE(res); for (auto &v : a) v = lb(res, v); return res; } #define SORTname(a, b, c, ...) c #define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__) #define SORT0(a) std::sort(std::begin(a), std::end(a)) #define SORT1(a, c) std::sort(std::begin(a), std::end(a), [](const auto x, const auto y) { return x c y; }) // math macro template inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; } template inline T LCM(T a, T b) { return a / GCD(a, b) * b; } template inline T modinv(T a, T M) { return (1 - M * modinv(M % a, a)) / a + M; } template inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; } template inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; } template inline T ceildiv(T x, T y) { return (x + y - 1) / y; } template T POW(T a, long long n) { T ret = 1; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } // modpow long long POW(long long a, long long n, const int mod) { long long ret = 1; while (n) { if (n & 1) (ret *= a) %= mod; (a *= a) %= mod; n >>= 1; } return ret; } // find integer x s.t. x^2<=n<(x+1)^2 template T isqrt(T n) { if (n == 0) return 0; if (n < 0) return -1; unsigned long long int m = n; m |= m >> 1; m |= m >> 2; m |= m >> 4; m |= m >> 8; m |= m >> 16; T x = 1 << ((__builtin_popcount(m) + 1) / 2); T y = (x + n / x) / 2; while (y < x) { x = y; y = (x + n / x) / 2; } return x; } //部分集合の列挙 std::vector subset(unsigned int S) { unsigned int cnt = __builtin_popcount(S); std::vector ret(1 << cnt, 0); int head = (1 << cnt) - 1; for (unsigned int T = S; T != 0; T = S & (T - 1), head--) { ret[head] = T; } return ret; } //N桁の二進数のうち丁度Kbitだけ立っている数の列挙 std::vector bits(long long N, long long K) { unsigned long long v = (1 << K) - 1, MAX = 1 << N; std::vector ret(0); unsigned long long x, y; while (v < MAX) { ret.emplace_back(v); x = v & (-v); y = v + x; v = (v & ~y) / x >> 1 | y; } return ret; } int bit_length(unsigned long long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x |= x >> 32; return __builtin_popcountll(x); } vector> childs( long long S){ long long tmp=S; vector> ret(0); while(tmp){ unsigned long long v=tmp&(-tmp); tmp^=v; ret.emplace_back( pair(S^v,bit_length(v)-1)); } return ret; } // others struct fast_io { fast_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } fast_io_; inline std::vector> NEXT(long long x, long long y) { return {{x - 1, y}, {x, y - 1}, {x, y + 1}, {x + 1, y}}; } inline std::vector> NEXT8(long long x, long long y) { return {{x - 1, y - 1}, {x - 1, y}, {x - 1, y + 1}, {x, y - 1}, {x, y + 1}, {x + 1, y - 1}, {x + 1, y}, {x + 1, y + 1}}; } constexpr const int inf = 1e9; constexpr const long long linf = 10e17; //int |x|<=2*10**9 long |x|<= 9*10**18 //constexpr const long long mod2 = 998244353; //constexpr const long long mod = 1000000007; using mint = modint1000000007; int main() { fast_io(); INT(N); LL(K); VEC(int,C,9); V<> nums(0); rep(i,9)rep(j,C[i])nums.eb(i+1); V> dp(1< fact(15,1ll); rep(i,1,15){ fact[i]=fact[i-1]*i; } long long f=dp[(1<