#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using i64 = long long; template struct BIT{ vector elm; BIT(int n, T init = T()) : elm(n + 1, init){ } // [0, x) T sum(int x){ T val = 0; for(; x > 0; x -= x & -x) val += elm[x]; return val; } // [l, r) T sum(int l, int r){ return sum(r) - sum(l); } void add(int x, T val){ for(++x; x < elm.size(); x += x & -x) elm[x] += val; } }; signed main(){ int n, x; cin >> n >> x; vector v(n); for(auto& x : v) cin >> x; vector r(n + 1, 0); for(int i = 0; i < n; ++i) r[i + 1] = r[i] + v[i]; vector nex(n, n), prev(n, 0); for(int i = 0; i < n; ++i){ auto it = upper_bound(r.begin(), r.end(), r[i + 1] + x); int idx = distance(r.begin(), it); nex[i] = idx - 1; auto it2 = lower_bound(r.begin(), r.end(), r[i] - x); idx = distance(r.begin(), it2); prev[i] = idx; } vector> a(n, BIT(n)), b(n, BIT(n)); for(int k = 1; k < n; ++k) for(int i = 0, j = k; j < n; ++i, ++j){ bool f = false; // TODO: set len // dp[i][j] : dp[i][j - x, j) // cout << j - prev[j] << " " << nex[i] - (i + 1) << " "; f |= (a[i].sum(max(i, prev[j]), j) != (j - max(i, prev[j]))); // dp[i][j] : dp[i, i + x][j, j) f |= (b[j].sum(i + 1, min(nex[i], j + 1)) != (min(nex[i], j + 1) - (i + 1))); if(f){ a[i].add(j, 1); b[j].add(i, 1); } // cout << "[" << i << "," << j << "] -> " << (f ? "Win" : "Lose") << endl; } /* for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j) cout << a[i].sum(j, j + 1) << " \n"[j == n - 1]; } cout << endl; */ cout << (a[0].sum(n - 1, n) ? "A" : "B") << endl; }