#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct SegmentTree{ using F=function; private: int sz; vector seg; Monoid query(int a,int b,int k,int l,int r){ if(a<=l and r<=b) return seg[k]; if(b<=l or r<=a) return M0; Monoid L=query(a,b,2*k,l,(l+r)/2); Monoid R=query(a,b,2*k+1,(l+r)/2,r); return f(L,R); } template int find_first(int a,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz; } int m=(l+r)/2; if(m<=a) return find_first(a,check,acc,2*k+1,m,r); if(a<=l and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_first(a,check,acc,2*k+0,l,m); if(x>=0) return x; return find_first(a,check,acc,2*k+1,m,r); } template int find_last(int b,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz+1;//ここはfalse, +1した位置はtrue } int m=(l+r)/2; if(b<=m) return find_last(b,check,acc,2*k,l,m); if(r<=b and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_last(b,check,acc,2*k+1,m,r); if(x>=0) return x; return find_last(b,check,acc,2*k,l,m); } public: F f; Monoid M0;// モノイドの元 SegmentTree(int n,F f,Monoid M0):f(f),M0(M0){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,Monoid x){ k+=sz; seg[k]=x; k>>=1; for(;k;k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } Monoid query(int a,int b){ return query(a,b,1,0,sz); } // http://codeforces.com/contest/914/submission/107505449 // max x, check(query(a, x)) = true template int find_first(int a,const C &check){ Monoid val=M0; return find_first(a,check,val,1,0,sz); } // http://codeforces.com/contest/914/submission/107505582 // min x, check(query(x, b)) = true template int find_last(int b,C &check){ Monoid val=M0; return find_last(b,check,val,1,0,sz); } }; int func(int a,int b){return a+b;} vector> dp(5001); vector> seg_l(5001,SegmentTree(5001,func,0)),seg_r(5001,SegmentTree(5001,func,0)); void solve(){ int n;ll x;cin>>n>>x; vector v(n); cin>>v; vector s(n); s[0]=v[0]; for(int i=1;i>n>>x; vector v(n); cin>>v; for(int w=2;w<=n;w++){ for(int l=0;l+w<=n;l++){ int r=l+w;// [l,r) bool win=false; // left { ll s=v[l]; for(int i=l+1;il and s<=x;i--){ if(!dp[l][i]) win=true; s+=v[i-1]; } } dp[l][r]=win; } } cout<<(dp[0][n]?"A":"B")<