#include using namespace std; typedef long long ll; ll cost[5001][5001]; ll result[5001]; ll re[5001][5001]; void costlyIntervals(int n, int k, vector A) { // Return a list of length n consisting of the answers for(int i = 0;i < n;i++){ ll r,an,mx,mn; result[i] = -1; for(int j = i;j < n;j++){ if(i == j){ cost[i][j] = 0; r = an = mx = mn = A[j]; }else{ an &= A[j]; r |= A[j]; mx = max(mx,A[j]); mn = min(mn,A[j]); cost[i][j] = r - mx +mn -an; } } } memset(re,-1,sizeof re); for(ll i = 0;i < n;i++){ for(ll j = i;j < n;j++){ if(cost[i][j] >= k){ re[i][j] = j - i + 1; } } for(int j = n - 2;j >= i;j--){ re[i][j] = max(re[i][j+1],re[i][j]); } } for(int i = 0;i < n;i++){ for(int j = 0;j < n;j++){ result[i] = max(max(re[j][i],re[i][j]),result[i]); } } for(int i = 0;i < n;i++){ printf("%d\n",result[i]); } } int main() { int n; int k; scanf("%d %d",&n,&k); vector A(n); for(int A_i = 0; A_i < n; A_i++){ scanf("%d",&A[A_i]); } costlyIntervals(n, k, A); return 0; }