import Data.List

main = do 
  (a:b:c:xs) <- map read . words <$> getLine
  d <- read <$> getLine
  putStrLn . show $ solve a b c d

solve a b c d = 
  let (t:s:f:xs) = sort [a,b,c]
  in t + s + f * d