#include #define REP(i,n) for(int i=0,i##_len=int(n);i>N; vector A(N),B(N),C(N); REP(i,N) cin>>A[i]>>B[i]>>C[i]; vector>> graph(N); vector num(N); REP(i,N) REP(j,N) if(i!=j){ if(A[i]<=B[j]-C[j]){ graph[i].push_back(make_pair(-B[i],j)); num[j]++; } } queue L,S; REP(i,N){ if(num[i]==0) S.push(i); } while(!S.empty()){ int n=S.front();S.pop(); L.push(n); REP(j,graph[n].size()){ int v=graph[n][j].second; num[v]--; if(num[v]==0) S.push(v); } } vector dist(N); vector negative(N,true); while(!L.empty()){ int u=L.front();L.pop(); negative[u]=false; for(auto e:graph[u]){ int v=e.second; dist[v]=min(dist[v],dist[u]+e.first); } } REP(i,N){ if(negative[i]) cout<<"BAN"<