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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;


const int N=2e5+5;
ll f[N],invf[N];

int mul(int a, int b) {
    return (ll) a * b % mod;
}
int my_pow(int a, int b) {
    int r = 1;
    while(b) {
        if(b % 2) {
            r = mul(r, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return r;
}
int inv_fac(int a) {
    return my_pow(a, mod - 2);
}
 
int binomial(int a, int b) {
    if(a < 0 || b < 0 || b > a) {
        return 0;
    }
    return mul(f[a], mul(invf[b], invf[a-b]));
}
 
int fa(int a, int b) {
    int tmp = binomial(a + b, b);
    //~ debug() << imie(a) imie(b) imie(tmp);
    return tmp;
}

ll mpow(ll x, ll y){ 
    ll res = 1;
    x = x % mod;
    while (y > 0) { 
        if (y & 1) res = (res * x) % mod; 
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
  
ll modInv(ll n){ 
    return mpow(n,mod-2); 
} 

void fact(){
    f[0]=1;
    invf[0]=1;
    for(ll i=1;i<N;i++){
        f[i]=(f[i-1]*i)%mod; 
        invf[i]=inv_fac(f[i]);
    }
}

ll paths(pair<ll,ll> p1, pair<ll,ll> p2){
    ll a=p1.first, b=p1.second, x=p2.first, y=p2.second;
    return ((f[x-a+y-b]*modInv(f[x-a]))%mod*modInv(f[y-b]))%mod;
}

ll paths1(pair<ll,ll> p1, pair<ll,ll> p2){
    ll a=p2.first - p1.first, b=p2.second - p1.second;
    return (f[a+b]*(modInv(f[a])*modInv(f[b]))%mod)%mod;
}

const int M=1e3+5;
//ll dp[M];
vector<ll> dp(M);
ll n,m,k;

bool comp(pair<ll,ll> a, pair<ll,ll> b){
    return a.first+a.second<b.first+b.second;
}


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    fact();
    cin>>n>>m>>k;
    ll x,y;
    vector<pair<ll,ll>> a(k);
    for(ll i=0;i<k;i++){
        cin>>a[i].first>>a[i].second; 
    }
    sort(a.begin(),a.end(),comp);
    a.pb({n,m});
    k=a.size();
    //vector<ll> dp(k);
    //memset(dp,-1,sizeof(dp));
    for(ll i=0;i<k;i++){
        ll p=fa(a[i].first-1, a[i].second-1), sub=0;
        for(ll j=0;j<i;j++){
            if(a[j].first<=a[i].first && a[j].second<=a[i].second)
                p=(p-mul(dp[j],fa(a[i].first - a[j].first, a[i].second-a[j].second))+mod)%mod;
        }
        dp[i]=p;
    }
    cout<<dp[k-1];


    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}