#include #include using namespace std; using ll = long long int; using u64 = unsigned long long; using pll = pair; // #include // using namespace atcoder; #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define REPrev(i, a, b) for (ll i = (a); i >= (b); i--) #define ALL(coll) (coll).begin(), (coll).end() #define SIZE(v) ((ll)((v).size())) #define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n" // @@ !! LIM(unordered_map power) // ---- inserted library file unordered_map.cc /* This code is based on https://codeforces.com/blog/entry/62393 */ /* #include using namespace __gnu_pbds; */ template struct safe_custom_hash; // For integer types (int, ll, u64, unsigned, ....) template struct safe_custom_hash::value>::type> { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // For string template <> struct safe_custom_hash { static uint64_t mix(uint64_t x) { x += 0x9e3779b97f4a7c15ULL; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL; x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL; return x ^ (x >> 31); } size_t operator()(const string& s) const { static const uint64_t seed = chrono::steady_clock::now().time_since_epoch().count(); uint64_t h = seed ^ 0x9e3779b97f4a7c15ULL; const unsigned char* p = (const unsigned char*)s.data(); size_t n = s.size(); while (n >= 8) { uint64_t v; memcpy(&v, p, 8); h = mix(h ^ v); p += 8; n -= 8; } uint64_t tail = 0; for (size_t i = 0; i < n; ++i) tail |= uint64_t(p[i]) << (8*i); h = mix(h ^ tail); return (size_t)h; } }; template using my_umap = unordered_map>; template using my_uset = unordered_set>; template using my_umultiset = unordered_multiset>; // ---- end unordered_map.cc // ---- inserted library file algOp.cc // Common definitions // zero, one, inverse template const T zero(const T& t) { if constexpr (is_integral_v || is_floating_point_v) { return (T)0; } else { return t.zero(); } } template const T one(const T& t) { if constexpr (is_integral_v || is_floating_point_v) { return (T)1; } else { return t.one(); } } template const T inverse(const T& t) { if constexpr (is_floating_point_v) { return 1.0 / t; } else { return t.inverse(); } } #ifdef BOOST_MP_CPP_INT_HPP template<> const cpp_int zero(const cpp_int& t) { return cpp_int(0); } template<> const cpp_int one(const cpp_int& t) { return cpp_int(1); } #endif // BOOST_MP_CPP_INT_HPP // begin -- detection ideom // cf. https://blog.tartanllama.xyz/detection-idiom/ namespace tartan_detail { template