comb :: (Eq t, Num t) => t -> [a] -> [[a]] comb n xs = go n xs [] [] where go 0 _ ys zs = reverse ys : zs go _ [] _ zs = zs go n (x:xs) ys zs = go (n-1) xs (x:ys) (go n xs ys zs) lcmList :: Integral a => [a] -> a lcmList [x] = x lcmList (x1:x2:xs) = lcmList (lcm x1 x2 : xs) main = do [n,l,h] <- map read . words <$> getLine cs <- map read . words <$> getLine print (onlyOne n l h cs) onlyOne :: Integral t => t -> t -> t -> [t] -> t onlyOne n l h cs = sum $ zipWith (*) as (map (sum . map (divs . lcmList)) ccs) where divs x = div h x - div l x + (if mod l x == 0 then 1 else 0) ccs = map (flip comb cs) [1..n] as = zipWith ($) (cycle [id,negate]) [1..n]