#include #define pt(sth) cout << sth << "\n" #define itr(x,c) for(auto x=c.begin();x!=c.end();x++) #define ritr(x,c) for(auto x=c.rbegin();x!=c.rend();x++) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define __builtin_popcount(v) popcount(v) using namespace std; #include using namespace atcoder; typedef long long ll; typedef pair pll; templatebool chmax(T &a, const T &b) {if(abool chmin(T &a, const T &b) {if(b>a[i]; typedef vector v1d; typedef vector v2d; typedef vector v3d; typedef vector v4d; struct S{ll M, m1, m2;}; S op(S a, S b){ ll M=max(a.M,b.M); ll m1=min(a.m1,b.m1); ll m2=a.m1>N; segtree seg(N); for(i=0;i>a; seg.set(i,{a,a,INF}); } ll ans=0; for(i=0;i