#include using namespace std; #ifdef _WIN32 #define scanfll(x) scanf("%I64d", x) #define printfll(x) printf("%I64d", x) #else #define scanfll(x) scanf("%lld", x) #define printfll(x) printf("%lld", x) #endif #define rep(i,n) for(long long i = 0; i < (long long)(n); i++) #define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define mt make_tuple #define mp make_pair template bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using ll = long long; using ld = long double; using vll = vector; using vvll = vector; using vld = vector; using vi = vector; using vvi = vector; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; } using P = pair; template ostream &operator<<(ostream &o, const pair &v) { o << "(" << v.first << ", " << v.second << ")"; return o; } template struct seq{}; template struct gen_seq : gen_seq{}; template struct gen_seq<0, Is...> : seq{}; template void print_tuple(basic_ostream& os, Tuple const& t, seq){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get(t)), 0)...}; } template auto operator<<(basic_ostream& os, tuple const& t) -> basic_ostream& { os << "("; print_tuple(os, t, gen_seq()); return os << ")"; } ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; } template ostream &operator<<(ostream &o, const vector &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const set &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const map &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const unordered_map &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; } void printbits(ll mask, ll n) { rep(i, n) { cout << !!(mask & (1ll << i)); } cout << endl; } #define ldout fixed << setprecision(40) // 半開区間!!!なので注意 struct Pool { int pos; char mem[20000000]; // 20MB Pool(){ free(); } template T *fetch(size_t n = 1) { T *res = (T*)(mem + pos); pos += sizeof(T)*n; return res; } void free(){ pos = 0; } }; Pool pool; template class AssosiativeOperator { public: AssosiativeOperator(void) { } T T0; // 単位元 virtual T op(T a, T b) = 0; // 結合二項演算 // 以下は、範囲更新クエリのために必要。点更新しかしないなら、そもそも呼ばれないので、適当な値を返してよい。 T L0; // 単位操作 virtual T op_lazy(T a, T b) = 0; // 遅延更新クエリの結合二項演算。元の値がaで、今新しく来たの値がb。 virtual T resolve_lazy(T d, T l, int nl, int nr) = 0; // 頂点(量d)が、その子ら[nl, nr)の全遅延更新クエリlを解消した時の、頂点の量 }; template class AssosiativeOperatorSum : public AssosiativeOperator { public: AssosiativeOperatorSum(void) { AssosiativeOperator::T0 = 0; AssosiativeOperator::L0 = 0; } virtual T op(T a, T b) { return a + b; } // Range Sum virtual T op_lazy(T a, T b) { return a + b; } // Range Add virtual T resolve_lazy(T d, T l, int nl, int nr) { return d + l * (nr - nl); } // 子の数だけ総和が増える }; template class SegmentTree { public: // dat, lazyのデータ構造 // 0123456789ABCDEF // インターフェースの添字 // ################ // 1--------------- // datの添字, 0は使わない!! // 2-------3------- // 4---5---6---7--- // 8-9-A-B-C-D-E-F- // GHIJKLMNOPQRSTUV // v<<1, v<<1|1は子どもたちを表している // lazy[v]: vとその子供たち[nl, nr)の全員はquery(lazy[v])を遅延しているという意味 T *dat, *lazy; AssosiativeOperator* op; int n = 1; // 確保しているサイズ! int bits = 0; // n == 1 << bits const size_t size_; // 確保しているサイズではない!! int ql, qr; bool enable_range_update_flag = false; bool enable_point_update_with_op_flag = false; SegmentTree(int n_, AssosiativeOperator* op) : size_(n_) { this->op = op; while(n < n_) { n <<= 1; bits++; } dat = pool.fetch(n+n); lazy = pool.fetch(n+n); init(); } void init(void) { fill_n(dat, n*4, this->op->T0); } void enableRangeUpdate(bool flag) { enable_range_update_flag = flag; } void enablePointUpdateWithOp(bool flag) { enable_point_update_with_op_flag = flag; } // 親→子 // これが呼ばれると、必ずvが正しい状態になる! // 親のlazyを解消して子に押し付ける // 子がいなければ押し付けない void inline pushdown(int v, int nl, int nr){ assert(enable_range_update_flag); dat[v] = op->resolve_lazy(dat[v], lazy[v], nl, nr); if(v < n){ // 子がいれば lazy[v<<1] = op->op_lazy(lazy[v<<1], lazy[v]); lazy[v<<1|1] = op->op_lazy(lazy[v<<1|1], lazy[v]); } lazy[v] = op->L0; } // 子→親 void inline pullup(int v){ assert(enable_range_update_flag); dat[v] = op->op(dat[v<<1], dat[v<<1|1]); } // 点更新 void update(int v, const T &x){ v += n; if (enable_point_update_with_op_flag) dat[v] = op->op(dat[v], x); else dat[v] = x; while (v){ v = v >> 1; dat[v] = op->op(dat[v<<1], dat[v<<1|1]); } } // 範囲更新 // 範囲番号nの区間[nl, nr)にop(x)を演算する void update(int n, int nl, int nr, const T &x){ // この関数は、[ql, qr)より上のノードとその子の全てにHITする assert(enable_range_update_flag); pushdown(n, nl, nr); if(nr <= ql || qr <= nl) return; if(ql <= nl && nr <= qr) { // 一回の区間更新に付き最大3回、した区間が小さい順にHitする。 lazy[n] = op->op_lazy(lazy[n], x); pushdown(n, nl, nr); return; } int m = (nl + nr) / 2; update(n<<1, nl, m, x); // 子供1 update(n<<1|1, m, nr, x); // 子供2 pullup(n); } // [l, r)にop(x)の演算を行う。 void update(int l, int r, const T &x){ ql = l; qr = r; return update(1, 0, n, x); } // 範囲クエリ // 範囲番号nの区間[nl, nr)にop(x)を演算結果を返す T query(int n, int nl, int nr){ // この関数は、[ql, qr)より上のノードとその子の全てにHITする if (enable_range_update_flag) pushdown(n, nl, nr); if(nr <= ql || qr <= nl) return op->T0; if(ql <= nl && nr <= qr) return dat[n]; // 一回の区間更新に付き最大3回、した区間が小さい順にHitする。 if (enable_range_update_flag) pullup(n); int m = (nl + nr) / 2; return op->op(query(n<<1, nl, m), query(n<<1|1, m, nr)); } // [l, r)の演算結果を出力 T query(int l, int r){ ql = l; qr = r; return query(1, 0, n); } // lの値を出力 T query(int l){ return query(l, l + 1); } void print(void) { rep(i, size()) { cout << query(i) << " "; } cout << endl; } void printAll(void) { for (int i = 1; i < n * 2; i++) { cout << dat[i]; int j = i, count = 0; while (j) { j /= 2; count++; } for (int j = 0; j < (1 << (bits - count + 1)); j++) cout << "\t"; if (__builtin_popcount(i+1) == 1) cout << endl; } cout << endl; } void printLazy(void) { for (int i = 1; i < n * 2; i++) { cout << lazy[i]; int j = i, count = 0; while (j) { j /= 2; count++; } for (int j = 0; j < (1 << (bits - count) + 1); j++) cout << "\t"; if (__builtin_popcount(i+1) == 1) cout << endl; } cout << endl; } size_t size() const { return size_; } }; // 並列二分探索 // // Incrementalな時変データ構造に対して、 // test(t, q)==trueであるのはいつか?というクエリをQ個処理する // ただしtest(t, q0)はtに対して単調であることを前提とする // // O((qnum qtime + stime + tmax nexttime) log tmax) // qnum: クエリサイズ // qtime: クエリ応答時間 // stime: データ構造の一回構築時間 // tmax: 時間幅最大 template class TimeDependentCharacteristicFunction { public: TimeDependentCharacteristicFunction(void) {}; virtual bool test(query& q) = 0; virtual void next(void) = 0; virtual void init(void) = 0; }; template class BinarySearchParallel { public: ll tmax; TimeDependentCharacteristicFunction* f; vector qs; vector fail, pass; BinarySearchParallel(ll t, TimeDependentCharacteristicFunction* tdcf) : tmax(t), f(tdcf) { } void addQuery(query& q) { qs.push_back(q); } void solve(void) { fail.assign(qs.size(), -1); pass.assign(qs.size(), tmax); rep(stage, (ll)(log(tmax) / log(2) + 2)) { vector check(tmax); rep(i, qs.size()) check[(fail[i] + pass[i]) / 2].push_back(i); f->init(); rep(i, tmax) { f->next(); for (int id : check[i]) if (pass[id] - fail[id] > 1) (f->test(qs[id]) ? pass : fail)[id] = i; } } } }; // ここで定義されるデータ構造がO(log tmax)回構築される。 // // init: データ構造と時間を初期化する // O(stime) // // next: 時間を進めて、データ構造を1つ進める // O(nexttime) // // test: 現在時刻tにおけるデータ構造を用いて、クエリに応答する struct Operator { ll a, b, x; }; template class TD_LazySegementTree : public TimeDependentCharacteristicFunction { public: ll t; ll n; ll h; vector op; SegmentTree s; TD_LazySegementTree(ll n, ll h, vector op) : n(n), h(h), op(op), s(n, new AssosiativeOperatorSum()) { s.enableRangeUpdate(true); this->init(); } bool test(query& q) { return s.query(q, q+1) >= h; } void next(void) { s.update(op[t].x, op[t].x + op[t].a, op[t].b); t++; } void init(void) { s.init(); t = 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, w, h; cin >> n >> w >> h; vector ops(n); rep(i, n) { cin >> ops[i].a >> ops[i].b >> ops[i].x; ops[i].x--; } BinarySearchParallel bsp(n, new TD_LazySegementTree(w, h, ops)); rep(wi, w) bsp.addQuery(wi); bsp.solve(); ll ret = 0; for (auto x : bsp.pass) ret += (x % 2 == 0 ? +1 : -1); if (ret > 0) cout << "A" << endl; else if (ret < 0) cout << "B" << endl; else cout << "DRAW" << endl; return 0; }