#include #define REP(i,n) for(int i=0,i##_len=int(n);i class SegmentTree{ private: typedef std::function F; int n; T d0; vector vertex; F f; F g; public: SegmentTree(F f,F g,T d):d0(d),f(f),g(g){} void init(int _n){ n=1; while(n<_n) n*=2; vertex.resize(2*n-1,d0); } void build(const vector &v){ int n_=v.size(); init(n_); for(int i=0;i=0;i--) vertex[i]=f(vertex[2*i+1],vertex[2*i+2]); } void update(int i,T x){ int k=i+n-1; vertex[k]=g(vertex[k],x); while(k>0){ k=(k-1)/2; vertex[k]=f(vertex[2*k+1],vertex[2*k+2]); } return; } T query(int l,int r){ T vl=d0,vr=d0; l+=n-1; r+=n-1; for(;l<=r;l/=2,r=r/2-1){ if(l%2==0) vl=f(vl,vertex[l]); if(r&1) vr=f(vr,vertex[r]); } return f(vl,vr); } }; int main(){ int N;cin>>N; assert(1<=N&&N<=100000); using T = tuple; vector X(N); vector A; const int MAX=1e9; REP(i,N) { int a,b,c; cin>>a>>b>>c; assert(1<=a&&a<=MAX); assert(1<=b&&b<=MAX); assert(1<=c&&c<=MAX); X[i]=tie(a,b,c,i); A.push_back(a); } sort(All(A)); sort(All(X)); vector ord(N); iota(All(ord),0); sort(All(ord),[&](int x,int y){ if(get<0>(X[y])<=get<1>(X[x])-get<2>(X[x])) return true; if(get<0>(X[x])<=get<1>(X[y])-get<2>(X[y])) return false; return get<0>(X[x])>get<0>(X[y]);}); const ll inf = 1LL<<50; SegmentTree dp([](ll a,ll b){return max(a,b);},[](ll a,ll b){return b;},0); SegmentTree bl([](bool a,bool b){return a|b;},[](bool a,bool b){return b;},false); dp.init(N); bl.init(N); for(int i=N-1;i>=0;--i){ int k=upper_bound(All(A),get<1>(X[ord[i]])-get<2>(X[ord[i]]))-A.begin(); ll pl=get<1>(X[ord[i]]); if(k>0) pl+=dp.query(0,k-1); if(bl.query(ord[i],N-1)) pl=inf; dp.update(ord[i],pl); if(k>0) bl.update(k-1,true); } for(int i=N-1;i>=0;--i){ int k=upper_bound(All(A),get<1>(X[ord[i]])-get<2>(X[ord[i]]))-A.begin(); if(k>0) dp.update(ord[i],max(dp.query(ord[i],ord[i]),dp.query(0,k-1))); } vector ans(N); REP(i,N) ans[get<3>(X[i])]=dp.query(i,i); REP(i,N){ if(ans[i]>=inf) cout<<"BAN"<