#!/bin/ruby def my_or(i, j, a) return a[i..j].inject(:|) end def my_and(i, j, a) return a[i..j].inject(:&) end def my_max(i, j, a) return a[i..j].max end def my_min(i, j, a) return a[i..j].min end def costlyIntervals(n, k, a, x) best = -1 for i in (0..n - 1) for j in (i..n - 1) cost = (my_or(i, j, a) - my_and(i, j, a)) - (my_max(i, j, a) - my_min(i, j, a)) if cost >= k && i <= x && x <= j best = j - i + 1 if !best best = j - i + 1 if j - i + 1 > best end end end return best end n, k = gets.strip.split(' ') n = n.to_i k = k.to_i a = gets.strip a = a.split(' ').map(&:to_i) result = (0..n - 1).map{|x| costlyIntervals(n, k, a, x)} #puts result print result.join("\n")