#P6744. Independent Trapezoids

    ID: 19952 Type: Default 1000ms 256MiB

Independent Trapezoids

Independent Trapezoids

Given two horizontal lines and N trapezoids between them, each trapezoid is defined by four integers a, b, c, and d (with a < b and c < d). The top side of a trapezoid lies between (a, U) and (b, U), and the bottom side lies between (c, L) and (d, L). Two trapezoids are said to be non intersecting (or independent) if one lies completely to the left of the other; that is, for trapezoids i and j, they do not intersect if either

[ \begin{cases} b_i < a_j \ d_i < c_j \end{cases} \quad\text{or}\quad \begin{cases} b_j < a_i \ d_j < c_i \end{cases} ]

Your task is to determine the size k of the maximum set of pairwise non intersecting trapezoids (also known as the maximum independent set) and count the number of such maximum independent sets modulo \(30013\).

inputFormat

The input begins with a line containing an integer \(N\) (\(1 \le N\)). Each of the next \(N\) lines contains four space-separated integers \(a\), \(b\), \(c\), and \(d\) satisfying \(0 \le a < b \le 10^9\) and \(0 \le c < d \le 10^9\), representing a trapezoid between the two horizontal lines.

outputFormat

Output two integers separated by a space: the size of the maximum independent set of trapezoids and the number of such maximum independent sets modulo \(30013\).

sample

3
1 3 2 4
4 6 5 7
2 5 3 6
2 1

</p>