fun water_vol (wh: int list) = let fun count_vol max hs acc = case hs of [] => acc | h2::hs' => if (max - h2) > 0 andalso (List.exists (fn x => x>max) hs') then count_vol max hs' (acc+max-h2) else count_vol h2 hs' acc in count_vol (hd wh) (tl wh) 0 end