Gats and the Rising Rooftops
Gats is exploring a rectangular grid of rooftops with rows and columns. Rooftop has height . He starts at rooftop and wants to reach rooftop .
From rooftop , Gats may jump either rightward or downward. He always lands on the first rooftop in the chosen direction that is strictly higher than his current rooftop:
- For a rightward jump, if there is at least one column satisfying and , he lands at for the smallest such .
If no strictly higher rooftop exists in the chosen direction, that jump is unavailable. Gats cannot jump leftward or upward.
A route is the sequence of rooftops on which Gats lands, including the starting and destination rooftops. Two routes are distinct if their sequences differ.
Determine the minimum number of jumps needed to reach and the number of distinct routes that use exactly that minimum number of jumps. If , the minimum is jumps and there is exactly route.
Input
The first line contains two integers and (, ), the number of rows and columns in the grid.
Output
Print two integers and separated by a space.
If Gats can reach , then is the minimum number of jumps required and is the number of distinct routes using exactly jumps, taken modulo .
Samples
Sample 1
Input
3 3 1 2 3 2 3 4 3 4 5
Output
4 6
Gats needs at least jumps. There are distinct routes that use exactly jumps.
Sample 2
Input
3 4 1 3 2 5 2 1 4 6 3 5 2 7
Output
3 1
The destination can be reached in jumps, and exactly one route uses that many jumps.
Sample 3
Input
2 2 4 3 2 1
Output
-1 0
Every rooftop to the right or below the starting rooftop is lower, so Gats cannot make a first jump.