#line 2 "Library\\gcc_option.hpp" #ifdef LOCAL #define _GLIBCXX_DEBUG #else #pragma GCC optimize("O3") #pragma GCC target("avx,avx2") #pragma GCC optimize("unroll-loops") #endif #line 2 "t.cpp" #include #line 5 "Library\\config.hpp" namespace config { const auto start_time{std::chrono::system_clock::now()}; int64_t elapsed() { using namespace std::chrono; const auto end_time{system_clock::now()}; return duration_cast(end_time - start_time).count(); } __attribute__((constructor)) void setup() { using namespace std; ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); #ifdef _buffer_check atexit([]{ ofstream cnsl("CON"); char bufc; if(cin >> bufc) cnsl << "\n\033[1;35mwarning\033[0m: buffer not empty.\n\n"; }); #endif } unsigned cases(void), caseid = 1; template void main() { for(const unsigned total = cases(); caseid <= total; ++caseid) C(); } } // namespace config #line 3 "Library\\utils\\iostream_overload.hpp" namespace std { template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second; } template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second; } template struct tupleis { static istream &apply(istream &is, tuple_t &t) { tupleis::apply(is, t); return is >> get(t); } }; template struct tupleis { static istream &apply(istream &is, tuple_t &t) { return is; } }; template istream &operator>>(istream &is, tuple &t) { return tupleis, tuple_size>::value - 1>::apply(is, t); } template <> istream &operator>>(istream &is, tuple<> &t) { return is; } template struct tupleos { static ostream &apply(ostream &os, const tuple_t &t) { tupleos::apply(os, t); return os << ' ' << get(t); } }; template struct tupleos { static ostream &apply(ostream &os, const tuple_t &t) { return os << get<0>(t); } }; template ostream &operator<<(ostream &os, const tuple &t) { return tupleos, tuple_size>::value - 1>::apply(os, t); } template <> ostream &operator<<(ostream &os, const tuple<> &t) { return os; } template , string>::value, nullptr_t> = nullptr> istream& operator>>(istream& is, Container &cont) { for(auto&& e : cont) is >> e; return is; } template , string>::value, nullptr_t> = nullptr> ostream& operator<<(ostream& os, const Container &cont) { bool flag = 1; for(auto&& e : cont) flag ? flag = 0 : (os << ' ', 0), os << e; return os; } } // namespace std #line 3 "Library\\utils\\read.hpp" namespace workspace { // read with std::cin. template struct read { typename std::remove_const::type value; template read(types... args) : value(args...) { std::cin >> value; } operator T() const { return value; } }; template <> struct read { template operator T() const { T value; std::cin >> value; return value; } }; } // namespace workspace #line 3 "Library\\utils\\casefmt.hpp" namespace workspace { std::ostream &casefmt(std::ostream& os) { return os << "Case #" << config::caseid << ": "; } } // namespace workspace #line 3 "Library\\utils\\fixed_point.hpp" namespace workspace { // specify the return type of lambda. template class fixed_point { lambda_type func; public: fixed_point(lambda_type &&f) : func(std::move(f)) {} template auto operator()(Args &&... args) const { return func(*this, std::forward(args)...); } }; } // namespace workspace #line 3 "Library\\utils\\chval.hpp" namespace workspace { template > bool chle(T &x, const T &y, Comp comp = Comp()) { return comp(y, x) ? x = y, true : false; } template > bool chge(T &x, const T &y, Comp comp = Comp()) { return comp(x, y) ? x = y, true : false; } } // namespace workspace #line 5 "Library\\utils\\binary_search.hpp" namespace workspace { // binary search on discrete range. template , bool>, std::nullptr_t> = nullptr> iter_type binary_search(iter_type ok, iter_type ng, pred_type pred) { assert(ok != ng); intmax_t dist(ng - ok); while(std::abs(dist) > 1) { iter_type mid(ok + dist / 2); if(pred(mid)) ok = mid, dist -= dist / 2; else ng = mid, dist /= 2; } return ok; } // binary search on real numbers. template , bool>, std::nullptr_t> = nullptr> real_type binary_search(real_type ok, real_type ng, const real_type eps, pred_type pred) { assert(ok != ng); while(std::abs(ok - ng) > eps) { real_type mid{(ok + ng) / 2}; (pred(mid) ? ok : ng) = mid; } return ok; } } // namespace workspace #line 2 "Library\\alias.hpp" using namespace std; using namespace __gnu_cxx; using i32 = int_least32_t; using i64 = int_least64_t; using p32 = pair; using p64 = pair; template > using heap = priority_queue, Comp>; template using hashset = unordered_set; template using hashmap = unordered_map; #line 11 "t.cpp" namespace workspace { struct solver; } int main() { config::main(); } unsigned config::cases() { // return -1; // not specify // int t; std::cin >> t; return t; // given return 1; } #line 4 "Library\\combinatorics\\factorial.hpp" template > class factorial { std::vector fact; Op op; public: factorial(T init = 1, Op op = Op()) : fact{init}, op{op} {} T operator()(const int &n) { if(n < 0) return 0; for(int m(fact.size()); m <= n; ++m) fact.emplace_back(op(fact.back(), m)); return fact[n]; } }; // class factorial #line 4 "Library\\modulus\\modint.hpp" template // compile-time defined modulo. struct modint { static_assert(mod > 0); template struct modif { using value_type = int_least32_t; }; template struct modif { using value_type = int_least64_t; }; using value_type = typename modif::value_type; constexpr static modint one() noexcept { return 1; } constexpr operator value_type() const noexcept { return value; } constexpr modint() noexcept = default; template ::value, std::nullptr_t> = nullptr> constexpr modint(int_type n) noexcept : value((n %= mod) < 0 ? mod + n : n) {} constexpr modint operator++(int) noexcept { modint t{*this}; return operator+=(1), t; } constexpr modint operator--(int) noexcept { modint t{*this}; return operator-=(1), t; } constexpr modint &operator++() noexcept { return operator+=(1); } constexpr modint &operator--() noexcept { return operator-=(1); } constexpr modint operator-() const noexcept { return value ? mod - value : 0; } constexpr modint &operator+=(const modint &rhs) noexcept { return (value += rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint &operator-=(const modint &rhs) noexcept { return (value += mod - rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint &operator*=(const modint &rhs) noexcept { return value = (int_fast64_t)value * rhs.value % mod, *this; } constexpr modint &operator/=(const modint &rhs) noexcept { return operator*=(rhs.inverse()); } template ::value, std::nullptr_t> = nullptr> constexpr modint operator+(const int_type &rhs) const noexcept { return modint{*this} += rhs; } constexpr modint operator+(const modint &rhs) const noexcept { return modint{*this} += rhs; } template ::value, std::nullptr_t> = nullptr> constexpr modint operator-(const int_type &rhs) const noexcept { return modint{*this} -= rhs; } constexpr modint operator-(const modint &rhs) const noexcept { return modint{*this} -= rhs; } template ::value, std::nullptr_t> = nullptr> constexpr modint operator*(const int_type &rhs) const noexcept { return modint{*this} *= rhs; } constexpr modint operator*(const modint &rhs) const noexcept { return modint{*this} *= rhs; } template ::value, std::nullptr_t> = nullptr> constexpr modint operator/(const int_type &rhs) const noexcept { return modint{*this} /= rhs; } constexpr modint operator/(const modint &rhs) const noexcept { return modint{*this} /= rhs; } template ::value, std::nullptr_t> = nullptr> constexpr friend modint operator+(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) + rhs; } template ::value, std::nullptr_t> = nullptr> constexpr friend modint operator-(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) - rhs; } template ::value, std::nullptr_t> = nullptr> constexpr friend modint operator*(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) * rhs; } template ::value, std::nullptr_t> = nullptr> constexpr friend modint operator/(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) / rhs; } constexpr modint inverse() const noexcept { assert(value); value_type a{mod}, b{value}, u{}, v{1}, t{}; while(b) t = a / b, a ^= b ^= (a -= t * b) ^= b, u ^= v ^= (u -= t * v) ^= v; return {u}; } constexpr static modint pow(modint rhs, int_fast64_t e) noexcept { if(e < 0) e = e % (mod - 1) + mod - 1; modint res{1}; while(e) { if(e & 1) res *= rhs; rhs *= rhs, e >>= 1; } return res; } friend std::ostream &operator<<(std::ostream &os, const modint &rhs) noexcept { return os << rhs.value; } friend std::istream &operator>>(std::istream &is, modint &rhs) noexcept { value_type value; rhs = (is >> value, value); return is; } protected: value_type value = 0; }; // class modint template <> // runtime defined modulo as default(mod = 0). struct modint<0> { using value_type = int_fast64_t; static value_type &mod() noexcept { static value_type mod{}; return mod; } static modint one() noexcept { return 1; } operator value_type() const noexcept { return value; } modint() noexcept = default; template ::value, std::nullptr_t> = nullptr> modint(int_type n) noexcept : value{ (assert(mod()), n %= mod() < 0 ? n + mod() : n) } {} modint operator++(int) noexcept { modint t{*this}; return operator+=(1), t; } modint operator--(int) noexcept { modint t{*this}; return operator-=(1), t; } modint &operator++() noexcept { return operator+=(1); } modint &operator--() noexcept { return operator-=(1); } modint operator-() const noexcept { return value ? mod() - value : 0; } modint &operator+=(const modint &rhs) noexcept { return (value += rhs.value) < mod() ? 0 : value -= mod(), *this; } modint &operator-=(const modint &rhs) noexcept { return (value += mod() - rhs.value) < mod() ? 0 : value -= mod(), *this; } modint &operator*=(const modint &rhs) noexcept { return (value *= rhs.value) %= mod(), *this; } modint &operator/=(const modint &rhs) noexcept { return operator*=(rhs.inverse()); } template ::value, std::nullptr_t> = nullptr> modint operator+(const int_type &rhs) const noexcept { return modint{*this} += rhs; } modint operator+(const modint &rhs) const noexcept { return modint{*this} += rhs; } template ::value, std::nullptr_t> = nullptr> modint operator-(const int_type &rhs) const noexcept { return modint{*this} -= rhs; } modint operator-(const modint &rhs) const noexcept { return modint{*this} -= rhs; } template ::value, std::nullptr_t> = nullptr> modint operator*(const int_type &rhs) const noexcept { return modint{*this} *= rhs; } modint operator*(const modint &rhs) const noexcept { return modint{*this} *= rhs; } template ::value, std::nullptr_t> = nullptr> modint operator/(const int_type &rhs) const noexcept { return modint{*this} /= rhs; } modint operator/(const modint &rhs) const noexcept { return modint{*this} /= rhs; } template ::value, std::nullptr_t> = nullptr> friend modint operator+(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) + rhs; } template ::value, std::nullptr_t> = nullptr> friend modint operator-(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) - rhs; } template ::value, std::nullptr_t> = nullptr> friend modint operator*(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) * rhs; } template ::value, std::nullptr_t> = nullptr> friend modint operator/(const int_type &lhs, const modint &rhs) noexcept { return modint(lhs) / rhs; } modint inverse() const noexcept { assert(mod() && value); long long a{mod()}, b{value}, u{}, v{1}, t{}; while(b) t = a / b, a ^= b ^= (a -= t * b) ^= b, u ^= v ^= (u -= t * v) ^= v; return {u}; } static modint pow(modint rhs, int_fast64_t e) noexcept { if(e < 0) e = e % (mod() - 1) + mod() - 1; modint res{1}; while(e) { if(e & 1) res *= rhs; rhs *= rhs, e >>= 1; } return res; } friend std::ostream &operator<<(std::ostream &os, const modint &rhs) noexcept { return os << rhs.value; } friend std::istream &operator>>(std::istream &is, modint &rhs) noexcept { long long value; rhs = modint((is >> value, value)); return is; } protected: value_type value = 0; }; // class modint<0> using modint_runtime = modint<0>; #line 4 "Library\\modulus\\inverse.hpp" // mod must be prime. template struct inverse { using value_type = modint; value_type operator()(int n) const { assert(n %= mod); if(n < 0) n += mod; for(int m(inv.size()); m <= n; ++m) inv.emplace_back(mod / m * -inv[mod % m]); return inv[n]; } private: static std::vector inv; }; template <> struct inverse<0> { using value_type = modint_runtime; value_type operator()(int n) const { int_fast64_t mod = value_type::mod(); assert(n %= mod); if(n < 0) n += mod; if(inv.empty()) inv = {1, mod != 1}; for(int m(inv.size()); m <= n; ++m) inv.emplace_back(mod / m * -inv[mod % m]); return inv[n]; } private: static std::vector inv; }; template std::vector> inverse::inv = {1, 1}; std::vector inverse<0>::inv; using inverse_runtime = inverse<0>; #line 5 "Library\\combinatorics\\binomial.hpp" template struct binomial { using value_type = modint; struct mulinv_Op { inverse &inv; value_type operator()(value_type f, size_t n) const { return f * inv(n); } }; static inverse inv; static factorial invfact; static factorial fact; value_type operator()(int n, int k) { return invfact(k) * invfact(n - k) * fact(n); } }; template inverse binomial::inv; template factorial, class binomial::mulinv_Op> binomial::invfact{1, mulinv_Op{binomial::inv}}; template factorial> binomial::fact; #line 18 "t.cpp" struct workspace::solver { // start here! using mint=modint<1000000007>; binomial<1000000007> bi; solver() { i64 k,n; cin>>n>>k; mint ans; for(int i=0;i