Scanf.scanf "%d %d %d %d %d %d" (fun aw ab bw bb c d -> let mw = max 0 (c - ab) in Printf.printf "%d\n" (aw - mw + min (bw + mw) d) )