#include using namespace std; // -------------------------------------------------------------------------------------------------------------- /*#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops")//*/ //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wdeprecated-copy" namespace VvyLw { namespace Twitter { void wa_haya_exe(){ cin.tie(nullptr); ios::sync_with_stdio(false); } } void solve(); } // VvyLw mt19937 EhaL(hash()("Huitloxopetl")); mt19937 Random() { random_device seed_gen; mt19937 engine {seed_gen()}; return engine; } using Timer = chrono::system_clock::time_point; [[maybe_unused]] Timer start, stop; #if local void now(Timer &t){ t = chrono::system_clock::now(); } void time(const Timer &t1, const Timer &t2){ auto tm = chrono::duration_cast(t2-t1).count(); cout << tm << "ms\n"; } #else [[maybe_unused]] void now(Timer &t){ void(0); } [[maybe_unused]] void time(const Timer &t1, const Timer &t2){ void(0); } #endif // -------------------------------------------------------------------------------------------------------------- #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0; i<(n); ++i) #define rep2(i,n) for(ll i=0; i<(n); ++i) #define rep3(i,a,b) for(ll i=(a); i<=(b); ++i) #define rep4(i,a,b,c) for(ll i=(a); i<=(b); i+=(c)) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rvp1(n) for(ll i=(n)-1; i>=0; i--) #define rvp2(i,n) for(ll i=(n)-1; i>=0; i--) #define rvp3(i,a,b) for(ll i=(a); i>=(b); i--) #define rvp4(i,a,b,c) for(ll i=(a); i>=(b); i-=(c)) #define rvp(...) overload4(__VA_ARGS__,rvp4,rvp3,rvp2,rvp1)(__VA_ARGS__) #define all1(v) v.begin(),v.end() #define all2(v,a) v.begin(),v.begin()+a #define all3(v,a,b) v.begin()+a,v.begin()+b #define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__) #define rall1(v) v.rbegin(),v.rend() #define rall2(v,a) v.rbegin(),v.rbegin()+a #define rall3(v,a,b) v.rbegin()+a,v.rbegin()+b #define rall(...) overload3(__VA_ARGS__,rall3,rall2,rall1)(__VA_ARGS__) #define each1(elem,v) for(auto &elem: v) #define each2(x,y,v) for(auto &[x,y]: v) #define each3(x,y,z,v) for(auto &[x,y,z]: v) #define each(...) overload4(__VA_ARGS__,each3,each2,each1)(__VA_ARGS__) #define sqrp1(n) for(ll i=0; i*i<(n); ++i) #define sqrp2(i,n) for(ll i=0; i*i<(n); ++i) #define sqrp3(i,a,b) for(ll i=(a); i*i<=(b); ++i) #define sqrp(...) overload3(__VA_ARGS__,sqrp3,sqrp2,sqrp1)(__VA_ARGS__) #define irp(it,v) for(auto it=v.begin(); it!=v.end(); ++it) #define ir(it,v) for(auto it=v.begin(); it!=v.end();) #define FE(v,f) for_each(all(v),f) using ll = long long; using ld = long double; using uint = unsigned; using ul = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; namespace vectors { template using V = vector; using vi = V; using vu = V
    ; using vd = V; using vc = V; using vs = V; using vb = V; using wi = V; using wu = V; using wd = V; using wc = V; using ws = V; using wb = V; template V& operator++(V& v){ each(el,v) el++; return v; } template V& operator--(V& v){ each(el,v) el--; return v; } template V& operator+=(V& v, const U x){ each(el,v) el+=x; return v; } template V& operator-=(V& v, const U x){ each(el,v) el-=x; return v; } template V& operator*=(V& v, const U x){ each(el,v) el*=x; return v; } template V& operator/=(V& v, const U x){ each(el,v) el/=x; return v; } template V operator+(const V& v, const U x){ V res = v; res+=x; return res; } template V operator-(const V& v, const U x){ V res = v; res-=x; return res; } template V operator*(const V& v, const U x){ V res = v; res*=x; return res; } template V operator/(const V& v, const U x){ V res = v; res/=x; return res; } template bool operator==(const V& v, const V& w){ return (v.size()==w.size() && equal(all(v),w.begin())); } template bool operator!=(const V& v, const V& w){ return !(v==w); } } // vectors using namespace vectors; namespace pairs { template using P = pair; template using PP = P; using pi = PP; using pd = PP; using pc = PP; using ps = PP; template PP operator+(const PP& a, const PP& b){ return {a.first + b.first, a.second + b.second}; } template PP operator-(const PP& a, const PP& b){ return {a.first - b.first, a.second - b.second}; } template PP operator-(const PP& a){ return {-a.first, -a.second}; } template PP operator*(const PP& a, const U& b){ return {a.first * b, a.second * b}; } template PP operator/(const PP& a, const U& b){ return {a.first / b, a.second / b}; } template PP& operator+=(PP& a, const PP& b){ return a = a + b; } template PP& operator-=(PP& a, const PP& b){ return a = a - b; } template PP& operator*=(PP& a, const U& b){ return a = a * b; } template PP& operator/=(PP& a, const U& b){ return a = a / b; } template bool operator==(const PP &p, const PP &q){ return p.first==q.first && p.second==q.second; } template bool operator!=(const PP &p, const PP &q){ return !(p==q); } template bool operator<(const PP &p, const PP &q){ if(p.first==q.first) return p.second bool operator<=(const PP &p, const PP &q){ if(p.first==q.first) return p.second<=q.second; return p.first bool operator>(const PP &p, const PP &q){ if(p.first==q.first) return p.second>q.second; return p.first>q.first; } template bool operator>=(const PP &p, const PP &q){ if(p.first==q.first) return p.second>=q.second; return p.first>q.first; } template bool operator==(const P &p, const P &q){ return p.first==q.first && p.second==q.second; } template bool operator!=(const P &p, const P &q){ return !(p==q); } template bool operator<(const P &p, const P &q){ if(p.first==q.first) return p.second bool operator<=(const P &p, const P &q){ if(p.first==q.first) return p.second<=q.second; return p.first bool operator>(const P &p, const P &q){ if(p.first==q.first) return p.second>q.second; return p.first>q.first; } template bool operator>=(const P &p, const P &q){ if(p.first==q.first) return p.second>=q.second; return p.first>q.first; } template PP rotate(const PP& a){ return {-a.second, a.first}; } // 90 degree ccw template T dot(const PP& a, const PP& b){ return a.first * b.first + a.second * b.second; } template T cross(const PP& a, const PP& b){ return dot(rotate(a), b); } template T square(const PP& a){ return dot(a, a); } template ld grad(const PP& a){ return 1.0L*a.second/a.first; } template ld abs(const PP& a){ return hypotl(a.first, a.second); } template T gcd(const PP& a){ return gcd(a.first, a.second); } template PP normalize(PP a) { if(a == PP{}) return a; a /= gcd(a); if(a < PP{}) a = -a; return a; } template P swap(const P &p){ P ret={p.second,p.first}; return ret; } template V> swap(const V> &vp) { V> ret; FE(vp,[&ret](P el){ret.emplace_back(swap(el));}); return ret; } template V first(const V> &vp) { V res; each(el,vp) res.emplace_back(el.first); return res; } template V second(const V> &vp) { V res; each(el,vp) res.emplace_back(el.second); return res; } } // pairs using namespace pairs; template using pq = priority_queue; template using pqr = priority_queue,greater>; template bool chmax(T& a, const U& b){ if(a bool chmin(T& a, const U& b){ if(a>b){ a=b; return 1; } return 0; } template inline bool overflow_if_add(T a, U b){ return (numeric_limits::max()-a) inline bool overflow_if_mul(T a, U b){ return (numeric_limits::max()/a)::infinity(); const double PI = acos(-1); const double E = 2.718281828459045; namespace IO { ostream &operator<<(ostream &dest, i128 value) { ostream::sentry s(dest); if(s) { u128 tmp = value < 0 ? -value : value; char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while(tmp); if(value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if(dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } template void scan(T& a){ cin >> a; } template void scan(P& p){ scan(p.first); scan(p.second); } template void scan_t(T &t) { if constexpr (id::value) { scan(get(t)); scan_t(t); } } template void scan(tuple &t){ scan_t(t); } template void scan(V& a){ each(i,a) scan(i); } template void lin(T& a){ getline(cin, a); } [[maybe_unused]] void in(){} template bool in(Head& head, Tail&... tail){ scan(head); in(tail...); return 1; } template void print(const T& a){ cout << a; } template void println(const T& a){ cout << a; } template void print(const P& p){ print(p.first); cout<<" "; print(p.second); } template void print_t(const T& t) { if constexpr (id::value) { if constexpr (id>0) cout << ' '; print(get(t)); print_t(t); } } template void print(const tuple& tpl){ print_t(tpl); } template void print(const V& a){ if(!a.empty()){ print(a[0]); for(auto i=a.begin(); ++i!=a.end();){ cout<<' '; print(*i); } } } template void println(const V& a){ if(!a.empty()){ print(a[0]); for(auto i=a.begin(); ++i!=a.end();){ cout<<'\n'; print(*i); } } } template void print(const map &m){ if(!m.empty()){ print(m.begin()->first); cout<<' '; print(m.begin()->second); for(auto i=m.begin(); ++i!=m.end();){ cout<<", "; print(i->first); cout<<' '; print(i->second); } } } template void print(const set &st){ print(*st.begin()); for(auto i=st.begin(); ++i!=st.end();){ cout<<' '; print(*i); } } template void print(queue que){ print(que.front()); while(que.size()){ cout<<' '; que.pop(); if(!que.empty()) print(que.front()); } } template void print(const deque &dq){ if(!dq.empty()){ print(dq[0]); for(auto i=dq.begin(); ++i!=dq.end();){ cout<<' '; print(*i); } } } template void println(const deque &dq){ if(!dq.empty()){ print(dq[0]); for(auto i=dq.begin(); ++i!=dq.end();){ cout<<'\n'; print(*i); } } } template void print(stack sk){ print(sk.top()); while(sk.size()){ cout<<' '; sk.pop(); if(!sk.empty()) print(sk.top()); } } template void print(priority_queue pq){ print(pq.top()); while(pq.size()){ pq.pop(); cout<<' '; if(!pq.empty()) print(pq.top()); } } void bl(){ cout<<' '; } void out(){ cout<<'\n'; } template void out(const T& t){ print(t); cout<<'\n'; } template void vout(const T& t){ println(t); cout<<'\n'; } template void out(const Head& head, const Tail&... tail){ print(head); cout<<' '; out(tail...); } template void vout(const Head& head, const Tail&... tail){ println(head); cout<<'\n'; vout(tail...); } void fix(short x){ cout << fixed << setprecision(x); } void Alpha(){ cout << boolalpha; } void Flush(){ flush(cout); } } // IO using namespace IO; #define INT(...) int __VA_ARGS__; in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; in(__VA_ARGS__) #define UL(...) ul __VA_ARGS__; in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; in(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; in(__VA_ARGS__) #define STR(...) string __VA_ARGS__; in(__VA_ARGS__) #define LIN(str) string str; lin(str) #define VEC(type,name,size) V name(size); in(name) #define WEC(type,name,h,w) V> name(h,V(w)); in(name) #define fin(...) do{ out(__VA_ARGS__); return; }while(false) namespace yesno_sys { inline void YES(bool ok=1){ out(ok?"YES":"NO"); } inline void NO(bool ok=1){ YES(!ok); } inline void Yes(bool ok=1){ out(ok?"Yes":"No"); } inline void No(bool ok=1){ Yes(!ok); } inline void yes(bool ok=1){ print(ok?"yes":"no"); } inline void no(bool ok=1){ yes(!ok); } } // yesno_sys using namespace yesno_sys; #ifdef local #include "debug_print.hpp" #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) static_cast(0) #endif #define elif else if #define scp(a,x,b) a<=x&&x<=b #define eid(el,v) &el-&v[0] #define gt(tpl,x) get(tpl) #define bif(bit,tar) if(((tar)>>(bit))&1) #define nxp(x) next_permutation(all(x)) #define prp(x) prev_permutation(all(x)) #define strpl(s,a,b) regex_replace(s,regex(a),b) #define rgxmt(s,rgx) regex_match(s,regex(rgx)) namespace zia_qu { template inline T sqr(T x){ return x*x; } template inline T cub(T x){ return x*x*x; } template inline T Mod(T x, T m){ return (x+m)%m; } template inline T Pow(T a, T b, T mod=0) { T res=1; if(mod) { res%=mod; a%=mod; } while(b>0) { if(b&1) res*=a; if(mod) res%=mod; a*=a; if(mod) a%=mod; b>>=1; } return res; } inline ll Ceil(ld x, ll m){ return ceil(x/m); } inline ll Round(ld x, ll m, short fx=0){ if(fx==0) return round(x/m); else { ul y=Pow
      (10,fx); return round((x/y)/m)*y; } } inline ld Log(ll x, double base=2){ return log2(x)/log2(base); } inline int bitdigit(ll x){ return 64-__builtin_clzll(x); } inline int popcnt(ll x){ return __builtin_popcountll(x); } inline int fione(ll x){ return __builtin_ffsll(x); } inline int zrcnt(ll x){ return __builtin_ctzll(x); } inline bool isupper(char c){ return std::isupper(c); } inline bool isupper(const string &s){ bool ok=1; each(el,s) ok&=isupper(el); return ok; } inline bool islower(char c){ return std::islower(c); } inline bool islower(const string &s){ bool ok=1; each(el,s) ok&=islower(el); return ok; } inline bool isalpha(char c){ return std::isalpha(c); } inline bool isalpha(const string &s){ bool ok=1; each(el,s) ok&=isalpha(el); return ok; } inline bool isdigit(char c){ return std::isdigit(c); } inline bool isdigit(const string &s){ bool ok=1; each(el,s) ok&=isdigit(el); return ok; } inline bool isalnum(char c){ return std::isalnum(c); } inline bool isalnum(const string &s){ bool ok=1; each(el,s) ok&=isalnum(el); return ok; } inline bool isspace(char c){ return std::isspace(c); } inline bool isspace(const string &s){ bool ok=1; each(el,s) ok&=isspace(el); return ok; } inline bool ispunct(char c){ return std::ispunct(c); } inline bool ispunct(const string &s){ bool ok=1; each(el,s) ok&=ispunct(el); return ok; } inline bool isprint(char c){ return std::isprint(c); } inline bool isprint(const string &s){ bool ok=1; each(el,s) ok&=isprint(el); return ok; } inline ll strins(string &s, ll id, const string &t){ s.insert(id,t); return s.size(); } inline string toupper(string s){ each(c,s) c=std::toupper(c); return s; } inline string tolower(string s){ each(c,s) c=std::tolower(c); return s; } inline vi ten_to_adic(ll m, ll n) { vi res; ll now=m; while(now!=0) { res.emplace_back(now%n); now/=n; } //rev(res); return res; } inline ll adic_to_ten(const vi &v, ll u) { ll res=0; //rev(v); each(el,v) { ll idx=eid(el,v); res+=Pow(u,idx)*el; } return res; } inline string to_hex(ll x) { stringstream ss; ss<(x); string s=ss.str(); reverse(all(s)); s.resize(ten_to_adic(x,2).size()); reverse(all(s)); return s; } inline ll to_ten(string s, short base){ return stoll(s,nullptr,base); } inline i128 stoL(const string &s) { i128 ret = 0; each(el,s) { if(isdigit(el)) ret = 10 * ret + el - '0'; } if(s.front() == '-') ret = -ret; return ret; } template constexpr auto symin(Ts... a){ return min(initializer_list>{a...}); } template constexpr auto symax(Ts... a){ return max(initializer_list>{a...}); } template inline V kyl(const map &m, const U val) { V keys; irp(it,m) { if(it->second==val) keys.emplace_back(it->first); } return keys; } template inline K kymin(const map &m){ return m.begin()->first; } template inline K kymax(const map &m){ return m.rbegin()->first; } template inline V kymin_v(const map &m){ return m.begin()->second; } template inline V kymax_v(const map &m){ return m.rbegin()->second; } template inline V vlmin(map &m){ auto pr = *min_element(all(m),[](P const &x, P const &y){ return x.second > y.second; }); return pr.second; } template inline V vlmax(map &m){ auto pr = *max_element(all(m),[](P const &x, P const &y){ return x.second < y.second; }); return pr.second; } template inline K vlmin_k(map &m){ auto pr = *min_element(all(m),[](P const &x, P const &y){ return x.second > y.second; }); return pr.first; } template inline K vlmax_k(map &m){ auto pr = *max_element(all(m),[](P const &x, P const &y){ return x.second < y.second; }); return pr.first; } template inline T stmin(const set &s){ return *s.begin(); } template inline T stmax(const set &s){ return *s.rbegin(); } } // zia qu namespace Lady_sANDy { template inline ll len(const T& v){ return v.size(); } template inline void rev(T& v){ reverse(all(v)); } template inline void rev(T& v, ll a, ll b){ reverse(all(v,a,b)); } template inline T revd(const T& v){ auto c=v; rev(c); return c; } template inline T revd(const T& v, ll a, ll b){ auto c=v; rev(c,a,b); return c; } template inline void Sort(T& v){ sort(all(v)); } template inline void Sort(T& v, ll a, ll b){ sort(all(v,a,b)); } template inline T sorted(T& v){ auto c=v; Sort(c); return c; } template inline T sorted(T& v, ll a, ll b){ auto c=v; Sort(c,a,b); return c; } template inline void Sortt(T& v){ sort(rall(v)); } template inline void Sortt(T& v, ll a, ll b){ sort(rall(v,a,b)); } template inline T Sorted(T& v){ auto c=v; Sortt(c); return c; } template inline T Sorted(T& v, ll a, ll b){ auto c=v; Sortt(c,a,b); return c; } template inline void Sorth(T& v){ make_heap(all(v)); sort_heap(all(v)); } template inline T mrg(T& a, T& b){ T res; merge(all(a),all(b),back_inserter(res)); return res; } template inline T Min(const V& v){ return *min_element(all(v)); } template inline T Max(const V& v){ return *max_element(all(v)); } template inline ll Min_i(const T& v){ return min_element(all(v))-v.begin(); } template inline ll Max_i(const T& v){ return max_element(all(v))-v.begin(); } template inline ll LB(const T& v, const U x){ return lower_bound(all(v),x)-v.begin(); } template inline ll UB(const T& v, const U x){ return upper_bound(all(v),x)-v.begin(); } template inline bool BS(const T& v, const U x){ return binary_search(all(v),x); } template inline bool BS(const T& v, const U x, Boolean fn){ return binary_search(all(v),x,fn); } template inline bool All(const T& v, Boolean fn){ return all_of(all(v),fn); } template inline bool Exist(const T& v, Boolean fn){ return any_of(all(v),fn); } template inline ll ptp(T& v, Boolean fn){ return partition_point(all(v),fn)-v.begin(); } template inline ll Find(const T& v, const U x){ auto itr=find(all(v),x); if(itr==v.end()) return -1LL; return itr-v.begin(); } template inline void rpl(T& v, const U fn, const U r){ replace(all(v),fn,r); } template inline void rplif(T& v, Boolean fn, const U r){ replace_if(all(v),fn,r); } template inline ul cntif(const T& v, Boolean fn){ return count_if(all(v),fn); } template inline T Count(T& v, ll x) { /*Sort(v);//*/ return UB(v,x)-LB(v,x); } template inline T IP(const V& v, const V& u, T init=0){ return inner_product(all(v),u.begin(),init); } template inline V iot(T n, ll init=0){ V a(n); iota(all(a),init); return a; } template inline ll ers(T& v, U x){ v.erase(remove(all(v),x),v.end()); return len(v); } template ll ersif(T& v, Boolean x){ v.erase(remove_if(all(v),x),v.end()); return len(v); } template inline ll unq(T& v){ Sort(v); v.erase(unique(all(v)),v.end()); return len(v); } template inline T cp(const T& v){ T res; copy(all(v),back_inserter(res)); return res; } template inline T cp(const T& v, ll a, ll b){ T res; copy(all(v,a,b),back_inserter(res)); return res; } template inline void rtt(T& s, ll idx){ ll id=zia_qu::Mod(idx,len(s)); rotate(all(s,id),s.end()); } template inline void rtt(T& s, ll a, ll b, ll c){ rotate(all(s,a,b),s.end()-c); } template inline V psum(const V& v){ V s; partial_sum(all(v),back_inserter(s)); return s; } template inline V adf(const V& v){ V a; adjacent_difference(all(v),back_inserter(a)); return a; } template inline V rext(V& v, mt19937 eng, ll size){ V res; sample(all(v),back_inserter(res),size,eng); return res; } template inline T rext(V& v, mt19937 eng){ V res; sample(all(v),back_inserter(res),1,eng); return res.front(); } template inline ll vsum(V &v){ return reduce(all(v),0LL); } template inline ll vsum(V &v, ll a, ll b){ return reduce(all(v,a,b),0LL); } template inline ld vdsum(V &v){ return reduce(all(v),0.0L); } template inline ld vdsum(V &v, ll a, ll b){ return reduce(all(v,a,b),0.0L); } template inline ll vmul(V &v){ return reduce(all(v),1LL,[](ll acc,ll i){ return acc*i; }); } template inline ll vmul(V &v, ll a, ll b){ return reduce(all(v,a,b),1LL,[](ll acc,ll i){ return acc*i; }); } template inline ld vdmul(V &v){ return reduce(all(v),1.0L,[](ll acc,ll i){ return acc*i; }); } template inline ld vdmul(V &v, ll a, ll b){ return reduce(all(v,a,b),1.0L,[](ll acc,ll i){ return acc*i; }); } } // Lady s&y namespace Heileden { template inline V divisor(T n) { V div; sqrp(i,1,n) { if(n%i==0) { div.emplace_back(i); if(i*i!=n) div.emplace_back(n/i); } } Lady_sANDy::Sort(div); return div; } inline bool is_prime(ul n) { if(n==1) return 0; sqrp(i,2,n) if(n%i==0) return 0; return 1; } template inline V> prmfct(T n) { V> res; sqrp(i,2,n) { if(n%i) continue; T tmp=0; while(n%i==0) { tmp++; n/=i; } res.emplace_back(i,tmp); } if(n!=1) res.emplace_back(n,1); return res; } struct p_table { vb SoE; p_table(int n): SoE(n+1,1){ SoE[0]=SoE[1]=0; rep(i,2,n) { if(!SoE[i]) continue; rep(j,i*i,n,i) SoE[j] = 0; } } vi table(int n) { vi p; rep(i,2,n) if(SoE[i]) p.emplace_back(i); return p; } }; struct p_fact { vi spf; p_fact(int n): spf(n + 1){ iota(all(spf),0); sqrp(i,2,n) { if(spf[i]==i) { rep(j,i*i,n,i) { if(spf[j]==j) spf[j]=i; } } } } map get(int n) { map m; while(n!=1) { m[spf[n]]++; n/=spf[n]; } return m; } }; template inline T bins(T ok, T ng, Boolean fn, ld eps = 1) { while(abs(ok-ng)>eps) { T mid=(ok+ng)/2; (fn(mid)?ok:ng) = mid; } return ok; } vi manacher(const string &s) { const ll n = Lady_sANDy::len(s); vi radius(n); ll i=0,j=0; while(i=0 && i+j=0 && i+k T factor(T n, T mod=0) { T res=1; while(n>0) { res*=n--; if(mod) res%=mod; } return res; } template T perm(T n, T r, T mod=0) { const T tmp=n; T res=1; while(n>tmp-r) { res*=n--; if(mod) res%=mod; } return res; } template T binom(T n, T r, T mod=0) { if(r < 0 || n < r) return 0; T res = 1; rep(i,1,r) { res*=n--; if(mod) res%=mod; res/=i; if(mod) res%=mod; } return res; } inline bool is_int(ld n){ ll r=floor(n); return r==n; } inline bool is_sqr(ll n){ return is_int(sqrtl(n)); } /* grundy sample template inline bool grundy(V v) { ll res=0; each(el,v) res^=el; return res!=0; }//*/ } // Heileden struct edge { ll to, cost, val; edge(ll to_, ll cost_, ll val_): to(to_), cost(cost_), val(val_){} operator ll() const { return to; } }; using ve = V; using we = V; template struct w_graph { we g; w_graph(ll n): g(n){} ve& operator[](ll x){ return g[x]; } const ve& operator[](ll x) const { return g[x]; } operator we&(){ return g; } operator const we&() const { return g; } auto begin() const { return g.cbegin(); } auto end() const { return g.cend(); } ll size() const { return g.size(); } void add(ll a, ll b, ll cost, ll val, uint indexed=1) { a-=indexed,b-=indexed; g[a].emplace_back(b,cost,val); if(indirected) g[b].emplace_back(a,cost,val); } void input(ll m, uint indexed=1) { rep(m) { LL(a,b,cost,val); add(a,b,cost,val,indexed); } } vi all_dist(ll v) { vi d(g.size(),-1); queue q; d[v]=0; q.emplace(v); while(q.size()) { ll tmp=q.front(); q.pop(); each(el,g[tmp]) { if(d[el]!=-1) continue; d[el]=d[tmp]+1; q.emplace(el); } } return d; } ll dist(ll u, ll v) { auto d=all_dist(u); return d[v]; } vi dijikstra(ll v) { vi cst(g.size(),LINF); pqr dj; cst[v]=0; dj.emplace(cst[v],v); while(dj.size()) { auto tmp=dj.top(); dj.pop(); if(cst[tmp.second] struct graph { wi g; graph(ll n): g(n){} vi& operator[](ll x){ return g[x]; } const vi& operator[](ll x) const { return g[x]; } operator wi&(){ return g; } operator const wi&() const { return g; } auto begin() const { return g.cbegin(); } auto end() const { return g.cend(); } ll size() const { return g.size(); } void add(ll a, ll b, uint indexed=1) { a-=indexed,b-=indexed; g[a].emplace_back(b); if(indirected) g[b].emplace_back(a); } void input(ll m, uint indexed=1) { rep(m) { LL(a,b); add(a,b,indexed); } } vi all_dist(ll v) { vi d(g.size(),-1); queue q; d[v]=0; q.emplace(v); while(q.size()) { ll tmp=q.front(); q.pop(); each(el,g[tmp]) { if(d[el]!=-1) continue; d[el]=d[tmp]+1; q.emplace(el); } } return d; } ll dist(ll u, ll v) { auto d=all_dist(u); return d[v]; } }; // -------------------------------------------------------------------------------------------------------------- using namespace zia_qu; using namespace Lady_sANDy; using namespace Heileden; int main() { VvyLw::Twitter::wa_haya_exe(); now(start); /*INT(t); while(t--)//*/ VvyLw::solve(); now(stop); time(start, stop); } // -------------------------------------------------------------------------------------------------------------- void VvyLw::solve() { LL(n,m,x); w_graph g(n); g.input(m); debug(g); auto dijkstra=[&](int v) { vi cst(g.size(),LINF); pqr dj; cst[0]=0; dj.emplace(cst[0],0); while(len(dj)) { auto tmp=dj.top(); dj.pop(); if(cst[tmp.second](-1,1e9,dijkstra)); }