#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") namespace VvyLw { namespace Twitter { void wa_haya_exe(){ cin.tie(nullptr); ios::sync_with_stdio(false); } } void solve(); }; // VvyLw mt19937 Random() { random_device seed_gen; mt19937 engine {seed_gen()}; return engine; } // -------------------------------------------------------------------------------------------------------------- template using V = vector; template using P = pair; template using pq = priority_queue; template using pqr = priority_queue,greater>; template using pqs = priority_queue>; template using pqrs = priority_queue,V>,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) using PP = pair; 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 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 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; } } // pairs using namespace pairs; 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; using pi = PP; using pd = PP; using pc = PP; using ps = PP; const int dx[]={-1,-1,-1,0,0,1,1,1}; const int dy[]={-1,0,1,-1,1,-1,0,1}; const int MOD = 998244353; const int M0D = 1000000007; const int INF = 0x3fffffff; const ll LINF = 0x1fffffffffffffff; const ld DINF = numeric_limits::infinity(); const double PI = acos(-1); const double E = 2.718281828459045; #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0; 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 void scan(T& a){ cin >> a; } template void scan(P& p){ scan(p.first); scan(p.second); } template void scan(V& a){ for(auto &i: a) scan(i); } void in(){} template void in(Head& head, Tail&... tail){ scan(head); in(tail...); } template void print(const T& a){ cout << a; } template void print(const P& p){ print(p.first); cout<<" "; print(p.second); } template void print(const V& a){ if(!a.empty()){ print(a[0]); for(auto i=a.begin(); ++i!=a.end();){ cout<<" "; print(*i); } } } void bl(){ cout<<' '; } void out(){ cout<<'\n'; } template void out(const T& t){ print(t); cout<<'\n'; } template void out(const Head& head, const Tail&... tail) { print(head); cout<<" "; out(tail...); } template void vout(V& v) { FE(v,[](T x){out(x);}); } 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 CHR(...) char __VA_ARGS__; in(__VA_ARGS__) #define STR(...) string __VA_ARGS__; in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; in(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; in(__VA_ARGS__) #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 #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 mp make_pair #define mt make_tuple #define gt(tpl,x) get(tpl) #define bif(bit,tar) (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 { inline ll Mod(ll x, ll m){ return (x+m)%m; } inline ll sqr(ll x){ return x*x; } inline ll cub(ll x){ return x*x*x; } inline ul Pow(ul a, uint b) { ul res=1; while(b>0) { if(b&1) res*=a; a*=a; b>>=1; } return res; } inline ll Ceil(ld x, ll m){ return ceil(x/m); } inline ld Round(ld x, ll m, uint fx){ if(fx==0) return (ll)round(x/m); else { ul y=Pow(10,fx+1); return round((x*y)/m/y); } } inline ld Log(ll x, int e){ return log(x)/log(e); } inline int bitdigit(ll x){ return 64-__builtin_clzll(x); } inline int popcnt(ll x){ return __builtin_popcountll(x); } inline bool popcnt_OE(ll x){ return __builtin_parityll(x); } inline int fione(ll x){ return __builtin_ffsll(x); } inline int zrcnt(ll x){ return __builtin_ctzll(x); } inline void strins(string &s, string t, ll id){ s.insert(id,t); } 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 string to_hex(ll x) { stringstream ss; ss<(x); return s.str(); } inline ll to_ten(string s, short base){ return stoll(s,nullptr,base); } 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(vi &v, ll u) { ll res=0; //rev(v); each(el,v) { ll idx=eid(el,v); res+=Pow(u,idx)*el; } return res; } template constexpr auto symin(T... a){ return min(initializer_list>{a...}); } template constexpr auto symax(T... a){ return max(initializer_list>{a...}); } 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(set s){ return *s.begin(); } template inline T stmax(set s){ return *s.rbegin(); } }; // zia qu namespace Lady_sANDy { 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 void Sort(T& v){ sort(all(v)); } template inline void Sort(T& v, ll a, ll b){ sort(all(v,a,b)); } 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 void Sorth(T& v){ make_heap(all(v)); sort_heap(all(v)); } template inline ll dst(T& v, I itr){ return distance(v.begin(),itr); } template inline ll dstl(T& v, I itr){ return distance(itr,v.end()); } 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 dst(v,min_element(all(v))); } template inline ll Max_i(const T& v){ return dst(v,max_element(all(v))); } template inline ll LB(const T& v, const U x){ return dst(v,lower_bound(all(v),x)); } template inline ll UB(const T& v, const U x){ return dst(v,upper_bound(all(v),x)); } 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 void pt(T& v, Boolean fn){ partition(all(v),fn); } template inline ll ptp(T& v, Boolean fn){ return dst(v,partition_point(all(v),fn)); } template inline ll Find(T& v, const U x){ auto itr=find(all(v),x); if(itr==v.end()) return -1LL; return dst(v,itr); } template inline void rpl(T& v, U fn, U r){ replace(all(v),fn,r); } template inline void rplif(T& v, Boolean fn, U r){ replace_if(all(v),fn,r); } template inline ul cntif(T& v, Boolean fn){ return count_if(all(v),fn); } template inline T Count(V& v, ll x) { /* Sort(v); //*/ return UB(v,x)-LB(v,x); } template inline T IP(const V& v, const V& u, T init){ return inner_product(all(v),u.begin(),init); } template inline V iot(T n, ll init){ V a(n); iota(all(a),init); return a;} template inline void vins(V& v, T x, ll id){ v.insert(v.begin()+id,x); } template inline void vins(T& v, U u, ll id){ v.insert(v.begin()+id,all(u)); } template inline void vins(T& v, U u, ll id, ll a, ll b){ v.insert(v.begin()+id,all(u,a,b)); } template inline ll ers(T& v, U x){ v.erase(remove(all(v),x),v.end()); return v.size(); } template ll ersif(T& v, Boolean x){ v.erase(remove_if(all(v),x),v.end()); return v.size(); } template inline ll unq(T& v){ Sort(v); v.erase(unique(all(v)),v.end()); return v.size(); } template inline bool eql(const T& v, const T& w){ return (v.size()==w.size() && equal(all(v),w.begin())); } 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,s.size()); 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(V& v) { V s(v.size()+1); partial_sum(all(v),s.begin()); rtt(s,-1); return s; } template inline V adf(V& v) { V res(v.size()); adjacent_difference(all(v),res.begin()); rtt(res, 1); res.resize(v.size()-1); return res; } #ifdef local #define rext(...) static_cast(0) template inline ll vsum(V &v){ return accumulate(all(v),0LL); } template inline ll vsum(V &v, ll a, ll b){ return accumulate(all(v,a,b),0LL); } template inline ld vdsum(V &v){ return accumulate(all(v),0.0L); } template inline ld vdsum(V &v, ll a, ll b){ return accumulate(all(v,a,b),0.0L); } template inline ll vmul(V &v){ return accumulate(all(v),1LL,[](ll acc,ll i){ return acc*i; }); } template inline ll vmul(V &v, ll a, ll b){ return accumulate(all(v,a,b),1LL,[](ll acc,ll i){ return acc*i; }); } template inline ld vdmul(V &v){ return accumulate(all(v),1.0L,[](ll acc,ll i){ return acc*i; }); } template inline ld vdmul(V &v, ll a, ll b){ return accumulate(all(v,a,b),1.0L,[](ll acc,ll i){ return acc*i; }); } #else 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; }); } #endif }; // Lady s&y namespace Heileden { /* BFS Sample template inline void bfs(V>& g, T start, vb& visited) { queue que; que.emplace(start); visited[start]=1; while(!que.empty()) { T v=que.front(); que.pop(); each(nv,g[v]) { if(!visited[nv]) { visited[nv]=1; que.emplace(nv); } } } }//*/ /* DFS Sample template inline void dfs(V>& g, T v, vb& visited) { visited[v]=1; each(nv,g[v]) if(!visited[nv]) dfs(g,nv,visited); }//*/ /* Permutation Sample template inline void nPr(V& v) { Sort(v); do {out(v);} while(nxp(v)); }//*/ /* Binary Search Sample template inline ll MGRBS(T v, U x, ll& ng, ll& ok) { while(abs(ok-ng)>1) { ll mid = (ok+ng)/2; if(v[mid]==x) ok=mid; else ng=mid; } return ok; }//*/ /* Dijikstra-like Sample template inline T dijikstra(const V& v) { pqr pq; T res=0; while(!pq.empty()) { each(el,v) pq.emplace(el+res); res=pq.top(); pq.pop(); } return res; }//*/ // divisor template inline V divisor(T n) { V div; sqrp(i,1,n+1) { if(n%i==0) { div.emplace_back(i); if(i*i!=n) div.emplace_back(n/i); } } Lady_sANDy::Sort(div); return div; } // prime judge inline bool is_prime(ul n) { if(n==1) return 0; sqrp(i,2,n+1) if(n%i==0) return 0; return 1; } // Siege of Eratosthenes inline vb SoE(ll n) { vb prime(n+1,1); if(n>=0) prime[0]=0; if(n>=1) prime[1]=0; sqrp(i,2,n+1) { if(!prime[i]) continue; rep(j,i*i,n+1,i) prime[j]=0; } return prime; } // prime factor template inline V> prmfct(T n) { V> res; rep(i,2,n+1) { if(n%i!=0) 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; } // Manacher V manacher(const string &s) { const int n = s.size(); V radius(n); int i = 0, j = 0; while(i < n) { while(i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j; radius[i] = j; int k = 1; while(i - k >= 0 && i + k < n && k + radius[i - k] < j) { radius[i + k] = radius[i - k]; ++k; } i += k; j -= k; } return radius; } // factorial template T factorial(T n) { T res=1; while(n>0) res*=n--; return res; } // permutation template T perm(T n, T r) { T tmp=n; T res=1; while(n>tmp-r) res*=n--; return res; } // binomial template T binom(T n, T r) { if(r < 0 || n < r) return 0; T ret = 1; rep(i,1,r) { ret *= n--; ret /= i; } return ret; } // integer judge inline bool is_int(ld n){ ll r=floor(n); return r==n; } inline bool is_sqr(ll n){ return is_int(sqrt(n)); } /* grundy sample template inline bool grundy(V v) { ll res=0; each(el,v) res^=el; return res!=0; }//*/ }; // Heileden //constexpr const int mod=MOD; constexpr const int mod=M0D; struct mint{ uint num = 0; constexpr mint() noexcept {} constexpr mint(const mint &x) noexcept : num(x.num){} constexpr operator ll() const noexcept { return num; } constexpr mint& operator+=(mint x) noexcept { num += x.num; if(num >= mod) num -= mod; return *this; } constexpr mint& operator++() noexcept { if(num == mod - 1) num = 0; else num++; return *this; } constexpr mint operator++(int) noexcept { mint ans(*this); operator++(); return ans; } constexpr mint operator-() const noexcept { return mint(0) -= *this; } constexpr mint& operator-=(mint x) noexcept { if(num < x.num) num += mod; num -= x.num; return *this; } constexpr mint& operator--() noexcept { if(num == 0) num = mod - 1; else num--; return *this; } constexpr mint operator--(int) noexcept { mint ans(*this); operator--(); return ans; } constexpr mint& operator*=(mint x) noexcept { num = ul(num) * x.num % mod; return *this; } constexpr mint& operator/=(mint x) noexcept { return operator*=(x.inv()); } template constexpr mint(T x) noexcept { using U = typename conditional= 4, T, int>::type; U y = x; y %= U(mod); if(y < 0) y += mod; num = uint(y); } template constexpr mint operator+(T x) const noexcept { return mint(*this) += x; } template constexpr mint& operator+=(T x) noexcept { return operator+=(mint(x)); } template constexpr mint operator-(T x) const noexcept { return mint(*this) -= x; } template constexpr mint& operator-=(T x) noexcept { return operator-=(mint(x)); } template constexpr mint operator*(T x) const noexcept { return mint(*this) *= x; } template constexpr mint& operator*=(T x) noexcept { return operator*=(mint(x)); } template constexpr mint operator/(T x) const noexcept { return mint(*this) /= x; } template constexpr mint& operator/=(T x) noexcept { return operator/=(mint(x)); } constexpr mint inv() const noexcept { ll x = 0, y = 0; extgcd(num, mod, x, y); return x; } static constexpr ll extgcd(ll a, ll b, ll &x, ll &y) noexcept { ll g = a; x = 1; y = 0; if(b){ g = extgcd(b, a % b, y, x); y -= a / b * x; } return g; } constexpr mint pow(ul x) const noexcept { mint ans = 1, cnt = *this; while(x){ if(x & 1) ans *= cnt; cnt *= cnt; x /= 2; } return ans; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.num; return os; } friend istream &operator>>(istream &is, mint &a) { ll t; is >> t; a=mint(t); return (is); } }; #define MINT(...) mint __VA_ARGS__; in(__VA_ARGS__) using vm = V; using wm = V; using pm = PP; vm fac(1,1),inv(1,1); void reserve(ll a){ if(fac.size()>=a) return; if(a=mod) a=mod; while(fac.size()>24){ mint ans=1; rep(r) ans*=n--; return ans; } reserve(n+1); return fac[n]*inv[n-r]; } mint nCr(ll n,ll r){ if(r<0 || n=M0D) fin(0); ll m=n/rng; n%=rng; debug(m,n); debug(a[m],fact(n)); mint ans=a[m]+fact(n); out(ans);//*/ }