#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct BIT{ int n; vector bit; //1-indexed BIT(int n_):n(n_+1),bit(n,0){} T sum(int i){ T s(0); for(int x=i;x>0;x-=(x&-x)) s+=bit[x]; return s; } void add(int i,T a){ if(i==0) return; for(int x=i;x<=n;x+=(x&-x)) bit[x]+=a; } int lower_bound(int w){ if(w<=0) return 0; int x=0,r=1; while(r0;k>>=1){ if(x+k<=n&&bit[x+k]>n>>x; vector as(n); for(int i=0;i>as[i]; //vector sm(n+1,0); //for(int i=0;i ls(n),rs(n); for(int i=0;i=0&&sm+as[j]<=x){ sm+=as[j]; j--; } ls[i]=j+1; } { int j=i+1,sm=0; while(j; vector bl(n,B(n+1)); vector br(n,B(n+1)); for(int w=1;w<=n;w++){ for(int l=0;l+w<=n;l++){ // [l, r] int r=l+w-1; dp[l][r]|=bl[l].sum0(r); dp[l][r]|=br[r].sum0(l); if(dp[l][r]) continue; bl[l].add0(r+1,1); bl[l].add0(rs[r]+1,-1); if(l){ br[r].add0(l-1,-1); br[r].add0(ls[l],1); } } } cout<<(dp[0][n-1]?"A":"B")<