#ifdef TODAY_KYOPRO /* */ void run() { II(Q); rep(q, Q) { II(t); switch(t) { case 1: { II(A, B); say(A + B); } case 2: say(q + 1); } } } #else // #define MULTI //------>8-------- begin kyopro_library/template.hpp --------->8------ //------>8------ begin kyopro_library/base/include.hpp ------->8------ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //------>8------- end kyopro_library/base/include.hpp -------->8------ //------>8-------- begin kyopro_library/base/type.hpp -------->8------ using i8 = int8_t; using i16 = short; using i32 = int; using i64 = long long; using i128 = __int128_t; using u16 = unsigned short; using u32 = unsigned int; using u64 = unsigned long long; using u128 = __uint128_t; using f64 = double; using f80 = long double; using ii = i64; using ll = i64; using ull = u64; using vi = vector; using vvi = vector>; using vvvi = vector>>; using vl = vector; using vvl = vector>; using vvvl = vector>>; using ii3 = array; using ii4 = array; using ii5 = array; using lll = i128; using ulll = u128; using ld = f80; using str = string; using vstr = vector; constexpr ii operator""_ii(ull x) { return static_cast(x); } constexpr lll operator""_lll(ull x) { return static_cast(x); } template using V = vector; template using VV = vector>; template using VVV = vector>>; template using VVVV = vector>>>; template using VVVVV = vector>>>>; template using VVVVVV = vector>>>>>; template using max_pq = priority_queue; template using min_pq = priority_queue, greater>; template using unset = unordered_set; template using unmap = unordered_map; template struct PR : pair { template PR(Args... args) : pair(args...) {} using pair::first; using pair::second; PR& operator+=(const PR& r) { first += r.first; second += r.second; return *this; } PR& operator-=(const PR& r) { first -= r.first; second -= r.second; return *this; } PR& operator*=(const PR& r) { first *= r.first; second *= r.second; return *this; } template PR& operator+=(const S& r) { first += r; second += r; return *this; } template PR& operator-=(const S& r) { first -= r; second -= r; return *this; } template PR& operator*=(const S& r) { first *= r; second *= r; return *this; } PR operator+(const PR& r) const { return PR(*this) += r; } PR operator-(const PR& r) const { return PR(*this) -= r; } PR operator*(const PR& r) const { return PR(*this) *= r; } template PR operator+(const S& r) const { return PR(*this) += r; } template PR operator-(const S& r) const { return PR(*this) -= r; } template PR operator*(const S& r) const { return PR(*this) *= r; } PR operator-() const { return PR{-first, -second}; } }; using pi = PR; using vpi = vector; using vvpi = vector>; using pl = PR; using vpl = vector; using vvpl = vector>; template struct TR : tuple { using tuple::tuple; T& x = get<0>(*this); U& y = get<1>(*this); V& z = get<2>(*this); TR() : tuple() {} TR(const T& a, const U& b, const V& c) : tuple(a, b, c) {} TR(const TR& other) : tuple(other), x(get<0>(*this)), y(get<1>(*this)), z(get<2>(*this)) {} TR(TR&& other) noexcept : tuple(move(other)), x(get<0>(*this)), y(get<1>(*this)), z(get<2>(*this)) {} TR& operator=(const TR& other) { tuple::operator=(other); return *this; } TR& operator=(TR&& other) noexcept { tuple::operator=(move(other)); return *this; } }; using ti = TR; using vti = vector; using vvti = vector>; using tl = TR; using vtl = vector; using vvtl = vector>; const i32 INF = 1e9 + 10; const i64 INFL = 4e18; const i128 INFLL = 1_lll << 120; template constexpr T inf = 0; template <> constexpr i32 inf = INF; template <> constexpr i64 inf = INFL; template <> constexpr i128 inf = INFLL; template <> constexpr u32 inf = INF; template <> constexpr u64 inf = INFL; template <> constexpr u128 inf = INFLL; template <> constexpr f64 inf = numeric_limits::infinity(); template <> constexpr f80 inf = numeric_limits::infinity(); istream& operator>>(istream& is, lll& x) { int c = is.peek(); while(c == ' ' || c == '\n') is.get(), c = is.peek(); bool neg = false; if(c == '-') neg = true, is.get(); x = 0; while(isdigit(is.peek())) x = x * 10 + is.get() - '0'; if(neg) x = -x; return is; } ostream& operator<<(ostream& os, lll x) { if(x < 0) os << '-', x = -x; if(x == 0) return os << '0'; string s; while(x > 0) s += char('0' + x % 10), x /= 10; reverse(s.begin(), s.end()); return os << s; } #ifdef TDY lll abs(lll x) { if(x < 0) return -x; return x; } lll gcd(lll a, lll b) { while(b) a %= b, swap(a, b); return a; } #endif //------>8--------- end kyopro_library/base/type.hpp --------->8------ //------>8------- begin kyopro_library/base/fastio.hpp ------->8------ #include #include #include #include #include /// @brief 高速入出力 (fread/fwrite ベース)。cin/cout を透過的に置換する /// @note 既存の input()/say/line/put/operator<< やマクロ・生 cin/cout がそのまま高速化される。 /// @note 未対応の型 (modint/fraction/set/deque など) は同一バッファを共有する /// std ストリームへフォールバックするため、書式・順序は従来と一致する。 /// @note operator>>/<< の本体は fastio_impl.hpp で定義する。フォールバック時に io.hpp の /// グローバル operator<< (tuple/set/deque/array など) を通常の名前検索で見つけるため、 /// template.hpp が io.hpp を include した後に fastio_impl.hpp を include する。 /// @attention using namespace std 前提で裸の cin/cout を使うこと。std::cin / std::cout と /// 完全修飾で書くと #define により壊れる。 namespace FastIO { /// @brief pair (および PR など pair 派生型) を判定するコンセプト template void pair_probe(const pair&); template concept PairLike = requires(const T& t) { pair_probe(t); }; template struct is_vec : false_type {}; template struct is_vec> : true_type {}; template struct is_vec2 : false_type {}; template struct is_vec2>> : true_type {}; template struct is_vec3 : false_type {}; template struct is_vec3>>> : true_type {}; /// @brief fread で stdin をチャンク読みする streambuf struct Reader : streambuf { static constexpr int SZ = 1 << 18; char buf[SZ]; Reader() { setg(buf, buf, buf); } /// @note fread ではなく read(2) を使う。fread はバッファが満杯 (or EOF) になるまで /// block するため、応答が1行ずつ来るインタラクティブ問題でデッドロックする。 int_type underflow() override { ssize_t n; do n = ::read(0, buf, SZ); while(n < 0 && errno == EINTR); if(n <= 0) { setg(buf, buf, buf); return traits_type::eof(); } setg(buf, buf, buf + n); return traits_type::to_int_type(buf[0]); } /// @brief 1 文字取得して進める (EOF は -1) int gc() { return this->sbumpc(); } /// @brief 空白を読み飛ばし、最初の非空白文字を返す (消費済み) int skip_ws() { int c = gc(); while(c == ' ' || c == '\n' || c == '\r' || c == '\t') c = gc(); return c; } template void read_int(T& x) { int c = skip_ws(); bool neg = false; if constexpr(is_signed_v) { if(c == '-') neg = true, c = gc(); } T v = 0; while(c >= '0' && c <= '9') v = v * 10 + (c - '0'), c = gc(); if constexpr(is_signed_v) { if(neg) v = -v; } x = v; } void read_i128(lll& x) { int c = skip_ws(); bool neg = false; if(c == '-') neg = true, c = gc(); ulll v = 0; while(c >= '0' && c <= '9') v = v * 10 + (ulll)(c - '0'), c = gc(); x = neg ? -(lll)v : (lll)v; } void read_u128(ulll& x) { int c = skip_ws(); ulll v = 0; while(c >= '0' && c <= '9') v = v * 10 + (ulll)(c - '0'), c = gc(); x = v; } void read_char(char& ch) { ch = (char)skip_ws(); } void read_str(string& s) { s.clear(); int c = skip_ws(); while(c != -1 && c != ' ' && c != '\n' && c != '\r' && c != '\t') s += (char)c, c = gc(); } template void read_float(F& x) { static string t; read_str(t); x = (F)strtold(t.c_str(), nullptr); } }; /// @brief fwrite で stdout へ書き出す streambuf struct Writer : streambuf { static constexpr int SZ = 1 << 18; char buf[SZ]; Writer() { setp(buf, buf + SZ); } ~Writer() { flush(); } /// @note write(2) で fd 1 へ直接書く。libc バッファを挟まないので flush() が即座に /// ジャッジへ届き、インタラクティブ問題でそのまま使える。 void flush() { char* p = pbase(); size_t len = pptr() - p; while(len > 0) { ssize_t w = ::write(1, p, len); if(w < 0) { if(errno == EINTR) continue; break; } p += w, len -= w; } setp(buf, buf + SZ); } int_type overflow(int_type c) override { flush(); if(c != traits_type::eof()) *pptr() = (char)c, pbump(1); return c; } int sync() override { flush(); return 0; } void pc(char c) { this->sputc(c); } void ps(const char* s, int n) { this->sputn(s, n); } template void write_int(T x) { using U = make_unsigned_t; U u; bool neg = false; if constexpr(is_signed_v) { if(x < 0) neg = true, u = U(0) - (U)x; else u = (U)x; } else u = (U)x; char t[24]; int n = 0; do t[n++] = (char)('0' + int(u % 10)), u /= 10; while(u); if(neg) pc('-'); while(n) pc(t[--n]); } void write_i128(lll x) { bool neg = x < 0; ulll u = neg ? (ulll)0 - (ulll)x : (ulll)x; char t[40]; int n = 0; do t[n++] = (char)('0' + int(u % 10)), u /= 10; while(u); if(neg) pc('-'); while(n) pc(t[--n]); } void write_u128(ulll u) { char t[40]; int n = 0; do t[n++] = (char)('0' + int(u % 10)), u /= 10; while(u); while(n) pc(t[--n]); } void write_float(long double x) { char t[64]; int n = snprintf(t, sizeof(t), "%.15Lf", x); ps(t, n); } }; /// @brief 高速入力ラッパ (cin を置換)。未対応型は fb (std::istream) にフォールバック struct FastIn { Reader rd; istream fb{&rd}; template FastIn& operator>>(T& x); // 本体は fastio_impl.hpp /// @brief std::ws などのマニピュレータ (テンプレート関数のため専用オーバーロードが必要) FastIn& operator>>(istream& (*f)(istream&)) { f(fb); return *this; } template void tie(T) {} }; /// @brief 高速出力ラッパ (cout を置換)。未対応型は fb (std::ostream) にフォールバック struct FastOut { Writer wt; ostream fb{&wt}; FastOut() { fb << fixed << setprecision(15); } void flush() { wt.flush(); } template void write_vec1(const vector& a) { int n = a.size(); for(int i = 0; i < n; i++) { *this << a[i]; if(i != n - 1) wt.pc(' '); } } template void write_vec2(const vector>& a) { int I = a.size(); for(int i = 0; i < I; i++) { int J = a[i].size(); for(int j = 0; j < J; j++) { *this << a[i][j]; if(j != J - 1) wt.pc(' '); } if(i != I - 1) wt.pc('\n'); } } template void write_vec3(const vector>>& a) { int I = a.size(); for(int i = 0; i < I; i++) { int J = a[i].size(); for(int j = 0; j < J; j++) { int K = a[i][j].size(); for(int k = 0; k < K; k++) { *this << a[i][j][k]; if(k != K - 1) wt.pc(' '); } wt.pc('\n'); } if(i != I - 1) wt.pc('\n'); } } template FastOut& operator<<(const T& x); // 本体は fastio_impl.hpp /// @brief std::endl / std::flush / std::ends などのマニピュレータ FastOut& operator<<(ostream& (*f)(ostream&)) { f(fb); return *this; } }; inline FastIn in; inline FastOut out; } // namespace FastIO #define cin FastIO::in #define cout FastIO::out //------>8-------- end kyopro_library/base/fastio.hpp -------->8------ //------>8---- begin kyopro_library/base/fastio_impl.hpp ----->8------ /// @brief FastIn/FastOut の operator 本体。io.hpp より後に include し、フォールバック時に /// io.hpp のグローバル operator>>/<< (tuple/set/deque/array など) を名前検索で解決する。 /// @note modint/fraction/geo などの friend 演算子は ADL で解決されるため include 順に依らない。 namespace FastIO { template FastIn& FastIn::operator>>(T& x) { if constexpr(is_same_v) rd.read_char(x); else if constexpr(is_same_v) fb >> x; else if constexpr(is_same_v) rd.read_i128(x); else if constexpr(is_same_v) rd.read_u128(x); else if constexpr(is_integral_v) rd.read_int(x); else if constexpr(is_floating_point_v) rd.read_float(x); else if constexpr(is_same_v) rd.read_str(x); else if constexpr(is_vec::value) for(auto& e : x) *this >> e; else if constexpr(PairLike) *this >> x.first, *this >> x.second; else fb >> x; return *this; } template FastOut& FastOut::operator<<(const T& x) { using D = decay_t; if constexpr(is_same_v) wt.pc(x); else if constexpr(is_same_v) wt.pc(x ? '1' : '0'); else if constexpr(is_same_v) wt.write_i128(x); else if constexpr(is_same_v) wt.write_u128(x); else if constexpr(is_integral_v) wt.write_int(x); else if constexpr(is_floating_point_v) wt.write_float((long double)x); else if constexpr(is_same_v) wt.ps(x.data(), (int)x.size()); else if constexpr(is_same_v || is_same_v) wt.ps(x, (int)strlen(x)); else if constexpr(is_vec3::value) write_vec3(x); else if constexpr(is_vec2::value) write_vec2(x); else if constexpr(is_vec::value) write_vec1(x); else if constexpr(PairLike) { *this << x.first; wt.pc(' '); *this << x.second; } else fb << x; return *this; } } // namespace FastIO //------>8----- end kyopro_library/base/fastio_impl.hpp ------>8------ //------>8------- begin kyopro_library/base/macro.hpp -------->8------ #define rep1(n) for(ii i = 0; i < (n); i++) #define rep2(i, n) for(ii i = 0; i < (n); i++) #define rep3(i, a, b) for(ii i = (a); i < (b); i++) #define rep4(i, a, b, c) for(ii i = (a); i < (b); i += (c)) #define rep_overload(a, b, c, d, e, ...) e #define rep(...) rep_overload(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define per1(n) for(ii i = (n) - 1; i >= 0; i--) #define per2(i, n) for(ii i = (n) - 1; i >= 0; i--) #define per3(i, a, b) for(ii i = (b) - 1; i >= (a); i--) #define per4(i, a, b, c) for(ii i = (b) - 1; i >= (a); i -= (c)) #define per_overload(a, b, c, d, e, ...) e #define per(...) per_overload(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__) #define fore(x, a) for(auto& x : a) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define QYN(q, a, b) ((q) ? (a) : (b)) #define pb push_back #define eb emplace_back #define mkp make_pair #define mkt make_tuple #define fi first #define se second #define dov(v, f) \ [&]() { \ auto&& _v = (v); \ for(auto& x : _v) \ f(x); \ }() #define mkv(v, f) \ [&]() { \ auto&& _v = (v); \ using Type = std::decay_t; \ std::vector ret; \ ret.reserve(_v.size()); \ for(const auto& x : _v) \ ret.push_back(f(x)); \ return ret; \ }() #define II(...) \ ii __VA_ARGS__; \ input(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ input(__VA_ARGS__) #define LLL(...) \ lll __VA_ARGS__; \ input(__VA_ARGS__) #define IDX(...) \ ii __VA_ARGS__; \ input(__VA_ARGS__); \ input_index(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ input(__VA_ARGS__); #define CHR(...) \ char __VA_ARGS__; \ input(__VA_ARGS__); #define LD(...) \ ld __VA_ARGS__; \ input(__VA_ARGS__); #define VI(A, N) \ vector A(N); \ input(A); #define VVI(A, N, M) \ vector> A(N, vector(M)); \ input(A); #define VL(A, N) \ vector A(N); \ input(A); #define VVL(A, N, M) \ vector> A(N, vector(M)); \ input(A); #define VPI(A, N) \ vpi A(N); \ input(A); #define VTI(A, N) \ vti A(N); \ input(A); #define VI2(A, B, N) \ vector A(N), B(N); \ rep(i, N) cin >> A[i] >> B[i]; #define VL2(A, B, N) \ vector A(N), B(N); \ rep(i, N) cin >> A[i] >> B[i]; #define VI3(A, B, C, N) \ vector A(N), B(N), C(N); \ rep(i, N) cin >> A[i] >> B[i] >> C[i]; #define VL3(A, B, C, N) \ vector A(N), B(N), C(N); \ rep(i, N) cin >> A[i] >> B[i] >> C[i]; #define VST(A, N) \ vector A(N); \ input(A); #define IN2(A, B) rep(i, siz(A)) cin >> A[i] >> B[i]; #define IN3(A, B, C) rep(i, siz(A)) cin >> A[i] >> B[i] >> C[i]; #define IN4(A, B, C, D) rep(i, siz(A)) cin >> A[i] >> B[i] >> C[i] >> D[i]; #define IN5(A, B, C, D, E) \ rep(i, siz(A)) cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i]; //------>8-------- end kyopro_library/base/macro.hpp --------->8------ //------>8--------- begin kyopro_library/base/io.hpp --------->8------ const char NL = '\n'; void flush() { cout.flush(); } const string Yes = "Yes"; const string No = "No"; const string YES = "YES"; const string NO = "NO"; const string ALICE = "Alice"; const string BOB = "Bob"; const string FIRST = "First"; const string SECOND = "Second"; inline string YesNo(bool f) { return f ? Yes : No; } inline string YESNO(bool f) { return f ? YES : NO; } inline string AliBo(bool f) { return f ? ALICE : BOB; } inline string FiSe(bool f) { return f ? FIRST : SECOND; } template istream& operator>>(istream& is, vector>& v) { for(auto& x : v) for(auto& y : x) is >> y; return is; } template istream& operator>>(istream& is, vector& v) { for(auto& x : v) is >> x; return is; } template istream& operator>>(istream& is, pair& p) { is >> p.first >> p.second; return is; } template void input(T&... a) { (cin >> ... >> a); } template void input_index(T& a) { a--; } template void input_index(T& a, Ts&... b) { a--; input_index(b...); } template ostream& operator<<(ostream& os, const pair& p) { os << p.fi << ' ' << p.se; return os; } template ostream& operator<<(ostream& os, const PR& p) { os << p.fi << ' ' << p.se; return os; } template ostream& operator<<(ostream& os, const tuple& t) { os << ' ' << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t); return os; } template ostream& operator<<(ostream& os, const TR& t) { os << ' ' << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t); return os; } template ostream& operator<<(ostream& os, const tuple& t) { os << ' ' << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t) << ' ' << get<3>(t); return os; } template ostream& operator<<(ostream& os, const vector>>& a) { int I = a.size(); for(int i = 0; i < I; i++) { int J = a[i].size(); for(int j = 0; j < J; j++) { int K = a[i][j].size(); for(int k = 0; k < K; k++) { os << a[i][j][k]; if(k != K - 1) os << ' '; } os << NL; } if(i != I - 1) os << NL; } return os; } template ostream& operator<<(ostream& os, const vector>& a) { int I = a.size(); for(int i = 0; i < I; i++) { int J = a[i].size(); for(int j = 0; j < J; j++) { os << a[i][j]; if(j != J - 1) os << ' '; } if(i != I - 1) cout << NL; } return os; } template ostream& operator<<(ostream& os, const vector& a) { int n = a.size(); for(int i = 0; i < n; i++) { os << a[i]; if(i != n - 1) os << ' '; } return os; } template ostream& operator<<(ostream& os, const set& a) { for(auto itr = a.begin(); itr != a.end(); itr++) { os << *itr; if(next(itr) != a.end()) os << ' '; } return os; } template ostream& operator<<(ostream& os, const multiset& a) { for(auto itr = a.begin(); itr != a.end(); itr++) { os << *itr; if(next(itr) != a.end()) os << ' '; } return os; } template ostream& operator<<(ostream& os, const deque& a) { for(auto itr = a.begin(); itr != a.end(); itr++) { os << *itr; if(next(itr) != a.end()) os << ' '; } return os; } template ostream& operator<<(ostream& os, queue a) { while(!a.empty()) { os << a.front(); a.pop(); if(a.size()) os << ' '; } return os; } template ostream& operator<<(ostream& os, priority_queue a) { while(!a.empty()) { os << a.top(); a.pop(); if(a.size()) os << ' '; } return os; } template ostream& operator<<(ostream& os, priority_queue, greater> a) { while(!a.empty()) { os << a.top(); a.pop(); if(a.size()) os << ' '; } return os; } template ostream& operator<<(ostream& os, array a) { for(int i = 0; i < N; i++) { os << a[i]; if(i != N - 1) os << ' '; } return os; } template void put(const T& a, const Ts&... b) { cout << a; (void)(cout << ... << b); } template void line(const T& a, const Ts&... b) { cout << a; (void)(cout << ... << (cout << ' ', b)); cout << ' '; } void say() { cout << '\n'; } template void say(const T& a, const Ts&... b) { cout << a; (void)(cout << ... << (cout << ' ', b)); cout << NL; } void esay() { #ifdef TDY flush(); cerr << NL; #endif } template void esay(const T& a, const Ts&... b) { #ifdef TDY flush(); cerr << a; (void)(cerr << ... << (cerr << ' ', b)); cerr << NL; #endif } #define O(...) \ { \ say(__VA_ARGS__); \ return; \ } //------>8---------- end kyopro_library/base/io.hpp ---------->8------ //------>8-------- begin kyopro_library/base/util.hpp -------->8------ template A amin(A a, B b) { if(a > b) return b; return a; } template A amax(A a, B b) { if(a < b) return b; return a; } template bool chmin(A& a, B b) { if(a > b) { a = b; return true; } return false; } template bool chmax(A& a, B b) { if(a < b) { a = b; return true; } return false; } template A myfloor(A a, B b) { assert(b != 0); if(b < 0) a = -a, b = -b; return a / b - (a % b < 0); } template A myceil(A a, B b) { assert(b != 0); if(b < 0) a = -a, b = -b; return a / b + (a % b > 0); } template A mymod(A a, B b) { assert(b != 0); if(b < 0) b = -b; if(a > 0) return a % b; return (a % b + b) % b; } // コンテナに対する関数 template inline ii siz(const T& v) { return v.size(); } template T minv(const vector& v) { if(v.empty()) return inf; return *min_element(all(v)); } template T maxv(const vector& v) { if(v.empty()) return -inf; return *max_element(all(v)); } template T sumv(const vector& v) { return reduce(v.begin(), v.end()); } template ii minidx(const vector& v) { return min_element(all(v)) - v.begin(); } template ii maxidx(const vector& v) { return max_element(all(v)) - v.begin(); } template ii lob(const vector& v, const T& x) { return lower_bound(all(v), x) - v.begin(); } template ii upb(const vector& v, const T& x) { return upper_bound(all(v), x) - v.begin(); } template ii findv(const vector& v, const T& x) { for(ii i = 0; i < siz(v); i++) if(v[i] == x) return i; return siz(v); } template ii find_lastv(const vector& v, const T& x) { for(ii i = siz(v) - 1; i >= 0; i--) if(v[i] == x) return i; return -1; } template void doso(T& v) { sort(v.begin(), v.end()); } template T mkso(const T& v) { auto w = v; doso(w); return w; } template void dosor(T& v) { sort(v.rbegin(), v.rend()); } template T mksor(const T& v) { auto w = v; dorsort(w); return w; } template void douniq(vector& v) { sort(all(v)); v.erase(unique(v.begin(), v.end()), v.end()); } template V mkuniq(const V& v) { auto w = v; douniq(w); return w; } template vector mkcomp(vector v) { auto w = v; douniq(w); for(T& x : v) x = lob(w, x); return v; } ii countv(const auto& a, auto v) { return count(a.begin(), a.end(), v); } void doinsert(auto& a, ii idx, auto v) { assert(idx <= siz(a)); a.insert(a.begin() + idx, v); } void doerase(auto& a, ii idx) { assert(idx < siz(a)); a.erase(a.begin() + idx); } // 先頭をoffset個分後ろに void dorotateback(auto& a, ii offset) { offset %= siz(a); rotate(a.begin(), a.end() - offset, a.end()); } // 末尾をoffset個分前の方に void dorotatefront(auto& a, ii offset) { offset %= siz(a); rotate(a.begin(), a.begin() + offset, a.end()); } auto mkinsert(const auto& a, ii idx, auto v) { auto b = a; insertv(b, idx, v); return b; } auto mkerase(const auto& a, ii idx) { auto b = a; erasev(b, idx); return b; } auto mkpush(const auto& a, auto v) { auto b = a; b.push_back(v); return b; } template V mkslice(const V& a, ii l, ii r) { assert(l <= r && l >= 0 && r <= siz(a)); V b(a.begin() + l, a.begin() + r); return b; } template V mkconcat(const V& a, const V& b) { auto ret = a; ret.reserve(siz(a) + siz(b)); for(auto x : b) ret.push_back(x); return ret; } template void doconcat(V& a, const V& b) { for(auto x : b) a.push_back(x); } template vector> zip(const vector& a, const vector& b) { ii n = siz(a); vector> ret(n); for(ii i = 0; i < n; i++) ret[i] = {a[i], b[i]}; return ret; } template vector> zip(const vector& a, const vector& b, const vector& c) { ii n = siz(a); vector> ret(n); for(ii i = 0; i < n; i++) ret[i] = {a[i], b[i], c[i]}; return ret; } template PR, vector> unzip(const vector>& p) { ii n = siz(p); vector reta(n); vector retb(n); for(ii i = 0; i < n; i++) { reta[i] = p[i].first; retb[i] = p[i].second; } return mkp(reta, retb); } template TR, vector, vector> unzip(const vector>& p) { ii n = siz(p); vector reta(n); vector retb(n); vector retc(n); for(ii i = 0; i < n; i++) { auto [a, b, c] = p[i]; reta[i] = a; retb[i] = b; retc[i] = c; } return mkt(reta, retb, retc); } template T pick(max_pq& v) { T ret = v.top(); v.pop(); return ret; } template T pick(min_pq& v) { T ret = v.top(); v.pop(); return ret; } template T pick(queue& v) { T ret = v.front(); v.pop(); return ret; } template T pick(vector& v) { T ret = v.back(); v.pop_back(); return ret; } template T pickf(deque& v) { T ret = v.front(); v.pop_front(); return ret; } template T pickb(deque& v) { T ret = v.back(); v.pop_back(); return ret; } template bool nxperm(T& v) { return next_permutation(v.begin(), v.end()); } // 前置インクリメント (++v) template V& operator++(V& a) { for(auto& x : a) ++x; return a; } // 後置インクリメント (v++) template V operator++(V& a, int) { V res = a; ++a; return res; } // 前置デクリメント (--v) template V& operator--(V& a) { for(auto& x : a) --x; return a; } // 後置デクリメント (v--) template V operator--(V& a, int) { V res = a; --a; return res; } // 演算子オーバーロードを一括定義するマクロ #define DEFINE_VECTOR_OP(OP) \ /* V OP= スカラー */ \ template \ V& operator OP##=(V& a, const U & b) { \ for(auto& x : a) x OP## = b; \ return a; \ } \ /* V OP= V (ベクトル同士) */ \ template \ V& operator OP##=(V& a, const V& b) { \ assert(a.size() == b.size()); \ for(ii i = 0; i < a.size(); i++) a[i] OP## = b[i]; \ return a; \ } \ /* V OP スカラー */ \ template \ V operator OP(V a, const U & b) { \ a OP## = b; \ return a; \ } \ /* スカラー OP V */ \ template \ V operator OP(const U & a, V b) { \ for(auto& x : b) x = a OP x; \ return b; \ } \ /* V OP V (ベクトル同士) */ \ template \ V operator OP(V a, const V& b) { \ a OP## = b; \ return a; \ } DEFINE_VECTOR_OP(+) DEFINE_VECTOR_OP(-) DEFINE_VECTOR_OP(*) DEFINE_VECTOR_OP(/) DEFINE_VECTOR_OP(%) DEFINE_VECTOR_OP(&) DEFINE_VECTOR_OP(|) DEFINE_VECTOR_OP(^) #undef DEFINE_VECTOR_OP template V mkvec(ii n, T init) { return V(n, init); } template auto mkvec(ii n, Ts... ts) { return V(n, mkvec(ts...)); } template vector mksum(const vector& v) { ii n = v.size(); vector ret(n + 1); for(ii i = 0; i < n; i++) ret[i + 1] = ret[i] + v[i]; return ret; } template vector mkpmax(const vector& v) { ii n = v.size(); vector ret(n + 1, -inf); for(ii i = 0; i < n; i++) ret[i + 1] = max(ret[i], v[i]); return ret; } template vector mkpmin(const vector& v) { ii n = v.size(); vector ret(n + 1, inf); for(ii i = 0; i < n; i++) ret[i + 1] = min(ret[i], v[i]); return ret; } template vector mksmax(const vector& v) { ii n = v.size(); vector ret(n + 1, -inf); for(ii i = n - 1; i >= 0; i--) ret[i] = max(ret[i + 1], v[i]); return ret; } template vector mksmin(const vector& v) { ii n = v.size(); vector ret(n + 1, inf); for(ii i = n - 1; i >= 0; i--) ret[i] = min(ret[i + 1], v[i]); return ret; } vi mkiota(ii n) { vi ret(n); iota(ret.begin(), ret.end(), 0); return ret; } template T mkrev(T A) { reverse(A.begin(), A.end()); return A; } template void dorev(T& A) { reverse(A.begin(), A.end()); } template vi mkinv(const V& A) { ii n = siz(A); vi ret(maxv(A) + 1); for(ii i = 0; i < n; i++) ret[A[i]] = i; return ret; } template vvi mkinvvec(const V& A) { ii n = siz(A); vvi ret(maxv(A) + 1); for(ii i = 0; i < n; i++) ret[A[i]].push_back(i); return ret; } template vi mkfreq(const V& A) { ii n = siz(A); vi ret(maxv(A) + 1); for(ii i = 0; i < n; i++) ret[A[i]]++; return ret; } template vi argsort(const V& A) { vi idx = mkiota(siz(A)); sort(idx.begin(), idx.end(), [&](ii i, ii j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); }); return idx; } template ii digit_siz(T n) { ii ret = 0; while(n) { ret++; n /= 10; } return ret; } template vector digits(T n) { vector ret; while(n) { ret.push_back(n % 10); n /= 10; } reverse(ret.begin(), ret.end()); return ret; } template T intpow(T x, T r) { T ret = 1; while(r) { if(r & 1) ret *= x; x *= x; r >>= 1; } return ret; } i64 tenpow(ii r) { i64 ret = 1; while(r--) ret *= 10; return ret; } template T intsqrt(T x) { i64 sq = (T)sqrtl(ld(x)); while(sq * sq > x) sq--; while((sq + 1) * (sq + 1) <= x) sq++; return sq; } template T euc_dist(auto ax, auto ay, auto bx, auto by) { return T(ax - bx) * (ax - bx) + T(ay - by) * (ay - by); } template T man_dist(auto ax, auto ay, auto bx, auto by) { return abs(T(ax) - bx) + abs(T(ay) - by); } ii lotoi(char c) { assert('a' <= c && c <= 'z'); return c - 'a'; } char itolo(ii i) { assert(0 <= i && i <= 25); return char('a' + i); } ii hitoi(char c) { assert('A' <= c && c <= 'Z'); return c - 'A'; } char itohi(ii i) { assert(0 <= i && i <= 25); return char('A' + i); } ii ctoi(char c) { assert('0' <= c && c <= '9'); return c - '0'; } char itoc(ii i) { assert(0 <= i && i <= 9); return char('0' + i); } vi stov(const str& s, char base = 'a') { vi ret(s.size()); rep(i, s.size()) ret[i] = s[i] - base; return ret; } str vtos(const vi& a, char base = 'a') { str ret; rep(i, a.size()) ret.push_back(char(base + a[i])); return ret; } ii popcount(i32 n) { return __builtin_popcount(n); } ii popcount(i64 n) { return __builtin_popcountll(n); } ii parity(i32 n) { return __builtin_parity(n); } ii parity(i64 n) { return __builtin_parityll(n); } // 最上位ビットの位置 ii topbit(i32 n) { return n ? 31 - __builtin_clz(n) : -1; } ii topbit(i64 n) { return n ? 63 - __builtin_clzll(n) : -1; } // 2進表現の長さ ii bitsiz(i32 n) { return n ? 32 - __builtin_clz(n) : 1; } ii bitsiz(i64 n) { return n ? 64 - __builtin_clzll(n) : 1; } // 最下位ビットの位置 ii bottombit(i32 n) { return n ? __builtin_ctz(n) : -1; } ii bottombit(i64 n) { return n ? __builtin_ctzll(n) : -1; } bool ispower2(i32 n) { return n && (n & -n) == n; } ll mkmask(ii n) { return (1LL << n) - 1; } bool hasbit(i64 n, ii i) { return (n >> i & 1); } vi mksubset(ii s) { vi ret; ii t = s; do { ret.push_back(t); --t &= s; } while(t != s); return ret; } string tobinary(i64 n, ii len = 32, bool rev = false) { string ret; for(ii i = 0; i < len; i++) ret += (hasbit(n, rev ? len - 1 - i : i) ? '1' : '0'); return ret; } //------>8--------- end kyopro_library/base/util.hpp --------->8------ void run(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); #ifdef MULTI II(T); rep(t, T) { #ifdef TDY esay("============ Case: #", t + 1, " ============"); #endif run(); } #else run(); #endif } #ifdef DEBUG #include "./debug.hpp" #else #define debug(...) #define print_line #endif //------>8--------- end kyopro_library/template.hpp ---------->8------ // #include #define TODAY_KYOPRO #include __FILE__ #endif // a.cpp // 2026-07-31 23:08:16