import Control.Applicative import Data.List main :: IO () main = inputOutput inputOutput :: IO () inputOutput = do [n, d] <- map read <$> words <$> getLine ls <- lines <$> getContents let (ps0, ms0) = splitAt n ls ms = map read $ take d ms0 ps = map read ps0 putStrLn $ unlines $ map show $ map (maxPair ps) ms maxPair :: [Int] -> Int -> Int maxPair xxs p = f 0 =<< reverse $ sort xxs where f r (x:xs) (y:ys) | x == y = r | l > p = f r xs (y:ys) | otherwise = f (max l r) (x:xs) ys where l = x + y f r _ _ = r