#ifdef __LOCAL #include // プリコンパイル済みヘッダ ~/local/include/mytemplate.hpp.gch #else #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif using namespace std; // #pragma GCC target "no-avx" // gcc12.2のバグ回避用。boost使用時はコメントアウトの事 // #include // using bint = boost::multiprecision::cpp_int; using int128 = __int128_t; using ll = long long; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vd = vector; using vvd = vector; using vc = vector; using vvc = vector; using pll = pair; #define REP1(i, n) REP3(i, 0, n, 1) #define REP2(i, s, n) REP3(i, s, n, 1) #define REP3(i, s, n, d) for(ll i = (ll)(s); i < (ll)(n); i += (d)) #define REP_OVERLOAD(e1, e2, e3, e4, NAME,...) NAME #define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define DEP1(i, n) DEP3(i, n, -1, 1) #define DEP2(i, n, s) DEP3(i, n, s, 1) #define DEP3(i, n, s, d) for(ll i = (ll)(n); (ll)(s) < i; i -= (d)) #define DEP_OVERLOAD(e1, e2, e3, e4, NAME,...) NAME #define dep(...) DEP_OVERLOAD(__VA_ARGS__, DEP3, DEP2, DEP1)(__VA_ARGS__) #define fore(e, a) for (auto&& e: (a)) #define len(a) (ll)(a).size() #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define eb emplace_back #define fi first #define se second #define th third /********* C O N S T A N T **********/ constexpr ll INF = LONG_LONG_MAX / 2 - 10000LL; // 4,611,686,018,427,377,903 ~= 4.6e+18, 19桁 const double PI = acos(-1); /********* P A I R **********/ template inline pair& operator+=(pair& a, const pair b); template inline pair& operator-=(pair& a, const pair b); template inline pair& operator*=(pair& a, const pair b); template inline pair& operator/=(pair& a, const pair b); template inline pair& operator%=(pair& a, const pair b); template inline pair& operator+=(pair& a, const V b); template inline pair& operator-=(pair& a, const V b); template inline pair& operator*=(pair& a, const V b); template inline pair& operator/=(pair& a, const V b); template inline pair& operator%=(pair& a, const V b); template inline pair operator+(pair a, const V& b); template inline pair operator-(pair a, const V& b); template inline pair operator*(pair a, const V& b); template inline pair operator/(pair a, const V& b); template inline pair operator%(pair a, const V& b); template inline pair operator+(pair a); template inline pair operator-(pair a); template istream& operator >>(istream& stream, pair& a); template ostream& operator <<(ostream &stream, const pair& a); /********* V E C T O R **********/ template inline vector& operator+=(vector& a, const vector b); template inline vector& operator-=(vector& a, const vector b); template inline vector& operator*=(vector& a, const vector b); template inline vector& operator/=(vector& a, const vector b); template inline vector& operator%=(vector& a, const vector b); template inline vector& operator+=(vector& a, const U b); template inline vector& operator-=(vector& a, const U b); template inline vector& operator*=(vector& a, const U b); template inline vector& operator/=(vector& a, const U b); template inline vector& operator%=(vector& a, const U b); template inline vector operator+(vector a, const U& b); template inline vector operator-(vector a, const U& b); template inline vector operator*(vector a, const U& b); template inline vector operator/(vector a, const U& b); template inline vector operator%(vector a, const U& b); template inline vector operator+(vector a); template inline vector operator-(vector a); template istream& operator >>(istream& stream, vector& a); template ostream& operator <<(ostream& stream, const vector& v); template ostream& operator <<(ostream& stream, const vector>& vv); template inline T Sum(const vector& v) {return reduce(all(v));} // v.size() == 0 のとき T() を返す template inline T Max(const vector& v) {assert(v.size()); return *max_element(all(v));} template inline T Min(const vector& v) {assert(v.size()); return *min_element(all(v));} template inline ll Argmax(const vector& v) {assert(v.size()); return max_element(all(v)) - v.begin();} template inline ll Argmin(const vector& v) {assert(v.size()); return min_element(all(v)) - v.begin();} template inline bool Contains(const vector& v, const U& a) {return find(all(v), a) != v.end();} template inline void Unique(vector& v) {sort(all(v)); v.erase(unique(all(v)), v.end());} // ソートされたユニーク値のvectorに書き換える, O(NlogN). template vector make_vector(int n, U v) { return vector(n, v); } template auto make_vector(int n, Args... args) {auto val = make_vector(args...); return make_vector(n, move(val));} /********* S E T **********/ template istream& operator >>(istream& stream, set& st); template ostream& operator <<(ostream& stream, const set& st); template inline T Max(const set& st) {assert(st.size()); return *prev(st.end());} template inline T Min(const set& st) {assert(st.size()); return *st.begin();} /********* M U L T I S E T **********/ template istream& operator >>(istream& stream, multiset& st); template ostream& operator <<(ostream& stream, const multiset& st); template inline T Max(const multiset& st) {assert(st.size()); return *prev(st.end());} template inline T Min(const multiset& st) {assert(st.size()); return *st.begin();} template inline bool EraseOne(multiset& st, T x) {auto it=st.find(x); if (it!=st.end()) {st.erase(it); return true;} else return false;} // 要素xを1つ削除. 消せたらtrueを返す. /********* S T R I N G **********/ inline string ToUpper(const string& s) {string t; t.resize(s.size()); std::transform(all(s), t.begin(), ::toupper); return t; } inline string ToLower(const string& s) {string t; t.resize(s.size()); std::transform(all(s), t.begin(), ::tolower); return t; } inline char ToUpper(const char& c) {string s{c}, t; t.resize(s.size()); std::transform(all(s), t.begin(), ::toupper); return t[0]; } inline char ToLower(const char& c) {string s{c}, t; t.resize(s.size()); std::transform(all(s), t.begin(), ::tolower); return t[0]; } inline bool IsUpper(const char& c) {return isupper(c) > 0; } inline bool IsLower(const char& c) {return islower(c) > 0; } /********* T R I O **********/ template struct trio { T1 first; T2 second; T3 third; // コンストラクタ・代入演算子 trio() {first=T1(); second=T2(); third=T3();} trio(const T1& x) : first(x), second(x), third(x) {} trio(const T1& x, const T2& y, const T3& z) : first(x), second(y), third(z) {} trio(const trio& t) {first=t.first; second=t.second; third=t.third;} // コピーコンストラクタ trio& operator =(const trio& t) {first=t.first; second=t.second; third=t.third; return *this;} // 比較演算子 auto operator <=>(const trio&) const = default; // 単項演算子(+ -) trio operator +() const { return *this; } trio operator -() const { return (-1) * (*this); } // 複合代入演算子 trio& operator +=(const trio& t) {first += t.first; second += t.second; third += t.third; return *this;} trio& operator -=(const trio& t) {first -= t.first; second -= t.second; third -= t.third; return *this;} trio& operator *=(const trio& t) {first *= t.first; second *= t.second; third *= t.third; return *this;} trio& operator /=(const trio& t) {first /= t.first; second /= t.second; third /= t.third; return *this;} trio& operator %=(const trio& t) {first %= t.first; second %= t.second; third %= t.third; return *this;} // 算術演算子 friend trio operator +(const trio& lhs, const trio& rhs) {return trio(lhs) += rhs;} friend trio operator -(const trio& lhs, const trio& rhs) {return trio(lhs) -= rhs;} friend trio operator *(const trio& lhs, const trio& rhs) {return trio(lhs) *= rhs;} friend trio operator /(const trio& lhs, const trio& rhs) {return trio(lhs) /= rhs;} friend trio operator %(const trio& lhs, const trio& rhs) {return trio(lhs) %= rhs;} // 入出力 template friend istream& operator >>(istream&, trio&); template friend ostream& operator <<(ostream&, const trio&); operator tuple() {return tie(first, second, third);} }; using tll = trio; /********* Q U A R T E T **********/ template struct quartet { T1 first; T2 second; T3 third; T4 fourth; // コンストラクタ・代入演算子 quartet() {first=T1(); second=T2(); third=T3(); fourth=T4();} quartet(const T1& x) : first(x), second(x), third(x), fourth(x) {} quartet(const T1& x, const T2& y, const T3& z, const T4& w) : first(x), second(y), third(z), fourth(w) {} quartet(const quartet& t) {first=t.first; second=t.second; third=t.third; fourth=t.fourth;} // コピーコンストラクタ quartet& operator =(const quartet& t) {first=t.first; second=t.second; third=t.third; fourth=t.fourth; return *this;} // 比較演算子 auto operator <=>(const quartet&) const = default; // 単項演算子(+ -) quartet operator +() const { return *this; } quartet operator -() const { return (-1) * (*this); } // 複合代入演算子 quartet& operator +=(const quartet& t) {first += t.first; second += t.second; third += t.third; fourth += t.fourth; return *this;} quartet& operator -=(const quartet& t) {first -= t.first; second -= t.second; third -= t.third; fourth -= t.fourth; return *this;} quartet& operator *=(const quartet& t) {first *= t.first; second *= t.second; third *= t.third; fourth *= t.fourth; return *this;} quartet& operator /=(const quartet& t) {first /= t.first; second /= t.second; third /= t.third; fourth /= t.fourth; return *this;} quartet& operator %=(const quartet& t) {first %= t.first; second %= t.second; third %= t.third; fourth %= t.fourth; return *this;} // 算術演算子 friend quartet operator +(const quartet& lhs, const quartet& rhs) {return quartet(lhs) += rhs;} friend quartet operator -(const quartet& lhs, const quartet& rhs) {return quartet(lhs) -= rhs;} friend quartet operator *(const quartet& lhs, const quartet& rhs) {return quartet(lhs) *= rhs;} friend quartet operator /(const quartet& lhs, const quartet& rhs) {return quartet(lhs) /= rhs;} friend quartet operator %(const quartet& lhs, const quartet& rhs) {return quartet(lhs) %= rhs;} // 入出力 template friend istream& operator >>(istream&, quartet&); template friend ostream& operator <<(ostream&, const quartet&); operator tuple() {return tie(first, second, third, fourth);} }; using qll = quartet; /********* R A N D O M **********/ struct Random { mt19937_64 rnd; Random() { random_device seed_gen; rnd.seed(seed_gen()); } Random(ll seed) { rnd.seed(seed); } ll randint(ll a, ll b) { // [a, b] uniform_int_distribution dist(a, b); return dist(rnd); } double randreal(double a, double b) { uniform_real_distribution dist(a, b); return dist(rnd); } char randchar(char a, char b) { // [a, b] uniform_int_distribution dist(a, b); return dist(rnd); } template void shuffle(vector& vec) { std::shuffle(all(vec), rnd); } }; /********* T I M E R **********/ struct Timer { int time_limit; int start_time; Timer(double time_limit_sec) { assert(time_limit_sec > 0); this->time_limit = time_limit_sec * CLOCKS_PER_SEC; this->start_time = clock(); } bool is_time_up() const { return clock() - this->start_time >= this->time_limit; } double get_elapsed_ratio() const { double ratio = 1.0 * (clock() - this->start_time) / (this->time_limit - this->start_time); return min(1.0, ratio); } }; /********* P R I N T **********/ template inline void print(const T& e); template inline void print(const H& h, const T&... t); template inline void End(const T&... t); /********* D E B U G **********/ #ifdef __LOCAL #define debug(...) if(DEBUG) do{cout << '[' << #__VA_ARGS__ << "] ";debug_(__VA_ARGS__);}while(0) #else #define debug(...) #endif void dbg_(const long long& e); template void dbg_(const T& e); template void dbg_(const pair& p); template void dbg_(const trio& t); template void dbg_(const quartet& t); template void debug_(const T& e); template void debug_(const vector& v); template void debug_(const vector>& vv); template void debug_(const map& mp); template void debug_(const vector>& vm); template void debug_(const set& st); template void debug_(const multiset& st); template void debug_(const vector>& vs); template void debug_(const vector>& vs); template void debug_(const H& h, const T&... t); /********* O T H E R S **********/ template inline bool chmin(T& a, U b) {if (a > b) {a = b; return true;} return false;} // bは値渡し! template inline bool chmax(T& a, U b) {if (a < b) {a = b; return true;} return false;} template inline auto Mod(const T& a, const U& m) {return (a % m + m) % m;} // 負もOK template inline auto Ceil(const T& x, const U& y) {return x < 0 ? x/y : (x + y - 1) / y;} // 負もOK template inline auto Floor(const T& x, const U& y) {return -(Ceil(-x, y)); } // 負もOK inline ll Isqrt(ll n) {assert(n >= 0); ll x = round(sqrt(n)); while(x * x > n) --x; return x;} inline ll Comb(ll n, ll r) {if (r < 0 || n < r) return 0; r = min(r, n - r); ll ret = 1; rep(i, r) {ret *= n - i; ret /= i + 1;} return ret;} // n=60, r=30までOK template inline T Pow(T x, ll n) {assert(n >= 0); T ret = 1; while(1) {if (n % 2) ret *= x; n /= 2; if(!n) return ret; x = x * x;}} // べき乗 mintもOK template inline T Aseries(T a, T d, ll n) {assert(n >= 0); return a * n + n * (n - 1) / 2 * d;} // 等差級数 mintもOK template inline T Gseries(T a, T r, ll n) {assert(n >= 0); if (r == 1) return a * n; else return a * (1 - Pow(r, n)) / (1 - r);} // 等比級数 mintもOK template using min_priority_queue = priority_queue, greater>; inline bool Bit(ll b, int i) {assert(0 <= i && i < 64); return (b >> i) & 1;} inline ll Popcount(ll b) {return __builtin_popcountll(b);} inline ll Mask(ll n) {assert(0 <= n && n < 63); return (1LL << n) - 1LL;} // [0, n)のbitが立った64bit整数を返す。 inline ll Mask(ll n, ll m) {assert(n >= m); return Mask(n) ^ Mask(m);} // [m, n)のbitが立った64bit整数を返す。 inline void PrintYesNo(bool b) {b ? print("Yes") : print("No");} /********* M O D **********/ // #include // https://atcoder.github.io/ac-library/production/document_ja/ // using namespace atcoder; // using mint = modint998244353; // modint1000000007; // istream& operator >>(istream& stream, mint& e) {ll n; stream >> n; e = n; return stream; } // ostream& operator <<(ostream& stream, const mint& e) { stream << e.val(); return stream; } // using vm = vector; // using vvm = vector; /***************************************/ constexpr bool DEBUG = true; // 区間の集合を管理 struct IntervalSet { map mp; // mp[r] = l for [l, r) IntervalSet() {} // 区間の個数 ll size() const { return len(mp); } // 区間[l, r)を挿入. 返り値: 更新有無 bool insert(ll l, ll r) { assert(l <= r); if (l == r) return false; auto it = mp.lower_bound(l); // 更新不要時の処理 if (it != mp.end() && (*it).se <= l && r <= (*it).fi) return false; // [l, r)と重なる区間を全て削除し、区間[l2, r2)を挿入 ll l2 = l; ll r2 = r; while(it != mp.end() && (*it).se <= r) { chmin(l2, (*it).se); chmax(r2, (*it).fi); it = mp.erase(it); } mp[r2] = l2; return true; } // 区間[x, x + 1)を挿入. 返り値: 更新有無 bool insert(ll x) { return insert(x, x + 1); } // 区間[l, r)を削除. 返り値: 更新有無 bool erase(ll l, ll r) { assert(l <= r); if (l == r) return false; auto it = mp.upper_bound(l); // 更新不要時の処理 if (it == mp.end() || r <= (*it).se) return false; // [l, r)と重なる区間を一旦全て削除し、更新された区間を挿入 vector new_intervals; while(it != mp.end() && (*it).se < r) { auto [r2, l2] = *it; if (l2 < l) new_intervals.eb(l, l2); // r, l if (r < r2) new_intervals.eb(r2, r); // r, l it = mp.erase(it); } fore(p, new_intervals) mp.emplace(p); return true; } // 区間[x, x + 1)を削除. 返り値: 更新有無 bool erase(ll x) { return erase(x, x + 1); } // 区間[l, r)が完全に含まれるか bool contains(ll l, ll r) const { assert(l <= r); auto it = mp.upper_bound(l); return it != mp.end() && (*it).se <= l && r <= (*it).fi; } // 区間[x, x + 1)が完全に含まれるか bool contains(ll x) const { return contains(x, x + 1); } // 区間[l, r)と交差する区間の配列を返す vector get_intersecting_intervals(ll l, ll r) const { assert(l <= r); vector ret; if (l == r) return ret; // 空区間[l, l)は任意の区間と交差しない auto it = mp.upper_bound(l); for (; it != mp.end(); it++) { auto [r1, l1] = *it; if (r <= l1) break; ret.eb(l1, r1); } return ret; } }; // auto ist = IntervalSet(); // ist.insert(1, 8); // {[1, 8)} // 区間の挿入 // ist.erase(3, 4); // {[1, 3), [4, 8)} // 区間の削除 // ist.size(); // 2 // 区間の個数 // ist.contains(5, 9); // false // 区間が完全に含まれるか // ist.get_intersecting_intervals(3, 5); // {[4, 8)} // 区間と交差する区間の配列 // 非負整数の多重集合を格納し、そのmex(minimum excluded value)を求める struct Mex { IntervalSet ist; // 集合を区間で管理 map counts; // 数値の個数を管理 Mex() : ist(IntervalSet()) {} Mex(vl& vec) : ist(IntervalSet()) { fore(e, vec) insert(e); } // 数値を追加 void insert(ll val) { assert(val >= 0); counts[val]++; if (counts[val] == 1) ist.insert(val); } // 数値を削除 void erase(ll val) { assert(counts.contains(val)); counts[val]--; if (counts[val] == 0) { counts.erase(val); ist.erase(val); } } // mexを取得 ll get() { auto it = ist.mp.begin(); if (it == ist.mp.end() || (*it).se > 0) return 0; else return (*it).fi; } // 数値が多重集合に含まれるかどうか bool contains(ll val) { return counts.contains(val); } }; // vl vec = {0, 1, 3, 5, 3}; // auto mex = Mex(vec); // mex.insert(5); // {0, 1, 3, 3, 5, 5} // mex.erase(1); // {0, 3, 3, 5, 5} // mex.get(); // 1 // mex.contains(4); // false; // n = 2, r = 3 : 3つのものを2つの箱に振り分ける // nHr = n+r-1Cr, 2H3=4C3 // vvl P = homo_enum(2, 3); // P = {{3, 0}, {2, 1}, {1, 2}, {0, 3}} vvl homo_enum(ll n, ll r) { assert(0 < n && 0 <= r); vl vec(n, 0); vec[0] = r; vvl ret = {vec}; rep(i, 1, n) { vvl nxt; fore(vec, ret) { rep(j, 0, vec[0] + 1) { vec[i] = j; vec[0] -= j; nxt.pb(vec); vec[i] = 0; vec[0] += j; } } swap(ret, nxt); } return ret; } // grundy数を愚直に計算 vl solve(ll n) { vl dp(n + 1, -1); dp[0] = 0; auto f = [&](auto&& f, ll n) -> ll { if (dp[n] != -1) return dp[n]; if (n == 1) return dp[n] = 1; auto mex = Mex(); mex.insert(0); // 配る人数をrとする rep(r, 2, n + 1) { vvl P = homo_enum(r, n - r); set st; fore(p, P) { sort(all(p)); if (st.contains(p)) continue; ll g = 0; fore(e, p) g ^= f(f, e + 1); st.insert(p); mex.insert(g); } } return dp[n] = mex.get(); }; f(f, n); return dp; } int main() { cin.tie(nullptr); cout << fixed << setprecision(10); auto grundy = [&](ll n) -> ll { if (n < 5) return (n + 1) / 2; ll ret = ((n + 1) / 3 - 1) * 4; if (n % 3 == 1) ret += 2; return ret; }; // ll n = 22; // vl vec1 = solve(n); // vl vec2(n + 1); // rep(i, n + 1) vec2[i] = grundy(i); // assert(vec1 == vec2); // debug(vec1); // → 0 1 1 2 2 4 4 6 8 8 10 12 12 14 16 16 18 20 20 22 24 24 26 ll T; cin >> T; rep(t, T) { ll N; cin >> N; vl A(N); cin >> A; ll g = 0; fore(a, A) g ^= grundy(a); if (g) print("Alice"); else print("Bob"); } } /********* P A I R **********/ template inline pair& operator+=(pair& a, const pair b) {a.fi += b.fi; a.se += b.se; return a;} template inline pair& operator-=(pair& a, const pair b) {a.fi -= b.fi; a.se -= b.se; return a;} template inline pair& operator*=(pair& a, const pair b) {a.fi *= b.fi; a.se *= b.se; return a;} template inline pair& operator/=(pair& a, const pair b) {a.fi /= b.fi; a.se /= b.se; return a;} template inline pair& operator%=(pair& a, const pair b) {a.fi %= b.fi; a.se %= b.se; return a;} template inline pair& operator+=(pair& a, const V b) {a.fi += b; a.se += b; return a;} template inline pair& operator-=(pair& a, const V b) {a.fi -= b; a.se -= b; return a;} template inline pair& operator*=(pair& a, const V b) {a.fi *= b; a.se *= b; return a;} template inline pair& operator/=(pair& a, const V b) {a.fi /= b; a.se /= b; return a;} template inline pair& operator%=(pair& a, const V b) {a.fi %= b; a.se %= b; return a;} template inline pair operator+(pair a, const V& b) {a += b; return a;} template inline pair operator-(pair a, const V& b) {a -= b; return a;} template inline pair operator*(pair a, const V& b) {a *= b; return a;} template inline pair operator/(pair a, const V& b) {a /= b; return a;} template inline pair operator%(pair a, const V& b) {a %= b; return a;} template inline pair operator+(pair a) {return a;} template inline pair operator-(pair a) {return a * (-1);} template istream& operator >>(istream& stream, pair& a) {stream >> a.fi >> a.se; return stream;} template ostream& operator <<(ostream &stream, const pair& a) { stream << a.fi << " " << a.se; return stream; } /********* V E C T O R **********/ template inline vector& operator+=(vector& a, const vector b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] += b[i]; return a;} template inline vector& operator-=(vector& a, const vector b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] -= b[i]; return a;} template inline vector& operator*=(vector& a, const vector b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] *= b[i]; return a;} template inline vector& operator/=(vector& a, const vector b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] /= b[i]; return a;} template inline vector& operator%=(vector& a, const vector b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] %= b[i]; return a;} template inline vector& operator+=(vector& a, const U b) {fore(e, a) e += b; return a;} template inline vector& operator-=(vector& a, const U b) {fore(e, a) e -= b; return a;} template inline vector& operator*=(vector& a, const U b) {fore(e, a) e *= b; return a;} template inline vector& operator/=(vector& a, const U b) {fore(e, a) e /= b; return a;} template inline vector& operator%=(vector& a, const U b) {fore(e, a) e %= b; return a;} template inline vector operator+(vector a, const U& b) {a += b; return a;} template inline vector operator-(vector a, const U& b) {a -= b; return a;} template inline vector operator*(vector a, const U& b) {a *= b; return a;} template inline vector operator/(vector a, const U& b) {a /= b; return a;} template inline vector operator%(vector a, const U& b) {a %= b; return a;} template inline vector operator+(vector a) {return a;} template inline vector operator-(vector a) {return a * (-1);} template istream& operator >>(istream& stream, vector& a) {fore(e, a) stream >> e; return stream;} template ostream& operator <<(ostream& stream, const vector& v) {if(v.size()){stream << v[0]; rep(i, 1, v.size()) cout << " " << v[i];} return stream;} template ostream& operator <<(ostream& stream, const vector>& vv) {if(vv.size()){stream << vv[0]; rep(i, 1, vv.size()) cout << '\n' << vv[i];} return stream;} /********* S E T **********/ template istream& operator >>(istream& stream, set& st) {T e; stream >> e; st.insert(e); return stream;} template ostream& operator <<(ostream& stream, const set& st) {if(st.size()){auto it=st.begin(); stream << *it++; for(; it!=st.end(); it++) cout << " " << *it;} return stream;} /********* M U L T I S E T **********/ template istream& operator >>(istream& stream, multiset& st) {T e; stream >> e; st.insert(e); return stream;} template ostream& operator <<(ostream& stream, const multiset& st) {if(st.size()){auto it=st.begin(); stream << *it++; for(; it!=st.end(); it++) cout << " " << *it;} return stream;} /********* P R I N T **********/ template inline void print(const T& e) {cout << e << '\n';} template inline void print(const H& h, const T&... t) {cout << h << ' '; print(t...);} template inline void End(const T&... t) {print(t...); exit(0);} /********* D E B U G **********/ void dbg_(const long long& e) {if (e == INF) cout << "INF"; else if (e == -INF) cout << "-INF"; else cout << e;} template void dbg_(const T& e) {cout << e;} template void dbg_(const pair& p) {cout << '('; dbg_(p.first); cout << ' '; dbg_(p.second); cout << ')';} template void dbg_(const trio& t) {cout << '('; dbg_(t.first); cout << ' '; dbg_(t.second); cout << ' '; dbg_(t.third); cout << ')';} template void dbg_(const quartet& t) {cout << '('; dbg_(t.first); cout << ' '; dbg_(t.second); cout << ' '; dbg_(t.third); cout << ' '; dbg_(t.fourth); cout << ')';} template void debug_(const T& e) {dbg_(e); cout << '\n';} template void debug_(const vector& v) {if (v.size()){auto it=v.begin(); dbg_(*it++); for(; it!=v.end(); ++it){cout << ' '; dbg_(*it);}} cout << '\n';} template void debug_(const vector>& vv) {cout << '\n'; ll cnt=0; for(auto&& v : vv){cout << cnt++ << ": "; debug_(v);}} template void debug_(const map& mp) {if (mp.size()) {auto it = mp.begin(); dbg_(*it++); for(; it != mp.end(); ++it) {cout << ' '; dbg_(*it);}} cout << '\n';} template void debug_(const vector>& vm){cout << '\n'; ll cnt=0; for(auto&& mp : vm){cout << cnt++ << ": "; debug_(mp);}} template void debug_(const set& st) {if(st.size()){auto it=st.begin(); dbg_(*it++); for(; it!=st.end(); ++it) {cout << ' '; dbg_(*it);}}cout << '\n';} template void debug_(const multiset& st) {if(st.size()) {auto it=st.begin(); dbg_(*it++); for(; it != st.end(); ++it) {cout << ' '; dbg_(*it);}} cout << '\n';} template void debug_(const vector>& vs) {cout << '\n'; ll cnt=0; for(auto&& st : vs){cout << cnt++ << ": "; debug_(st);}} template void debug_(const vector>& vs) {cout << '\n'; ll cnt=0;for(auto&& st : vs){cout << cnt++ << ": "; debug_(st);}} template void debug_(const H& h, const T&... t) {dbg_(h); cout << ", "; debug_(t...);} /********* T R I O **********/ template istream& operator >>(istream &stream, trio& t) {return stream >> t.first >> t.second >> t.third;} template ostream& operator <<(ostream &stream, const trio& t) {return stream << t.first << " " << t.second << " " << t.third;} /********* Q U A R T E T **********/ template istream& operator >>(istream &stream, quartet& t) {return stream >> t.first >> t.second >> t.third >> t.fourth;} template ostream& operator <<(ostream &stream, const quartet& t) {return stream << t.first << " " << t.second << " " << t.third << " " << t.fourth;}