#line 1 "other/y.cc" /* * @file template.cpp * @brief Template */ #include #line 2 "Library/lib/alias" /* * @file alias * @brief Alias */ #line 13 "Library/lib/alias" namespace workspace { constexpr char eol = '\n'; using namespace std; using i32 = int_least32_t; using i64 = int_least64_t; using i128 = __int128_t; using u32 = uint_least32_t; using u64 = uint_least64_t; using u128 = __uint128_t; template > using priority_queue = std::priority_queue, Comp>; template using stack = std::stack>; } // namespace workspace #line 2 "Library/lib/cxx20" /* * @file cxx20 * @brief C++20 Features */ #if __cplusplus <= 201703L #include namespace std { /* * @fn erase_if * @brief Erase the elements of a container that do not satisfy the condition. * @param __cont Container. * @param __pred Predicate. * @return Number of the erased elements. */ template inline typename vector<_Tp, _Alloc>::size_type erase_if( vector<_Tp, _Alloc>& __cont, _Predicate __pred) { const auto __osz = __cont.size(); __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), __cont.end()); return __osz - __cont.size(); } /* * @fn erase * @brief Erase the elements of a container that are equal to the given value. * @param __cont Container. * @param __value Value. * @return Number of the erased elements. */ template inline typename vector<_Tp, _Alloc>::size_type erase( vector<_Tp, _Alloc>& __cont, const _Up& __value) { const auto __osz = __cont.size(); __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), __cont.end()); return __osz - __cont.size(); } } // namespace std #endif #line 2 "Library/lib/option" /* * @file option * @brief Optimize Options */ #ifdef ONLINE_JUDGE #pragma GCC optimize("O3") #pragma GCC target("avx,avx2") #pragma GCC optimize("unroll-loops") #endif #line 2 "Library/src/utils/binary_search.hpp" /* * @file binary_search.hpp * @brief Binary Search */ #if __cplusplus >= 201703L #include #include #include namespace workspace { /* * @fn binary_search * @brief binary search on a discrete range. * @param ok pred(ok) is true * @param ng pred(ng) is false * @param pred the predicate * @return the closest point to (ng) where pred is true */ template std::enable_if_t< std::is_convertible_v, bool>, iter_type> binary_search(iter_type ok, iter_type ng, pred_type pred) { assert(ok != ng); std::make_signed_t dist(ng - ok); while (1 < dist || dist < -1) { iter_type mid(ok + dist / 2); if (pred(mid)) ok = mid, dist -= dist / 2; else ng = mid, dist /= 2; } return ok; } /* * @fn parallel_binary_search * @brief parallel binary search on discrete ranges. * @param ends a vector of pairs; pred(first) is true, pred(second) is false * @param pred the predicate * @return the closest points to (second) where pred is true */ template std::enable_if_t>, std::vector>, std::vector> parallel_binary_search(std::vector> ends, pred_type pred) { std::vector mids(ends.size()); for (;;) { bool all_found = true; for (size_t i{}; i != ends.size(); ++i) { auto [ok, ng] = ends[i]; iter_type mid(ok + (ng - ok) / 2); if (mids[i] != mid) { all_found = false; mids[i] = mid; } } if (all_found) break; auto res = pred(mids); for (size_t i{}; i != ends.size(); ++i) { (res[i] ? ends[i].first : ends[i].second) = mids[i]; } } return mids; } /* * @fn binary_search * @brief binary search on the real number line. * @param ok pred(ok) is true * @param ng pred(ng) is false * @param eps the error tolerance * @param pred the predicate * @return the boundary point */ template std::enable_if_t< std::is_convertible_v, bool>, real_type> binary_search(real_type ok, real_type ng, const real_type eps, pred_type pred) { assert(ok != ng); for (auto loops = 0; loops != std::numeric_limits::digits && (ok + eps < ng || ng + eps < ok); ++loops) { real_type mid{(ok + ng) / 2}; (pred(mid) ? ok : ng) = mid; } return ok; } /* * @fn parallel_binary_search * @brief parallel binary search on the real number line. * @param ends a vector of pairs; pred(first) is true, pred(second) is false * @param eps the error tolerance * @param pred the predicate * @return the boundary points */ template std::enable_if_t>, std::vector>, std::vector> parallel_binary_search(std::vector> ends, const real_type eps, pred_type pred) { std::vector mids(ends.size()); for (auto loops = 0; loops != std::numeric_limits::digits; ++loops) { bool all_found = true; for (size_t i{}; i != ends.size(); ++i) { auto [ok, ng] = ends[i]; if (ok + eps < ng || ng + eps < ok) { all_found = false; mids[i] = (ok + ng) / 2; } } if (all_found) break; auto res = pred(mids); for (size_t i{}; i != ends.size(); ++i) { (res[i] ? ends[i].first : ends[i].second) = mids[i]; } } return mids; } } // namespace workspace #endif #line 2 "Library/src/utils/chval.hpp" /* * @file chval.hpp * @brief Change Less/Greater */ #line 9 "Library/src/utils/chval.hpp" namespace workspace { /* * @fn chle * @brief Substitute y for x if comp(y, x) is true. * @param x Reference * @param y Const reference * @param comp Compare function * @return Whether or not x is updated */ template > bool chle(Tp &x, const Tp &y, Comp comp = Comp()) { return comp(y, x) ? x = y, true : false; } /* * @fn chge * @brief Substitute y for x if comp(x, y) is true. * @param x Reference * @param y Const reference * @param comp Compare function * @return Whether or not x is updated */ template > bool chge(Tp &x, const Tp &y, Comp comp = Comp()) { return comp(x, y) ? x = y, true : false; } } // namespace workspace #line 2 "Library/src/utils/clock.hpp" /* * @fn clock.hpp * @brief Clock */ #line 9 "Library/src/utils/clock.hpp" namespace workspace { using namespace std::chrono; namespace internal { // The start time of the program. const auto start_time{system_clock::now()}; } // namespace internal /* * @fn elapsed * @return elapsed time of the program */ int64_t elapsed() { const auto end_time{system_clock::now()}; return duration_cast(end_time - internal::start_time).count(); } } // namespace workspace #line 2 "Library/src/utils/ejection.hpp" /* * @file ejection.hpp * @brief Ejection */ #line 9 "Library/src/utils/ejection.hpp" namespace workspace { /* * @brief eject from a try block, throw nullptr * @param arg output */ template void eject(Tp const &arg) { std::cout << arg << "\n"; throw nullptr; } } // namespace workspace #line 2 "Library/src/utils/exponential_search.hpp" /* * @file exponential_search.hpp * @brief Exponential Search */ #line 9 "Library/src/utils/exponential_search.hpp" #if __cplusplus >= 201703L namespace workspace { /* * @fn exponential_search * @brief Exponential search on a discrete range. * @param range Range of search, exclusive * @param pred Predicate * @return The minimum non-negative integer where pred is false. */ template std::enable_if_t< std::is_convertible_v, bool>, size_type> exponential_search(size_type range, pred_type pred) { size_type step(1); while (step < range && pred(step)) step <<= 1; if (range < step) step = range; return binary_search(size_type(0), step, pred); } /* * @fn exponential_search * @brief Exponential search on the real number line. * @param range Range of search * @param eps Error tolerance * @param pred Predicate * @return The boundary point. */ template std::enable_if_t< std::is_convertible_v, bool>, real_type> exponential_search(real_type range, const real_type eps, pred_type pred) { real_type step(1); while (step < range && pred(step)) step += step; if (range < step) step = range; return binary_search(real_type(0), step, eps, pred); } } // namespace workspace #endif #line 2 "Library/src/utils/fixed_point.hpp" /* * @file fixed_point.hpp * @brief Fixed Point Combinator */ #line 9 "Library/src/utils/fixed_point.hpp" namespace workspace { /* * @class fixed_point * @brief Recursive calling of lambda expression. */ template class fixed_point { lambda_type func; public: /* * @param func 1st arg callable with the rest of args, and the return type * specified. */ fixed_point(lambda_type &&func) : func(std::move(func)) {} /* * @brief Recursively apply *this to 1st arg of func. * @param args Arguments of the recursive method. */ template auto operator()(Args &&... args) const { return func(*this, std::forward(args)...); } }; } // namespace workspace #line 6 "Library/src/utils/hash.hpp" #line 2 "Library/src/utils/sfinae.hpp" /* * @file sfinae.hpp * @brief SFINAE */ #line 10 "Library/src/utils/sfinae.hpp" #include namespace workspace { template class trait> using enable_if_trait_type = typename std::enable_if::value>::type; template using element_type = typename std::decay()))>::type; template struct has_begin : std::false_type {}; template struct has_begin()), nullptr)> : std::true_type {}; template struct mapped_of { using type = element_type; }; template struct mapped_of::first_type> { using type = typename T::mapped_type; }; template using mapped_type = typename mapped_of::type; template struct is_integral_ext : std::false_type {}; template struct is_integral_ext< T, typename std::enable_if::value>::type> : std::true_type {}; template <> struct is_integral_ext<__int128_t> : std::true_type {}; template <> struct is_integral_ext<__uint128_t> : std::true_type {}; #if __cplusplus >= 201402 template constexpr static bool is_integral_ext_v = is_integral_ext::value; #endif template struct multiplicable_uint { using type = uint_least32_t; }; template struct multiplicable_uint::type> { using type = uint_least64_t; }; template struct multiplicable_uint::type> { using type = __uint128_t; }; } // namespace workspace #line 8 "Library/src/utils/hash.hpp" namespace workspace { template struct hash : std::hash {}; #if __cplusplus >= 201703L template struct hash> { size_t operator()(uint64_t x) const { static const uint64_t m = std::random_device{}(); x ^= x >> 23; x ^= m; x ^= x >> 47; return x - (x >> 32); } }; #endif template size_t hash_combine(const size_t &seed, const Key &key) { return seed ^ (hash()(key) + 0x9e3779b9 /* + (seed << 6) + (seed >> 2) */); } template struct hash> { size_t operator()(const std::pair &pair) const { return hash_combine(hash()(pair.first), pair.second); } }; template class hash> { template ::value - 1> struct tuple_hash { static uint64_t apply(const Tuple &t) { return hash_combine(tuple_hash::apply(t), std::get(t)); } }; template struct tuple_hash { static uint64_t apply(const Tuple &t) { return 0; } }; public: uint64_t operator()(const std::tuple &t) const { return tuple_hash>::apply(t); } }; template struct hash_table_wrapper : hash_table { using key_type = typename hash_table::key_type; size_t count(const key_type &key) const { return hash_table::find(key) != hash_table::end(); } template auto emplace(Args &&... args) { return hash_table::insert(typename hash_table::value_type(args...)); } }; template using cc_hash_table = hash_table_wrapper<__gnu_pbds::cc_hash_table>>; template using gp_hash_table = hash_table_wrapper<__gnu_pbds::gp_hash_table>>; template using unordered_map = std::unordered_map>; template using unordered_set = std::unordered_set>; } // namespace workspace #line 2 "Library/src/utils/io/casefmt.hpp" /* * @file castfmt * @brief Case Output Format */ #line 2 "Library/src/utils/iterate_case.hpp" /* * @file iterate_case.hpp * @brief Iterate Testcases */ namespace workspace { namespace internal { // The 1-based index of the current testcase. unsigned caseid; } // namespace internal void main(); unsigned case_number(); /* * @fn iterate_main * @brief Iterate main function. */ void iterate_main() { for (unsigned total = case_number(), &counter = (internal::caseid = 1); counter <= total; ++counter) { try { main(); } catch (std::nullptr_t) { } } } } // namespace workspace #line 9 "Library/src/utils/io/casefmt.hpp" namespace workspace { /* * @fn casefmt * @brief printf("Case #%u: ", internal::caseid) * @param os Reference to ostream * @return os */ std::ostream& casefmt(std::ostream& os) { return os << "Case #" << internal::caseid << ": "; } } // namespace workspace #line 2 "Library/src/utils/io/istream.hpp" /* * @file stream.hpp * @brief Input Stream */ #include #line 13 "Library/src/utils/io/istream.hpp" #line 15 "Library/src/utils/io/istream.hpp" namespace workspace { /* * @class istream * @brief A wrapper class for std::istream. */ class istream : public std::istream { template struct helper { helper(std::istream &is, Tp &x) { if constexpr (has_begin::value) for (auto &&e : x) helper(is, e); else static_assert(has_begin::value, "istream unsupported type."); } }; template struct helper< Tp, decltype(std::declval() >> std::declval())>>(), nullptr)> { helper(std::istream &is, Tp &x) { is >> x; } }; template struct helper> { helper(std::istream &is, std::pair &x) { helper(is, x.first), helper(is, x.second); } }; template struct helper> { helper(std::istream &is, std::tuple &x) { iterate(is, x); } private: template void iterate(std::istream &is, Tp &x) { if constexpr (N == std::tuple_size::value) return; else helper::type>(is, std::get(x)), iterate(is, x); } }; public: template istream &operator>>(Tp &x) { helper(*this, x); if (std::istream::fail()) { static auto once = atexit([] { std::cerr << "\n\033[43m\033[30mwarning: failed to read \'" << abi::__cxa_demangle(typeid(Tp).name(), 0, 0, 0) << "\'.\033[0m\n\n"; }); assert(!once); } return *this; } }; namespace internal { auto *const cin_ptr = (istream *)&std::cin; } auto &cin = *internal::cin_ptr; } // namespace workspace #line 2 "Library/src/utils/io/ostream.hpp" /* * @file ostream.hpp * @brief Output Stream */ #line 10 "Library/src/utils/io/ostream.hpp" namespace workspace { template std::ostream &operator<<(std::ostream &os, const std::pair &p) { return os << p.first << ' ' << p.second; } template struct tuple_os { static std::ostream &apply(std::ostream &os, const tuple_t &t) { tuple_os::apply(os, t); return os << ' ' << std::get(t); } }; template struct tuple_os { static std::ostream &apply(std::ostream &os, const tuple_t &t) { return os << std::get<0>(t); } }; template struct tuple_os { static std::ostream &apply(std::ostream &os, const tuple_t &t) { return os; } }; template std::ostream &operator<<(std::ostream &os, const std::tuple &t) { return tuple_os, std::tuple_size>::value - 1>::apply(os, t); } template ()))> typename std::enable_if< !std::is_same::type, std::string>::value && !std::is_same::type, char *>::value, std::ostream &>::type operator<<(std::ostream &os, const Container &cont) { bool head = true; for (auto &&e : cont) head ? head = 0 : (os << ' ', 0), os << e; return os; } } // namespace workspace #line 3 "Library/src/utils/io/read.hpp" namespace workspace { namespace internal { struct cast_read { template operator T() const { T value; workspace::cin >> value; return value; } }; } // namespace internal /* * @fn read * @tparam Tp The type of input. * @brief Read from stdin. */ template auto read() { typename std::remove_const::type value; cin >> value; return value; } /* * @fn read * @brief Read from stdin on type casting. */ template <> auto read() { return internal::cast_read(); } } // namespace workspace #line 2 "Library/src/utils/io/setup.hpp" /* * @file setup.hpp * @brief I/O Setup */ #line 10 "Library/src/utils/io/setup.hpp" namespace workspace { /* * @fn io_setup * @brief Setup I/O before main process. */ __attribute__((constructor)) void io_setup() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); #ifdef _buffer_check atexit([] { char bufc; if (std::cin >> bufc) std::cerr << "\n\033[43m\033[30mwarning: buffer not empty.\033[0m\n\n"; }); #endif } } // namespace workspace #line 2 "Library/src/utils/make_vector.hpp" /* * @file make_vector.hpp * @brief Multi-dimensional Vector */ #if __cplusplus >= 201703L #include #include namespace workspace { /* * @brief Make a multi-dimensional vector. * @tparam Tp type of the elements * @tparam N dimension * @tparam S integer type * @param sizes The size of each dimension * @param init The initial value */ template constexpr auto make_vector(S* sizes, Tp const& init = Tp()) { static_assert(std::is_convertible_v); if constexpr (N) return std::vector(*sizes, make_vector(std::next(sizes), init)); else return init; } /* * @brief Make a multi-dimensional vector. * @param sizes The size of each dimension * @param init The initial value */ template constexpr auto make_vector(const S (&sizes)[N], Tp const& init = Tp()) { return make_vector((S*)sizes, init); } /* * @brief Make a multi-dimensional vector. * @param sizes The size of each dimension * @param init The initial value */ template constexpr auto make_vector(std::array const& sizes, Tp const& init = Tp()) { static_assert(std::is_convertible_v); if constexpr (I == N) return init; else return std::vector(sizes[I], make_vector(sizes, init)); } /* * @brief Make a multi-dimensional vector. * @param sizes The size of each dimension * @param init The initial value */ template constexpr auto make_vector(std::tuple const& sizes, Tp const& init = Tp()) { using tuple_type = std::tuple; if constexpr (I == std::tuple_size_v || I == N) return init; else { static_assert( std::is_convertible_v, size_t>); return std::vector(std::get(sizes), make_vector(sizes, init)); } } /* * @brief Make a multi-dimensional vector. * @param sizes The size of each dimension * @param init The initial value */ template constexpr auto make_vector(std::pair const& sizes, Tp const& init = Tp()) { static_assert(std::is_convertible_v); static_assert(std::is_convertible_v); return make_vector({(size_t)sizes.first, (size_t)sizes.second}, init); } } // namespace workspace #endif #line 3 "Library/src/utils/random_number_generator.hpp" template class random_number_generator { typename std::conditional::value, std::uniform_int_distribution, std::uniform_real_distribution>::type unif; std::mt19937 engine; public: random_number_generator(num_type min = std::numeric_limits::min(), num_type max = std::numeric_limits::max()) : unif(min, max), engine(std::random_device{}()) {} num_type min() const { return unif.min(); } num_type max() const { return unif.max(); } // generate a random number in [min(), max()]. num_type operator()() { return unif(engine); } }; #line 2 "Library/src/utils/round_div.hpp" /* * @file round_div.hpp * @brief Round Integer Division */ #line 9 "Library/src/utils/round_div.hpp" #line 11 "Library/src/utils/round_div.hpp" namespace workspace { /* * @fn floor_div * @brief floor of fraction. * @param x the numerator * @param y the denominator * @return maximum integer z s.t. z <= x / y * @note y must be nonzero. */ template constexpr typename std::enable_if<(is_integral_ext::value && is_integral_ext::value), typename std::common_type::type>::type floor_div(T1 x, T2 y) { assert(y != 0); if (y < 0) x = -x, y = -y; return x < 0 ? (x - y + 1) / y : x / y; } /* * @fn ceil_div * @brief ceil of fraction. * @param x the numerator * @param y the denominator * @return minimum integer z s.t. z >= x / y * @note y must be nonzero. */ template constexpr typename std::enable_if<(is_integral_ext::value && is_integral_ext::value), typename std::common_type::type>::type ceil_div(T1 x, T2 y) { assert(y != 0); if (y < 0) x = -x, y = -y; return x < 0 ? x / y : (x + y - 1) / y; } } // namespace workspace #line 4 "Library/src/utils/trinary_search.hpp" // trinary search on discrete range. template iter_type trinary(iter_type first, iter_type last, comp_type comp) { assert(first < last); intmax_t dist(last - first); while(dist > 2) { iter_type left(first + dist / 3), right(first + dist * 2 / 3); if(comp(left, right)) last = right, dist = dist * 2 / 3; else first = left, dist -= dist / 3; } if(dist > 1 && comp(first + 1, first)) ++first; return first; } // trinary search on real numbers. template long double trinary(long double first, long double last, const long double eps, comp_type comp) { assert(first < last); while(last - first > eps) { long double left{(first * 2 + last) / 3}, right{(first + last * 2) / 3}; if(comp(left, right)) last = right; else first = left; } return first; } #line 2 "Library/src/utils/wrapper.hpp" template class reversed { Container &ref, copy; public: constexpr reversed(Container &ref) : ref(ref) {} constexpr reversed(Container &&ref = Container()) : ref(copy), copy(ref) {} constexpr auto begin() const { return ref.rbegin(); } constexpr auto end() const { return ref.rend(); } constexpr operator Container() const { return ref; } }; #line 12 "other/y.cc" int main() { workspace::iterate_main(); } unsigned workspace::case_number() { // return -1; // unspecified // unsigned t; cin >> t, cin.ignore(); return t; // given return 1; } #line 2 "Library/src/combinatorics/binomial.hpp" /* * @file binomial.hpp * @brief Binomial Coefficient */ #line 2 "Library/src/modular/inverse.hpp" /* * @file inverse.hpp * @brief Inverse Table */ #line 9 "Library/src/modular/inverse.hpp" #line 2 "Library/src/modular/modint.hpp" /* * @file modint.hpp * @brief Modular Arithmetic */ #line 10 "Library/src/modular/modint.hpp" #line 12 "Library/src/modular/modint.hpp" namespace workspace { namespace internal { /* * @struct modint_base * @brief base of modular arithmetic. * @tparam Mod identifier, which represents modulus if positive */ template struct modint_base { static_assert(is_integral_ext::value, "Mod must be integral type."); using mod_type = typename std::conditional<0 < Mod, typename std::add_const::type, decltype(Mod)>::type; static mod_type mod; using value_type = typename std::decay::type; constexpr operator value_type() const noexcept { return value; } constexpr static modint_base one() noexcept { return 1; } constexpr modint_base() noexcept = default; template ::value>::type * = nullptr> constexpr modint_base(int_type n) noexcept : value((n %= mod) < 0 ? mod + n : n) {} constexpr modint_base(bool n) noexcept : modint_base(int(n)) {} constexpr modint_base operator++(int) noexcept { modint_base t{*this}; return operator+=(1), t; } constexpr modint_base operator--(int) noexcept { modint_base t{*this}; return operator-=(1), t; } constexpr modint_base &operator++() noexcept { return operator+=(1); } constexpr modint_base &operator--() noexcept { return operator-=(1); } constexpr modint_base operator-() const noexcept { return value ? mod - value : 0; } constexpr modint_base &operator+=(const modint_base &rhs) noexcept { return (value += rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint_base &operator-=(const modint_base &rhs) noexcept { return (value += mod - rhs.value) < mod ? 0 : value -= mod, *this; } constexpr modint_base &operator*=(const modint_base &rhs) noexcept { return value = (typename multiplicable_uint::type)value * rhs.value % mod, *this; } constexpr modint_base &operator/=(const modint_base &rhs) noexcept { return operator*=(rhs.inverse()); } template constexpr typename std::enable_if::value, modint_base>::type operator+(const int_type &rhs) const noexcept { return modint_base{*this} += rhs; } constexpr modint_base operator+(const modint_base &rhs) const noexcept { return modint_base{*this} += rhs; } template constexpr typename std::enable_if::value, modint_base>::type operator-(const int_type &rhs) const noexcept { return modint_base{*this} -= rhs; } constexpr modint_base operator-(const modint_base &rhs) const noexcept { return modint_base{*this} -= rhs; } template constexpr typename std::enable_if::value, modint_base>::type operator*(const int_type &rhs) const noexcept { return modint_base{*this} *= rhs; } constexpr modint_base operator*(const modint_base &rhs) const noexcept { return modint_base{*this} *= rhs; } template constexpr typename std::enable_if::value, modint_base>::type operator/(const int_type &rhs) const noexcept { return modint_base{*this} /= rhs; } constexpr modint_base operator/(const modint_base &rhs) const noexcept { return modint_base{*this} /= rhs; } template constexpr friend typename std::enable_if::value, modint_base>::type operator+(const int_type &lhs, const modint_base &rhs) noexcept { return modint_base(lhs) + rhs; } template constexpr friend typename std::enable_if::value, modint_base>::type operator-(const int_type &lhs, const modint_base &rhs) noexcept { return modint_base(lhs) - rhs; } template constexpr friend typename std::enable_if::value, modint_base>::type operator*(const int_type &lhs, const modint_base &rhs) noexcept { return modint_base(lhs) * rhs; } template constexpr friend typename std::enable_if::value, modint_base>::type operator/(const int_type &lhs, const modint_base &rhs) noexcept { return modint_base(lhs) / rhs; } constexpr modint_base 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}; } template constexpr typename std::enable_if::value, modint_base>::type power(int_type e) noexcept { return pow(*this, e); } template friend constexpr typename std::enable_if::value, modint_base>::type pow(modint_base b, int_type e) noexcept { modint_base res{1}; for (e < 0 ? b = b.inverse(), e = -e : 0; e; e >>= 1, b *= b) if (e & 1) res *= b; return res; } friend std::ostream &operator<<(std::ostream &os, const modint_base &rhs) noexcept { return os << rhs.value; } friend std::istream &operator>>(std::istream &is, modint_base &rhs) noexcept { intmax_t value; rhs = (is >> value, value); return is; } protected: value_type value = 0; }; template typename modint_base::mod_type modint_base::mod = Mod; } // namespace internal /* * @typedef modint * @brief modular arithmetic. * @tparam Mod modulus */ template 0)>::type * = nullptr> using modint = internal::modint_base; /* * @typedef modint_runtime * @brief runtime modular arithmetic. * @tparam type_id uniquely assigned */ template using modint_runtime = internal::modint_base<-(signed)type_id>; // #define modint_newtype modint_runtime<__COUNTER__> } // namespace workspace #line 11 "Library/src/modular/inverse.hpp" namespace workspace { // Modulus must be prime. template struct inverse_table { static_assert(std::is_same::value); using value_type = Modint; constexpr value_type operator()(int n) const { constexpr 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_table::inv; } // namespace workspace #line 4 "Library/src/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 11 "Library/src/combinatorics/binomial.hpp" namespace workspace { template struct binomial; template struct binomial { static_assert(std::is_same::value); using value_type = Modint; struct mulinv_Op { value_type operator()(const value_type &f, const size_t &n) const { return f * inv(n); } }; static inverse_table inv; static factorial fact_inv; static factorial fact; value_type operator()(int_least32_t n, int_least32_t k) { return fact_inv(k) * fact_inv(n - k) * fact(n); } }; template inverse_table binomial::inv; template factorial::mulinv_Op> binomial::fact_inv; template factorial binomial::fact; } // namespace workspace #line 22 "other/y.cc" namespace workspace { using mint = modint<998244353>; binomial bn; void main() { // start here! mint n; cin >> n; mint ans, np{1}; for (auto m = 0; m <= n - 2; ++m) { ans += np * bn(n, m + 2) * bn.fact(n - m - 2) * bn(n - 2, m); np *= n; } (ans /= np) *= n; cout << ans << eol; } } // namespace workspace