겹치지 않는 직사각형 장애물이 놓인 n×m 격자에서 (1,1)에서 (n,m)까지 오른쪽이나 위로 이동하는 경로 중, 어떤 장애물이 경로의 왼쪽에 있느냐 오른쪽에 있느냐가 다른 경우를 세어 10^9+7로 나눈 나머지를 구한다.
어려움8동적 계획법정렬조합론구현아직 제출이 없습니다시간 제한2초메모리 제한512 MBLittle girl Masha likes winter sports, today she's planning to take part in slalom skiing.
The track is represented as a grid composed of n × m squares. There are rectangular obstacles at the track, composed of grid squares. Masha must get from the square (1, 1) to the square (n, m). She can move from a square to adjacent square: either to the right, or upwards. If the square is occupied by an obstacle, it is not allowed to move to that square.
One can see that each obstacle can actually be passed in two ways: either it is to the right of Masha's path, or to the left. Masha likes to try all ways to do things, so she would like to know how many ways are there to pass the track. Two ways are considered different if there is an obstacle such that it is to the right of the path in one way, and to the left of the path in the other way.
Help Masha to find the number of ways to pass the track. The number of ways can be quite big, so Masha would like to know it modulo 109 + 7.
The pictures below show different ways to pass the track in sample tests.



The first line of input data contains three positive integers: n, m and k (3 ≤ n, m ≤ 106, 0 ≤ k ≤ 105) — the size of the track and the number of obstacles.
The following k lines contain four positive integers each: x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m) — coordinates of bottom left, and top right squares of the obstacle.
It is guaranteed that there are no obstacles at squares (1, 1) and (n, m), and no obstacles overlap (but some of them may touch).
Output one integer — the number of ways to pass the track modulo 109 + 7.