Slalom
Time limit2sMemory limit512 MB
Count the right-or-up paths from (1, 1) to (n, m) that avoid rectangular obstacles, where each obstacle is passed on either side, modulo 10^9 + 7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Little girl Masha likes winter sports, and today she plans to take part in slalom skiing.
The track is a grid of squares. Rectangular obstacles on the track are made of grid squares. Masha must get from square to square . She can move from a square to an adjacent square, either to the right or upward. She cannot enter a square that is occupied by an obstacle.
Each obstacle can be passed in two ways: either it is to the right of Masha's path, or it is to the left. Masha wants to try every way to do this, so she wants to know how many ways there are to pass the track. Two ways are different if some obstacle is to the right of the path in one way and to the left of the path in the other.
Help Masha count the ways to pass the track. The count can be large, so print it modulo .
The pictures below show the different ways to pass the track in the sample tests.



Input
The first line contains three positive integers , , and (, ), the size of the track and the number of obstacles.
Each of the next lines contains four positive integers , , , (, ), the coordinates of the bottom left and top right squares of an obstacle.
Squares and have no obstacles. No two obstacles overlap, but they may touch.
Output
Print one integer, the number of ways to pass the track modulo .