Painting Bob's Fence
Alice is bored, and the fence running along her and Bob's shared yard is endless in both
directions. Over the course of the day she picks up her paint roller n times and, each time,
paints the stretch of fence from meter l up to (but not including) meter r. She doesn't plan
ahead, so her stretches can overlap, land exactly inside one another, or sit right end-to-end
with a previous stretch.
That evening Bob walks the fence and wants two numbers: how many meters of fence now have paint on them (a meter that got painted twice still counts once), and into how many separate painted pieces the paint has split up. Two stretches that merely touch — one ending exactly where the next begins — count as one continuous piece, since there's no bare wood between them.
Input
The first line contains an integer n (1 ≤ n ≤ 2·10^5), the number of stretches Alice paints.
Each of the next n lines contains two integers l and r (-10^18 ≤ l < r ≤ 10^18)
describing one stretch: every point x with l ≤ x < r gets painted.
Output
Print two integers separated by a space: the total painted length, and the number of maximal painted pieces. Both fit in a 64-bit signed integer.
Notes
In the first example, the stretches [1, 5) and [3, 7) overlap and merge into one painted
piece [1, 7) of length 6, while [10, 12) stays separate, for a total length of 8 across 2
pieces.
In the second example, [1, 3) and [3, 5) only touch at the point 3, but that's still enough
to join them into a single piece [1, 5) of length 4.