using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static int[] costlyIntervals(int n, int k, int[] A) { var temps = new List(); var list = new List(); for (var i = 0; i < n; i++) { for (var j = i; j < n; j++) { list.Add(j); var or = A[list[0]]; var and = A[list[0]]; var max = A[list[0]]; var min = A[list[0]]; foreach (var x in list) { or |= A[x]; and &= A[x]; max = Math.Max(max, A[x]); min = Math.Min(min, A[x]); } var cost = (or - and) - (max - min); temps.Add(new Temp {List = new List(list.ToArray()), Cost = cost}); } list.Clear(); } var vals = temps.Where(t => t.Cost >= k).ToList(); var res = new List(); for (var i = 0; i < n; i++) { var ex = vals.Where(t => t.List.Contains(i)).ToList(); if (ex.Any()) { res.Add(ex.OrderByDescending(t => t.Cost).First().List.Count); } else { res.Add(-1); } } return res.ToArray(); } class Temp { public List List { get; set; } public int Cost { get; set; } } 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(' '); int[] A = Array.ConvertAll(A_temp,Int32.Parse); int[] result = costlyIntervals(n, k, A); Console.WriteLine(String.Join("\n", result)); } }