import Control.Monadimport Control.Monad.Instances main = readLn >>= print . sum . (liftM2 (zipWith min) (scanl1 max) (scanr1 max) >>= zipWith (-))
[0, 5, 0, 1, 6000, 0, 2, 1, 0]
11
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!