local mfl = math.floor local function comp(a, b) return a < b end local function lower_bound(ary, x) local num = #ary if num == 0 then return 1 end if not comp(ary[1], x) then return 1 end if comp(ary[num], x) then return num + 1 end local min, max = 1, num while 1 < max - min do local mid = mfl((min + max) / 2) if comp(ary[mid], x) then min = mid else max = mid end end return max end local n, d = io.read("*n", "*n") local t = {} local a = {} for i = 1, n do t[i] = io.read("*n") a[i] = t[i] end table.sort(t) for i = 1, n do local lb = lower_bound(t, a[i] - d + 1) print(lb - 1) end