#include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o< class SegTree { public: int n; vector segMax, segAdd; vector segIdx; void _add(int a, int b, T x, int k, int l, int r){ if(r<=a || b<=l) return; if(a<=l && r<=b){segAdd[k]+=x; return;} int cl = k*2+1, cr = k*2+2; _add(a,b,x,cl,l,(l+r)/2); _add(a,b,x,cr,(l+r)/2,r); T vl = segMax[cl]+segAdd[cl]; T vr = segMax[cr]+segAdd[cr]; if(vl > vr){ segMax[k] = vl; segIdx[k] = segIdx[cl]; } else { segMax[k] = vr; segIdx[k] = segIdx[cr]; } } pair _max(int a, int b, int k, int l, int r){ // (tree上でのidx) if(r<=a || b<=l) return mp(-INF, n-1); if(a<=l && r<=b) return mp(segMax[k]+segAdd[k], segIdx[k]); pair vl = _max(a,b,k*2+1,l,(l+r)/2); pair vr = _max(a,b,k*2+2,(l+r)/2,r); if(vl.fi > vr.fi) return mp(vl.fi+segAdd[k], vl.se); else return mp(vr.fi+segAdd[k], vr.se); } SegTree(int n_){ n=1; while(n=0; i--) segIdx[i] = 2*i+1; } inline void add(int a, int b, T x){ _add(a,b,x,0,0,n);} //add x in [a,b) inline pair getMax(int a,int b){return _max(a,b,0,0,n);} }; int main(){ long n,w,h; cin>>n>>w>>h; SegTree st(w); vector a(n),b(n),x(n); rep(i,n) cin>>a[i]>>b[i]>>x[i]; rep(i,n) x[i]--; int p[2] = {0,0}; rep(i,n){ st.add(x[i], x[i]+a[i], b[i]); int cnt=0; while(true){ auto val = st.getMax(x[i],x[i]+a[i]); // dbg(mp(val.fi, val.se - (st.n-1))); if(val.fi=w) break; } if(p[0]>p[1]) cout << "A" << endl; else if(p[0]==p[1]) cout << "DRAW" << endl; else cout << "B" << endl; return 0; }