import Control.Applicative
import Data.List (nub)

countUpGroups gs i = take i gs ++ [(x,f+1)] ++ drop (i+1) gs
  where (x,f) = gs !! i

groupPatterns :: Integer -> Integer -> Integer -> [(Integer,Integer)] -> [[(Integer,Integer)]]
groupPatterns n c d gs
  | count == n = [gs]
  | count > n = []
  | any (\(_,f)->(f<c||d<f)&&f/=0) gs = []
  | otherwise = concatMap (groupPatterns n c d) gss
  where count = sum $ map (uncurry (*)) gs :: Integer
        gss = map (countUpGroups gs) [0..length gs-1]

comb a b = product [a..(a-b')] `div` product [b'..1]
    where b' = min b (a-b)

factorial 0 = 1
factorial n = n*factorial (n-1)

solve :: Integer -> [(Integer,Integer)] -> Integer
solve n gs = ans `div` product (map snd gs)
    where egs = concatMap (\(x,f) -> replicate (fromIntegral f) x) gs
          ans = factorial n `div` product (map factorial egs)

main = do
  [n,a,b,c,d] <- map read.words <$> getLine :: IO [Integer]
  print $ sum $ map (solve n) $ nub $ groupPatterns n c d [(x,0)|x<-[a..b]]
