Problem:
Score : 100 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns.
Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.

In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the others are all empty squares.
It is guaranteed that Squares (1, 1) and (H, W) are empty squares.

Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.

Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Constraints

All values in input are integers.

2 \leq H, W \leq 10^5

1 \leq N \leq 3000

1 \leq r_i \leq H

1 \leq c_i \leq W

Squares (r_i, c_i) are all distinct.

Squares (1, 1) and (H, W) are empty squares.

Input

Input is given from Standard Input in the following format:

H W N
r_1 c_1
r_2 c_2
:
r_N c_N

Output

Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Sample Input 1

3 4 2
2 2
1 4

Sample Output 1

3

There are three paths as follows:

Sample Input 2

5 2 2
2 1
4 2

Sample Output 2

0

There may be no paths.

Sample Input 3

5 5 4
3 1
3 5
1 3
5 3

Sample Output 3

24

Sample Input 4

100000 100000 1
50000 50000

Sample Output 4

123445622

Be sure to print the count modulo 10^9 + 7.

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#define mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
ll fac[2*N];

ll sub(ll a,ll b){
	return (a-b+mod)%mod;
}

ll mul(ll a,ll b){
	return (a*b)%mod;
}

ll binomial(ll a,ll b){
	if(a<0||b<0||b>a)
		return 0;
	
	ll temp = (fac[a]*inv(fac[b]))%mod;
	temp = (temp*inv(fac[a - b]))%mod;
	return temp;
}

ll f(ll a,ll b){
	return binomial(a+b,b);
}

int main(){
	boost;
	fac[0] = 1;
	for(int i = 1;i<2*N;i++){
		fac[i] = (fac[i-1]*i)%mod;
	}
	
	ll h,w,n;
	cin>>h>>w>>n;
	vector<pair<int,int>> v(n);
	
	for(int i = 0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		v[i] = make_pair(a,b);
	}
	
	v.push_back(make_pair(h,w));
	sort(v.begin(),v.end(),[&](pair<int,int> a,pair<int,int> b){
		return a.first + a.second < b.first + b.second;
	});
	
	//debug() << imie(v);
	vector<int> dp(n+1);
	
	for(int i = 0;i<n+1;i++){
		ll ans = binomial(v[i].first + v[i].second - 2, v[i].first - 1);
		//debug()<< imie(ans);
		for(int j = i-1;j>=0;j--){
			if(v[j].first<=v[i].first&&v[j].second<=v[i].second)
				ans = sub(ans,mul(dp[j],f(v[i].first - v[j].first, v[i].second - v[j].second)));
		}
		dp[i] = ans;
	}
	//debug() << imie(dp);
	cout<<dp[n]<<endl;
	return 0;
}