import Control.Applicative ((<$>), (<*>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr, foldl') import Data.Char (isSpace) import Data.IntMap (IntMap, (!)) import qualified Data.IntMap as IM main :: IO () main = solve <$> f <*> f >>= print where f = readil B.readInt <$> B.getLine solve :: [Int] -> [Int] -> Int solve [n, x] as = IM.foldlWithKey' (\ct k v -> if IM.member (x-k) db then ct + v * db ! (x-k) else ct) 0 db where db = foldl' (\m a -> IM.insertWith (+) a 1 m) IM.empty as readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')