#include using namespace std; using Int = long long; template struct SegmentTree{ typedef function F; typedef function G; typedef function H; typedef function P; Int n; F f; G g; H h; P p; T d1; E d0; vector dat; vector laz; SegmentTree(Int n_,F f,G g,H h,T d1,E d0, vector v=vector(),P p=[](E a,Int b){return a;}): f(f),g(g),h(h),d1(d1),d0(d0),p(p){ init(n_); if(n_==(Int)v.size()) build(n_,v); } void init(Int n_){ n=1; while(n v){ for(Int i=0;i=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]); } inline void eval(Int len,Int k){ if(laz[k]==d0) return; if(k*2+1>n>>p; vector h(n+1,INF); for(Int i=0;i>h[i]; SegmentTree ushi(n+1, [](Int a,Int b){ return min(a,b); }, [](Int a,Int b){ return a+b; }, [](Int a,Int b){ return a+b; }, INF,Int(0),vector(n+1,0)); SegmentTree beet=ushi; vector dp(n,INF); dp[0]=0; ushi.update(1,2,p); for(Int i=1;i