using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static int[] costlyIntervals(int n, int k, long[] A) { checked { var x = new int[n]; //var cache = new Dictionary(); for (long I = 0; I < n; ++I) { x[I] = -1; for (long L = 0; L <= I; ++L) { var OR = 0L; var AND = A[L]; var MIN = long.MaxValue; var MAX = 0L; for (long t = L; t <= I - 1; ++t) { Calculate(A[t], ref OR, ref AND, ref MIN, ref MAX); } for (long R = I; R <= n - 1; ++R) { Calculate(A[R], ref OR, ref AND, ref MIN, ref MAX); var cost = OR - AND - MAX + MIN; if (cost >= k && x[I] < R - L + 1) x[I] = (int)(R - L + 1); } //var q = L * 1000000L + R; //if (cache.ContainsKey(q)) // cost = cache[q]; //cache[q] = cost; } } return x; } } private static void Calculate(long a, ref long OR, ref long AND, ref long MIN, ref long MAX) { checked { OR |= a; AND &= a; MIN = Math.Min(MIN, a); MAX = Math.Max(MAX, a); } } static void Main(String[] args) { string[] tokens_n = Console.ReadLine().Split(' '); int n = Convert.ToInt32(tokens_n[0]); int k = Convert.ToInt32(tokens_n[1]); string[] A_temp = Console.ReadLine().Split(' '); long[] A = Array.ConvertAll(A_temp, long.Parse); int[] result = costlyIntervals(n, k, A); Console.WriteLine(String.Join("\n", result)); } /* 5 6 2 4 3 1 7 */ }