## The Contest Contest 1 P5 - A Typical CCO Problem

View as PDF

Points: 20 (partial)
Time limit: 3.0s
Memory limit: 512M

Author:
Problem types

After experimenting with the Loop and Line models, you, the mayor of Grid Town, have come up with a more compact way to organize the town. Grid Town can be represented by a grid with rows and columns, labelled from to and to respectively. The square at row and column is denoted .

For simplicity, Grid Town only has houses of two sizes, and . You wish to cover the town with houses such that every square is occupied by a house. However, to achieve maximum strategic savings, you also require that the town is covered using the least number of houses possible.

To possibly reduce the number of houses needed, there are squares in the town where different houses may overlap (but are not required to). In other words, that square can be considered a part of multiple houses. No overlaps are allowed on the remainder of squares since residences of Grid Town dislike sharing.

As the mayor, you need to determine the minimum number of houses required to fill the town, and how many ways the town can be filled using this minimum number of houses.

Two arrangements of houses are considered different if there exists a square such that one of the following holds:

• One arrangement contains a house with its top left square at while the other arrangement does not.
• Both arrangements contain a house with its top left square at but the house dimensions are different.

#### Constraints

are pairwise-distinct.

#### Input Specification

The first line contains two integers and .

The next lines each contain two integers and , indicating that the square allows overlaps.

#### Output Specification

On the first line, output the minimum number of houses required to fill the town.

On the second line, output the number of ways of filling the town using the minimum number of houses. Since this number may be very large, please output it modulo .

#### Sample Input 1

4 3
1 3
2 2
2 3

#### Sample Output 1

5
2

#### Explanation for Sample 1

The minimum number of houses required is and there are arrangements that use houses, which are shown below:

#### Sample Input 2

9 6
1 3
2 3
3 4
3 5
2 6
3 6

#### Sample Output 2

13
16

#### Sample Input 3

123 1
2 6

#### Sample Output 3

184
72793001