#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; template struct SegmentTree{ using F = function; int n; F f;//二項演算 T ti;//単位元 vector dat; SegmentTree(){} SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){//sizeがn_のsegtreeを作る n=1; while(n &v){//vによってsegtreeをbuildする int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){//区間[a,b)に対しFを適応した値を返す if(a>=b) return ti; T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template int find(int st,C &check,T &acc,int k,int l,int r){// if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?k-n:-1; } int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l&&!check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template int find(int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } T &operator [] (int i) {return dat[i+n];}; }; int n;ll x; ll a[5010]; bool dp[5010][5010]; int S1[5010][5010],S2[5010][5010]; int max1[5010],max2[5010]; void solve(){ cin >> n >> x; rep(i,n){ cin >> a[i+1]; } a[0]=INF; a[n+1]=INF; int j=1;ll S=a[1]; Rep(i,1,n+1){ while(S+a[j+1]<=x){ j+=1; S+=a[j]; } max1[i]=j; S-=a[i]; } j=n;S=a[n]; Per(i,1,n+1){ while(S+a[j-1]<=x){ j-=1; S+=a[j]; } max2[i]=j; S-=a[i]; } // rep(i,n){ // cout << max1[i+1] << " "; // } // cout << "" << endl; // rep(i,n){ // cout << max2[i+1] << " "; // } // cout << "" << endl; bool ans; Rep(d,1,n+2){ rep(i,n+2-d){ int j=i+d; dp[i][j]=1; if(d==1){ dp[i][j]=1; } else{ //cout << seg1[j].query(i+1,min(max1[i+1]+1,j)) << endl; //cout << seg2[i].query(max(i+1,max2[j-1]),j) << endl; dp[i][j]&=(S1[j][i+1]-S1[j][min(max1[i+1]+1,j)]==min(max1[i+1]+1,j)-i-1); dp[i][j]&=(S2[i][j-1]-S2[i][max(i,max2[j-1]-1)]==j-1-max(i,max2[j-1]-1)); dp[i][j]^=1; //cout << s << endl; } //cout << i << " " << j << " " << dp[i][j] << endl; //cout << S1[j][i+1]-S1[j][min(max1[i+1]+1,j)] << endl; //cout << S2[i][j-1]-S2[i][max(i,max2[j-1]-1)] << endl; S1[j][i]=S1[j][i+1]+dp[i][j]; S2[i][j]=S2[i][j-1]+dp[i][j]; } } if(dp[0][n+1]) cout << "A" << endl; else cout << "B" << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }