#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class BinaryIndexedTree { private: int n; vector data; public: BinaryIndexedTree(int n){ // コンストラクタ this->n = n; data.assign(n+1, 0); } void add(int k, long long x){ // k番目の要素にxを加算する ++ k; while(k <= n){ data[k] += x; k += k & -k; } } long long sum(int k){ // 区間[0,k]の総和を返す ++ k; long long ret = 0; while(k > 0){ ret += data[k]; k -= k & -k; } return ret; } long long sum(int a, int b){ // 区間[a,b]の総和を返す return sum(b) - sum(a-1); } int upper_bound(long long x){ // 総和が初めてxを超える位置を返す(ただし、各位置の数値が非負数であることを前提とする) int b = 1; while(b < n) b *= 2; int a = 0; while(b > 0){ if(a+b <= n && x >= data[a+b]){ x -= data[a+b]; a += b; } b /= 2; } return (a < n)? a : -1; } int lower_bound(long long x){ // 総和が初めてx以上になる位置を返す(ただし、各位置の数値が非負数であることを前提とする) return upper_bound(x-1); } }; int main() { int n, w; long long h; cin >> n >> w >> h; vector > v(2*n); for(int i=0; i> a >> b >> x; v[2*i] = make_tuple(x-1, i, b); v[2*i+1] = make_tuple(x-1+a, i, -b); } sort(v.begin(), v.end()); BinaryIndexedTree bit(n); int k = 0; int cnt = 0; for(int x=0; x(v[k]) == x){ bit.add(get<1>(v[k]), get<2>(v[k])); ++ k; } int i = bit.lower_bound(h); if(i % 2 == 0) ++ cnt; } if(cnt > w - cnt) cout << 'A' << endl; else if(cnt == w - cnt) cout << "DRAW" << endl; else cout << 'B' << endl; return 0; }