Intersection of intervals in vectors

Rust Medium vectors

Task «Intersection of intervals in vectors»

Given two vectors containing non-overlapping and ascending sorted intervals. Each interval is represented by a pair of integers [start, end] (inclusive). It is necessary to find the intersection of these two sets of intervals. The result should be represented as a vector of intervals sorted in ascending order. If there are no intersections, output an empty vector. It is guaranteed that the input intervals do not overlap within each vector.

Input Format

In the first line, an integer n — the number of intervals in the first vector. Then n lines, each containing two integers start and end separated by a space. Next, an integer m — the number of intervals in the second vector. Then m lines with intervals.

Output Format

In the first line, an integer k — the number of intervals in the intersection. Then k lines, each with two numbers — start and end separated by a space.

Examples

Example 1

INPUT
1 4 7 1 8 10
OUTPUT
0

Example 2

INPUT
bbbbb
OUTPUT
1

Example 3

INPUT
3 1 2 3
OUTPUT
0
main.rs