import Control.Applicative ((<$>)) import Data.Char (isSpace) import Data.List (unfoldr) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B getL :: (ByteString -> [Int]) -> IO [Int] getL f = f <$> B.getContents readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int]) readIL f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') main :: IO () main = print =<< solve <$> getL (readIL B.readInt) solve :: [Int] -> Int solve [aw, ab, bw, bb, c, d] | c <= ab && d >= bw = aw + bw | c <= ab && d < bw = aw + d | c > ab && d >= (bw + c - ab) = aw + bw | c > ab && d < (bw + c - ab) = (aw - (c - ab)) + d | otherwise = 0