#include using namespace std; typedef vector vi; typedef pair ii; typedef long long ll; typedef pair l4; typedef vector vll; typedef double db; typedef vector vdb; typedef pair dd; typedef set si; typedef set sll; #define fi first #define se second #define matrix(a) vector< vector > #define sz(a) int((a).size()) #define lop(i,a,b) for (int i=a; i<=b; i++) #define rlop(i,a,b) for (int i=b; i>=a; i--) #define all(s) (s).begin(),(s).end() #define pb push_back #define enter cout<<'\n' #define lb(i,v) int(lower_bound(all(v),i)-v.begin()) #define ub(i,v) int(upper_bound(all(v),i)-v.begin()) class event{ public: int type; int val; event(int t,int v){ type=t; val=v; } event(){ type=0; val=0; } }; template void initialize(int start, vi& stree, vector& level, int l, int u) { if (sz(stree) - 1 < start)stree.resize(start + 1); if (l == u)stree[start] = l; else { initialize(2 * start, stree, level, l, (u + l) / 2); initialize(2 * start + 1, stree, level, (u + l) / 2 + 1, u); if (level[stree[start * 2]] < level[stree[start * 2 + 1]])stree[start] = stree[start * 2]; else stree[start] = stree[start * 2 + 1]; } return; } template int rmq(int start, vi& stree,vector& level,int i, int j, int l, int u) { if (i > j)swap(i, j); if (ju)return -1; if (l >= i&&u <= j)return stree[start]; int t1 = rmq(2 * start, stree, level, i, j, l, (u + l) / 2); int t2 = rmq(2 * start + 1, stree, level, i, j, (u + l) / 2 + 1, u); if (t1 == -1)return t2; if (t2 == -1)return t1; if (level[t1] < level[t2])return t1; return t2; } int main() { int n,k; cin >> n >> k; vector a(n),preand(n),preor(n),na(n); for(int i = 0; i < n; i++){ cin >> a[i]; na[i]=-a[i]; if(i){ preand[i]=a[i]&preand[i-1]; preor[i]=a[i]|preor[i-1]; } else{ preand[i]=a[i]; preor[i]=a[i]; } } vi stree,nstree; initialize(1,stree,a,0,n-1); initialize(1,nstree,na,0,n-1); vi interval(n,-1); matrix(event) b(n+1); int rightmost=-1; lop(i,0,n-1){ int start=max(i,rightmost+1); if(start>n-1)break; int aand=preand[start],aor=preor[start],mini=a[rmq(1,stree,a,i,start,0,n-1)],maxi=a[rmq(1,nstree,na,i,start,0,n-1)]; if(i){ aand^=(!preand[i-1]); aor^=preor[i-1]; } if(aor-aand-maxi+mini>=k)interval[i]=start; lop(j,start+1,n-1){ mini=min(mini,a[j]); maxi=max(maxi,a[j]); aand&=a[j]; aor|=a[j]; if(aor-aand-maxi+mini>=k)interval[i]=j; } rightmost=max(rightmost,interval[i]); if(interval[i]!=-1){ int length=interval[i]-i+1; b[i].pb(event(1,length)); b[interval[i]+1].pb(event(2,length)); } } multiset ms; ms.insert(-1); lop(i,0,n-1){ lop(j,0,sz(b[i])-1){ if(b[i][j].type==1)ms.insert(b[i][j].val); else{ multiset::iterator it=ms.find(b[i][j].val); ms.erase(it); } } cout<<*(--ms.end())<<'\n'; } return 0; }