Suki and Biscuit Share the Garden
Suki, the curly black dog with the grey beard, shares a garden with Biscuit, the terrier from next door. Each dog's family lets their dog out several times a day, and the family diary lists these garden windows in no particular order. The two families wrote their windows down carelessly, so one dog's windows may overlap, touch, or even repeat. Suki wants to know when she can play with Biscuit.
Time is measured in minutes from the start of the day and flows continuously. A window [l, r] means the dog is in the garden at every moment t with l ≤ t ≤ r (when l = r the dog only pops out for a single moment). A dog is in the garden at moment t if t lies in at least one of its windows.
A shared stretch is a maximal closed interval [a, b] of moments at which both dogs are in the garden: both are outside at every moment from a to b, and the interval cannot be extended in either direction. A shared stretch may be a single moment (a = b), and its length is b − a minutes.
Find all shared stretches, their total length, and the length of the longest one.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 2·10^5): the number of Suki's windows and of Biscuit's windows.
Each of the next n lines contains two integers l and r (0 ≤ l ≤ r ≤ 10^9): one of Suki's windows.
Each of the next m lines contains two integers l and r (0 ≤ l ≤ r ≤ 10^9): one of Biscuit's windows.
Output
On the first line print three integers: the number k of shared stretches, their total length, and the length of the longest one. If there are no shared stretches, print 0 0 0.
Then print k lines, each with two integers a b: the shared stretches in increasing order of a.
Notes
In the first example Suki's windows [1, 4] and [3, 7] overlap, so she is outside from minute 1 to minute 7, and her windows [10, 12] and [12, 15] touch, so she is also outside from 10 to 15. Biscuit is outside during [5, 11] and [15, 20]. Both dogs are outside during [5, 7], during [10, 11], and at the single moment 15, which gives three stretches of total length 2 + 1 + 0 = 3; the longest has length 2.
In the second example the dogs are never in the garden at the same moment: Biscuit goes out at minute 5 only after Suki came in at minute 4, and goes back in before Suki's next window starts.