1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include "bits/stdc++.h" using namespace std;
#define all(a) (a).begin(), (a).end() template<typename T, typename F=less<T>> using pque=priority_queue<T, vector<T>, F>; template<typename T, typename F=less<T>> pque<T, F> make_pque(F cmp) { return pque<T, F>(cmp); } typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef vector<vs> vvs;
template <typename T1, typename T2> auto max(T1 a, T2 b) -> decltype(a + b) { return a>b?a:b; } template <typename T1, typename T2> auto min(T1 a, T2 b) -> decltype(a + b) { return a<b?a:b; } template <typename T1, typename T2, typename T3> auto max(T1 a, T2 b, T3 c) -> decltype(a + b + c) { return max(max(a, b), c); } template <typename T1, typename T2, typename T3> auto min(T1 a, T2 b, T3 c) -> decltype(a + b + c) { return min(min(a, b), c); } template <typename T> T max(const vector<T>& a) {T r = a[0]; for(auto e : a) r = max(r, e); return r;} template <typename T> T min(const vector<T>& a) {T r = a[0]; for(auto e : a) r = min(r, e); return r;} template<typename T> T sum(const vector<T>& a) { T r = 0; for(auto& e : a) r+=e; return r;} template<typename T> T gcd(T a, T b) { while(b) { T r = a%b; a = b; b = r;} return a;} template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } template<typename F> ll lb(ll b, ll e, F f) {if(b>=e) return e; while(b<e-1) {auto m=b+(e-1-b)/2; if(!f(m)) b=m+1; else e=m+1;} return f(b)?b:e;} template<typename F> ll ub(ll b, ll e, F f) {return lb(b, e, [&](ll i){return !f(i);});}
template<typename T> struct cast_helper {T operator() (stringstream& ss) {T r=T{}; ss >> r; return r;}}; template<> struct cast_helper<string> {string operator() (stringstream& ss) { return ss.str();}}; template<typename R, typename T> R sstream_cast(const T& o) {stringstream ss; ss << o; return cast_helper<R>()(ss);} string format(const char* f, ...){va_list a; va_start(a, f); char b[4096]; vsnprintf(b, 4096, f, a); va_end(a); return b;} template<typename T> unordered_map<T, int> counter(const vector<T>& a) {unordered_map<T, int> r;for(auto e : a) ++r[e];return r;} unordered_map<char, int> counter(const string& a) {unordered_map<char, int> r;for(auto e : a) ++r[e];return r;} template<typename I> vector<I> range(I b, I e) {vector<I> r(e-b);iota(all(r), b);return r;}
vvi make_vvi(int n, int m, int v=0) { return vvi(n, vi(m, v));} vvb make_vvb(int n, int m, bool v=false) { return vvb(n, vb(m, v));} vvs make_vvs(int n, int m, const string& v="") { return vvs(n, vs(m, v));} typedef tuple<int, int> tii; typedef tuple<ll, ll> tll; typedef tuple<int, int, int> tiii; #define _0(o) get<0>(o) #define _1(o) get<1>(o) #define _2(o) get<2>(o) namespace std { template<>struct hash<tii>{size_t operator()(const tii& a)const {return _0(a)^_1(a);}}; template<>struct hash<tiii>{size_t operator()(const tiii& a)const {return _0(a)^_1(a)^_2(a);}}; }; tii dir4[] = {tii(-1, 0), tii(0, 1), tii(1, 0), tii(0,-1)}; tii dir8[] = {tii(-1, 0), tii(0, 1), tii(1, 0), tii(0,-1), tii(-1,-1), tii(-1,1), tii(1,1), tii(1,-1)}; tii& operator += (tii& a, const tii& b) { _0(a)+=_0(b); _1(a)+=_1(b); return a; } tii operator + (const tii& a, const tii& b) { return tii(_0(a)+_0(b), _1(a)+_1(b)); } tii& operator -= (tii& a, const tii& b) { _0(a)-=_0(b); _1(a)-=_1(b); return a; } tii operator - (const tii& a, const tii& b) { return tii(_0(a)-_0(b), _1(a)-_1(b)); } tii operator - (const tii& a) { return tii(-_0(a), -_1(a)); } tii& operator *= (tii& a, int k) { _0(a)*=k; _1(a)*=k; return a; } tii operator * (int k, const tii& a) { return tii(k*_0(a), k*_1(a)); } tii operator * (const tii& a, int k) { return tii(_0(a)*k, _1(a)*k); } tii& operator /= (tii& a, int k) { _0(a)/=k; _1(a)/=k; return a; } tii operator / (const tii& a, int k) { return tii(_0(a)/k, _1(a)/k); } bool in_range(tii p, tii e) {return 0<=_0(p)&&_0(p)<_0(e)&&0<=_1(p)&&_1(p)<_1(e);} bool in_range(tii p, tii b, tii e) {return _0(b)<=_0(p)&&_0(p)<_0(e)&&_1(b)<=_1(p)&&_1(p)<_1(e);}
constexpr int INF = 1e9+7; constexpr int MOD = 1e9+7;
#ifndef cout struct _ { template <typename T> _& operator << (const T&){ return *this; } }; #define cout _() #define endl '\n' #endif
int _main_() { return 0; }
#undef cout #undef endl
|