#include using namespace std; #define rep(i,a,b) for(int i=a;i class SegTreeAddMaxWithIndex { public: vector > val; vector > ma; #define def -INF SegTreeAddMaxWithIndex() { int i; val.resize(NV * 2); ma.resize(NV * 2); rep(i, 0, NV) val[i + NV] = ma[i + NV] = make_pair(0, i); rep(i, 0, NV) val[i] = make_pair(0, 0); for (i = NV - 1; i >= 1; i--) ma[i] = max(ma[2 * i], ma[2 * i + 1]); }; pair getval(int x, int y, int l = 0, int r = NV, int k = 1) { if (r <= x || y <= l) return make_pair(def, 0); if (x <= l && r <= y) return ma[k]; auto a = max(getval(x, y, l, (l + r) / 2, k * 2), getval(x, y, (l + r) / 2, r, k * 2 + 1)); a.first += val[k].first; return a; } void update(int x, int y, V v, int l = 0, int r = NV, int k = 1) { if (l >= r) return; if (x <= l && r <= y) { val[k].first += v; ma[k].first += v; } else if (l < y && x < r) { update(x, y, v, l, (l + r) / 2, k * 2); update(x, y, v, (l + r) / 2, r, k * 2 + 1); ma[k] = max(ma[k * 2], ma[k * 2 + 1]); ma[k].first += val[k].first; } } }; //----------------------------------------------------------------------------------- int N, W; ll H; SegTreeAddMaxWithIndex st; ll P[2]; int ok; int main() { cin >> N >> W >> H; rep(i, 0, N) { ll a, b, x; cin >> a >> b >> x; st.update(x, a + x, b); while (1) { auto p = st.getval(0, W); if (p.first < H) break; ok++; st.update(p.second, p.second + 1, -INF); } P[i % 2] += ok; if (ok == W) break; } if (P[0] == P[1]) cout << "DRAW" << endl; else if (P[0] < P[1]) cout << "B" << endl; else cout << "A" << endl; }