#include using namespace std; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a V compress(V v){ sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return v; } template map dict(const vector &v){ map res; for(Int i=0;i<(Int)v.size();i++) res[v[i]]=i; return res; } map dict(const string &v){ return dict(vector(v.begin(),v.end())); } struct SCC{ vector< vector > G,R,T,C; vector vs,used,blg; SCC(){} SCC(Int n):G(n),R(n),used(n),blg(n){} void add_edge(Int u,Int v){ G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(Int v){ used[v]=1; for(Int u:G[v]) if(!used[u]) dfs(u); vs.emplace_back(v); } void rdfs(Int v,Int k){ used[v]=1; blg[v]=k; C[k].emplace_back(v); for(Int u:R[v]) if(!used[u]) rdfs(u,k); } Int build(){ Int n=G.size(); for(Int v=0;v=0;i--){ if(!used[vs[i]]){ T.emplace_back(); C.emplace_back(); rdfs(vs[i],k++); } } for(Int v=0;v void drop(const T &x){cout<>n; vector as(n),bs(n),cs(n); for(Int i=0;i>as[i]>>bs[i]>>cs[i]; vector vs(as); for(Int i=0;i cnt(k,0); for(Int i=0;i dp(k,0); for(Int i=k-1;i>=0;i--){ if(cnt[i]>1){ dp[i]=INF; continue; } for(Int j:T[i]) chmax(dp[i],dp[j]); for(Int v:C[i]) if(v ans(n); for(Int i=0;i=INF) cout<<"BAN"<