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
For simplicity, Grid Town only has houses of two sizes,
To possibly reduce the number of houses needed, there are
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
- 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
Subtask 1 [5%]
Subtask 2 [10%]
Subtask 3 [20%]
Subtask 4 [30%]
Subtask 5 [35%]
No additional constraints.
Input Specification
The first line contains two integers
The next
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
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
Comments