Scanf.scanf "%d" (fun n ->
    let rec loop i acc =
        if i = n then acc else
            let acc = Scanf.scanf " %d %d" (fun l r -> acc + r - l + 1) in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)
