#include #include using namespace atcoder; templatestruct ve; using ml=modint;using m1=ve; auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} auto&operator<<(std::ostream&o,const ml&x){return o<0;) #define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i=i##O;i-=i##E) #define debug(...) pp(#__VA_ARGS__,__VA_ARGS__) #define JO(s,t) s##t #define jo(s,t) JO(s,t) #define I(...) template<__VA_ARGS__> #define J typename #define O operator #define au auto #define cs const #define ifc if constexpr #define rr return #define uu using uu std::cin,std::cout,std::begin,std::end,std::rbegin; uu std::deque,std::tuple,std::array,std::bitset; uu std::swap,std::move,std::minmax,std::gcd,std::lcm; I(J T)uu ilis=std::initializer_list; uu vo=void; vo solve(); uu bo=bool; I(J A,J B)constexpr bo same=std::is_same_v; I(bo b,J A,J B)uu ift=std::conditional_t; uu is=std::istream;uu os=std::ostream; uu dd=long double;uu ll=long long; uu ull=unsigned long long; uu lll=__int128_t;uu ulll=__uint128_t; uu str=std::string; ll oo=3e18,i998244353=998244353,i1000000007=1000000007; arraydx{-1,0,1,0,-1,1,1,-1},dy{0,-1,0,1,-1,-1,1,1}; dd ee=1e-12,pi=acosl(-1); str sp=" ",nc="",nl="\n"; I(J T,J U=T)uu map=std::map; I(J T,J U=T)uu umap=std::unordered_map; I(J T)uu qmax=std::priority_queue; I(J T)uu qmin=std::priority_queue,std::greater<>>; I(J T,ll n)au TP(){ifc(n)rr tuple_cat(tuple(T()),TP());else rr tuple();} I(J T,ll n)uu tp=decltype(TP());I(ll n)uu tpl=tp; tpl<3>rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr{a,b-s,c};} ll rnd(ll l,ll r=oo){static ull a=76,b=53,c=20,d=41;ull t=a^(a<<11);a=b,b=c,c=d,d=(d^(d>>19))^(t^(t>>8));rr r==oo?d%l:d%(r-l)+l;} bo odd(ll x){rr x&1;}bo eve(ll x){rr~x&1;} ll pwm1(ll x){rr 1-2*(x&1);}ll pw2(ll n){rr 1LL<>i&1;} ll l2(ulll x){x|=1;ll r=0;wh(x)x>>=1,++r;rr r;} ll l10(ulll x){x|=1;ll r=0;wh(x)x/=10,++r;rr r;} I(J T,J U,J V)bo in(T l,U x,V r){rr l<=x&&x=0?x/y:(x+1)/y-1;} I(J T)T cei(T x,T y){rr y<0?x=-x,y=-y:x<=0?x/y:(x-1)/y+1;} I(J T)T sq(T a){rr a*a;} I(J T)T zz(T x){rr x<0?-x:x;} I(J T)ll len(cs T&a){rr a.size();} I(J T)bo add(T&a,cs T&b){rr a+=b,1;} I(J T,J U)bo amax(T&a,cs U&b){rr ab?a=b,1:0;} struct edg{ll t,w;edg(){}edg(ll t,ll w=1):t(t),w(w){}}; I(J A,J B=A)struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(std::pairp):a(p.first),b(p.second){} cp O-()cs{rr cp(-a,-b);} cp&O+=(cs cp&c){a+=c.a,b+=c.b;rr*this;}cp O+(cs cp&c)cs{rr cp{*this}+=c;} cp&O-=(cs cp&c){a-=c.a,b-=c.b;rr*this;}cp O-(cs cp&c)cs{rr cp{*this}-=c;} bo O<(cs cp&c)cs{rr a!=c.a?a(cs cp&c)cs{rr a!=c.a?a>c.a:b>c.b;} bo O==(cs cp&c)cs{rr a==c.a&&b==c.b;} };uu cl=cp; I(J A,J B=A,J C=A)struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo O<(cs tr&t)cs{rr a!=t.a?a(cs tr&t)cs{rr a!=t.a?a>t.a:b!=t.b?b>t.b:c>t.c;} };uu tl=tr; I(J V)struct ve; I(J V)constexpr bo isv=0; I(J V)constexpr bo isv> =1; I(J V)constexpr bo isv> =1; I(J V)au pure_val(V){ifc(isv)rr pure_val(J V::value_type());else rr V();} I(J V)struct ve:std::vector{ uu std::vector::vector; uu pure_type=decltype(pure_val(V())); ve(cs std::vector&v={}){fe(v,e)this->eb(e);} au&O+=(cs ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;} au&O-=(cs ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;} au&O^=(cs ve&u){fe(u,e)this->eb(e);rr*this;} au&O+=(cs pure_type&c){au&v=*this;fe(v,e)e+=c;rr v;} au&O-=(cs pure_type&c){au&v=*this;fe(v,e)e-=c;rr v;} au O+(cs ve&u){rr ve(*this)+=u;} au O-(cs ve&u){rr ve(*this)-=u;} au O^(cs ve&u){rr ve(*this)^=u;} au O-(){ve r=*this;fe(r,e)e=-e;rr r;} au O+(cs pure_type&c){rr ve(*this)+=c;}au&O++(){rr*this+=1;} au O-(cs pure_type&c){rr ve(*this)-=c;}au&O--(){rr*this-=1;} au lower_bound(cs V&x){rr std::lower_bound(all(*this),x);} au upper_bound(cs V&x){rr std::upper_bound(all(*this),x);} ll arglb(cs V&x){rr lower_bound(x)-begin(*this);} ll argub(cs V&x){rr upper_bound(x)-begin(*this);} ll argmax(){rr std::max_element(all(*this))-begin(*this);} ll argmin(){rr std::min_element(all(*this))-begin(*this);} au ika_max(cs V&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs V&x){rr this->lower_bound(x);} vo af(V e={}){this->ep(begin(*this),e);} vo df(){this->erase(begin(*this));} I(bo f(pure_type&,cs pure_type&))au scan(){ cpr; fe(*this,e){ ifc(!isv)r.b?f(r.a,e),r:r={e,1}; ef(au t=e.template scan();t.b)r.b?f(r.a,t.a),r:r=t; } rr r; } au sum(){rr scan().a;} au max(){rr scan().a;} au min(){rr scan().a;} vo fill(pure_type x={}){fe(*this,e)ifc(isv)e.fill(x);else e=x;} au zeta(){ve v=*this;ifc(isv)fe(v,e)e=e.zeta();fo(i,len(v)-1)v[i+1]+=v[i];rr v;} au mobi(){ve v=*this;ifc(isv)fe(v,e)e=e.mobi();of(i,len(v)-1)v[i+1]-=v[i];rr v;} au de(cs str&b="a"){ ift,ve,str>r; ifc(isv)fe(*this,e)r.eb(e.de(b)); else fe(*this,e)r+=len(b)==1?e+b[0]:0<=e&&e(s[i],x); else{au X=vec(s,x);rr ve(s[i],X);} } I(ll n,J...A)vo setsize(cs ll(&l)[n],A&...a){((a=vec(l,pure_val(a))),...);} I(J T)uu V1=ve;uu u1=V1;I(J T)uu V2=V1>;uu u2=V2; uu cls=V1;uu tls=V1;uu strs=V1;uu gra=V2; I(J T)struct set:std::set{ set(cs V1&a={}){fe(a,e)this->ep(e);} au ika_max(cs T&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs T&x){rr this->lower_bound(x);} au between(cs T&l,cs T&r){au p=this->lower_bound(l),q=this->lower_bound(r);rr cp{p,q};} friend os&O<<(os&o,cs set&s){fe(s,e)o<{ mset(cs V1&a={}){fe(a,e)this->ep(e);} vo uerase(cs T&x){if(au p=this->find(x);p!=this->end())this->erase(p);} au ika_max(cs T&x){au p=this->upper_bound(x);rr p!=this->begin()?prev(p):this->end();} au ijo_min(cs T&x){rr this->lower_bound(x);} au between(cs T&l,cs T&r){au p=this->lower_bound(l),q=this->lower_bound(r);rr cp{p,q};} friend os&O<<(os&o,cs mset&s){fe(s,e)o<{ uset(cs V1&a={}){fe(a,e)this->ep(e);} friend os&O<<(os&o,cs uset&s){fe(s,e)o<&s){T r=bg(s);s.erase(begin(s));rr r;} I(J T)T pof(mset&s){T r=bg(s);s.erase(begin(s));rr r;} I(J T)T pob(set&s){T r=rb(s);s.erase(--end(s));rr r;} I(J T)T pob(mset&s){T r=rb(s);s.erase(--end(s));rr r;} I(J T)T&srt(T&a){sort(all(a));rr a;} I(J T)T&rv(T&a){reverse(all(a));rr a;} I(J T)T&rsr(T&a){rr rv(srt(a));} I(J T)T&uq(T&a){srt(a).erase(unique(all(a)),end(a));rr a;} I(J T)decltype(au)bg(T&a){rr*begin(a);} I(J T)decltype(au)rb(T&a){rr*rbegin(a);} I(J T)au pof(T&a){au r=bg(a);a.pop_front();rr r;} I(J T)au pob(T&a){au r=rb(a);a.pop_back();rr r;} I(J T)au pot(T&a){au r=a.top();a.pop();rr r;} I(J...A)au max(cs A&...a){rr max(ilis>{a...});} I(J...A)au min(cs A&...a){rr min(ilis>{a...});} struct fio{fio(){cin.tie(0)->sync_with_stdio(0); cout<&v){fe(v,e)o<&c){rr o<&m){fe(m,e)o<&t){apply([&](cs au&...a){ll i=0;(((o<>(is&i,std::vector&v){fe(v,e)i>>e;rr i;} I(J V)os&O<<(os&o,cs std::vector&v){ str s=nl; ifc(!isv)s=sp;else ifc(isv)s+=nl; fe(v,e)o<>...>>a);} I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} vo Yes(bo y=1){pp(y?"Yes":"No");}vo No(){Yes(0);} gra tog(cs u2&a){gra g;fe(a,e){g.eb();fe(e,v)rb(g).eb(v);}rr g;} u2 tou(cs gra&g){u2 a;fe(g,e){a.eb();fe(e,v,w)rb(a).eb(v);}rr a;} au gi(gra&g,ll m,bo y=0,bo f=0){UV(m,a,b,c);a-=!f,b-=!f;fo(i,m)g[a[i]].eb(b[i],c[i]),!y?g[b[i]].eb(a[i],c[i]),0:0;rr tuple{a,b,c};} au gi(u2&g,ll m,bo y=0,bo f=0){UV(m,a,b);a-=!f,b-=!f;fo(i,m)g[a[i]].eb(b[i]),!y?g[b[i]].eb(a[i]):0;rr tuple{a,b};} I(J G)au ti(G&g,bo y=0,bo f=0){rr gi(g,len(g)-1,y,f);} u1 en(cs str&s,cs str&b="a"){u1 r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));rr r;} u1 sien(cs str&b="a"){ST(s);rr en(s,b);} u2 en(cs strs&s,cs str&b="a"){u2 r;fe(s,e)r.eb(en(e,b));rr r;} u2 sien(ll n,cs str&b="a"){u2 r;fo(n)r.eb(sien(b));rr r;} I(J F)struct rec:F{rec(F&&f):F(std::forward(f)){}I(J...A)decltype(au)O()(A&&...a)cs{rr F::O()(*this,std::forward(a)...);}}; I(J...A)vo dec(A&...a){((--a),...);} u1 it(ll n,ll x=0){u1 a;fo(i,n)a.eb(i+x);rr a;} I(J...A)u1 zp(A&...a){u1 v=(a^...);uq(v);([&](u1&u){fe(u,e)e=v.arglb(e);}(a),...);rr v;} I(J F,J...A)u1 vs(F f,A&...a){u1 o=it((len(a)&...));sort(all(o),f);([&](au&e){au c=e;fo(i,len(e))e[i]=c[o[i]];}(a),...);rr o;} I(J F)dd bsd(F f,dd o,dd n){fo(log2(zz(o-n)/ee)+5)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} I(J F)ll bsl(F f,ll o,ll n){wh(zz(o-n)>1)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} ll sqr(ll x){ll r=sqrt(zz(x-ee));wh(r+1<=x/(r+1))++r;rr r;} u1 divs(ll n){u1 r;fo(i,1,sqr(n)+1)if(n%i==0)r.eb(i),r.eb(n/i);rr uq(r);} cls fact(ll n){umapm;fo(i,2,sqr(n)+1)wh(n%i==0)++m[i],n/=i;if(n>1)++m[n];cls r;fe(m,e)r.eb(e);rr srt(r);} cls rle(cs u1&a){cls r;fe(a,e)len(r)&&e==rb(r).a?++rb(r).b:r.eb(e,1).b;rr r;} cls rce(u1 a){rr rle(srt(a));} lll pow(lll x,lll n,ll m=0){lll r=1;wh(n)n&1?r*=x:r,x*=x,m?r%=m,x%=m:r,n>>=1;rr r;} int main(){ll T=1;fo(T)solve();} I(J T)T fill(ll x){ ifc(same)rr x; else ifc(same)rr T(x,x); else ifc(same)rr T(x,x,x); else ifc(same>){T r;fe(r,e)e=x;rr r;} else ifc(same>>){ T r;apply([&](au&...a){((a=x),...);},r);rr r; }else assert(0); } I(J T)T moo(){rr fill(-oo);} I(J T)T poo(){rr fill(oo);} I(J T)T uni(){rr{};} I(J T)T op_max(T a,T b){rr max(a,b);} I(J T)T op_min(T a,T b){rr min(a,b);} I(J T)T op_sum(T a,T b){rr a+b;} I(J T)T op_mul(T a,T b){rr a*b;} I(J T)uu seg_max=segtree,moo>; I(J T)uu seg_min=segtree,poo>; I(J T)uu seg_sum=segtree,uni>; I(J S)ll kth_on_segtree(seg_sum&s,ll k,ll l=0){ rr s.max_right(l,[&](S v){rr v&s,ll x,ll l){ rr s.max_right(l,[&](S v){rr v>x;}); } I(J S)ll ika_righmost(seg_min&s,ll x,ll r){ rr s.min_left(r,[&](S v){rr v>x;})-1; } I(J S)ll ijo_leftmost(seg_max&s,ll x,ll l){ rr s.max_right(l,[&](S v){rr v&s,ll x,ll r){ rr s.min_left(r,[&](S v){rr vrot45(cs u1&x,cs u1&y){ ll n=len(x); u1 u(n),v(n); fo(i,n){ u[i]=x[i]-y[i]; v[i]=x[i]+y[i]; } rr cp{u,v}; } bo issquare(cs u1&x,cs u1&y){ ll n=4; u1 v; fo(i,n)fo(j,i+1,n)v.eb(sq(x[i]-x[j])+sq(y[i]-y[j])); srt(v); ll a=bg(v); if(a==0)rr 0; rr v[0]==a&&v[3]==a&&v[4]==a*2&&v[5]==a*2; } bo iscube(cs u1&x,cs u1&y,cs u1&z){ ll n=8; u1 v; fo(i,n)fo(j,i+1,n)v.eb(sq(x[i]-x[j])+sq(y[i]-y[j])+sq(z[i]-z[j])); srt(v); ll a=bg(v); if(a==0)rr 0; rr v[0]==a&&v[11]==a&&v[12]==a*2&&v[23]==a*2&&v[24]==a*3&&v[27]==a*3; } vo solve(){ LL(N); UV(N,t,x,v); t.eb(),x.eb(),v.eb(); u1 a=x+t,b=-x+t; ll M=len(zp(a,b)); seg_maxs(M); s.set(a[N],0); u2 g(M); fo(i,N)g[a[i]].eb(i); u1 res(N); fo(k,a[N],M){ fe(g[k],i)res[i]=s.prod(0,b[i]+1)+v[i]; fe(g[k],i)s.set(b[i],max(s.get(b[i]),res[i])); } pp(res.max()); }