import Control.Monad import Data.List main = do [vl,vr,d,w] <- map read . words <$> getContents print (shuttle vl vr d w) shuttle vl vr d w = sum $ take 100 $ unfoldr tofrom d where tofrom d' = let db = d'*(w/(w+vr)) + (d'-d'*(w/(w+vr)))*(w/(w+vl)) in Just (db,d'-db*((vl+vr)/w))