import qualified Control.Arrow as Arrow import Control.Monad (replicateM) import qualified Data.List as L import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Maybe as Maybe import qualified Data.Vector.Unboxed as VU getInt :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString) getInt = fmap (Arrow.second BSC8.tail) . BSC8.readInt getAB :: IO (Int, Int) getAB = (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 getInt <$> BSC8.getLine main :: IO () main = do (n, d) <- getAB xs <- map (fst. Maybe.fromJust . BSC8.readInt) <$> replicateM n BSC8.getLine if n == 1 then print 0 else putStr $ unlines $ map show $ solve n d xs solve :: Int -> Int -> [Int] -> [Int] solve n d xs = map f ys where -- ys :: [(Int, [Int])] ys = part xs -- f :: (Int, [Int]) -> Int f (a, zs) = length $ filter (\x -> a - x >= d) zs part :: [Int] -> [(Int, [Int])] part [x] = [(x, [])] part (x:xs) = (x, xs) : map (\(y, ys) -> (y, x:ys)) (part xs)