#K48107. Check for Overlapping Intervals

    ID: 28347 Type: Default 1000ms 256MiB

Check for Overlapping Intervals

Check for Overlapping Intervals

You are given the working intervals of two employees. Your task is to determine if there is any overlapping period between the intervals of the two employees. Two intervals \([a, b)\) and \([c, d)\) overlap if and only if the following condition holds:

$$a < d \quad \text{and} \quad c < b$$

Note that if the end of one interval equals the start of another (i.e. they only touch), they are not considered to overlap.

For example, given the intervals for the first employee as \([1, 5)\), \([10, 15)\), and \([20, 25)\) and for the second employee as \([5, 10)\) and \([15, 20)\), the answer is NO because none of the intervals actually overlap.

inputFormat

The first line contains a single integer \(n\) representing the number of intervals for the first employee.

The next \(n\) lines each contain two integers \(a\) and \(b\) representing an interval \([a, b)\) for the first employee.

The following line contains a single integer \(m\) representing the number of intervals for the second employee.

The next \(m\) lines each contain two integers \(c\) and \(d\) representing an interval \([c, d)\) for the second employee.

outputFormat

Output a single line containing YES if there exists an overlapping interval between the two sets of intervals, or NO otherwise.

## sample
3
1 5
10 15
20 25
2
5 10
15 20
NO