Scanf.scanf "%d %d %d %d %d" (fun a b c d m -> let rec loop x y mx = if y > d then mx else if x > b then loop a (y + 1) mx else loop (x + 1) y (max mx ((x + y) mod m)) in loop a b 0 |> Printf.printf "%d\n" )