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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

/*

  This is an optimization for based question where the complexity is n*n but here 
  it will be o(obstacles * obstacles) where obstacles are less than grid dimension n.

  User:- sanyam
*/

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)
#define init_arr(i,val) memset(i, val, sizeof(val))
#define sort_cut(x) (x).begin(), (x).end()

const ll inf = 1e18;

void take_fileIO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  return;
}


/* ---------------------Code--------------------  */
ll dp[3001];
ll fact[200001];
ll invofFact[200001];

ll power(ll x, ll exp){
  if(exp==0)
    return 1;
  if(exp==1)
    return x%mod;
  ll res = power(x, exp/2)%mod;
  if(exp & 1){
    return (res%mod * res%mod * x%mod)%mod;
  }
  return (res%mod * res%mod)%mod;
}

ll inverse(ll num){
  return power(num , mod-2)%mod;
}

ll NCR(ll n, ll r){
  return (fact[n]%mod * invofFact[r]%mod * invofFact[n-r]%mod)%mod;
}

ll calc_ways(ll i, ll j, ll ei, ll ej){
  ll down = ei-i;
  ll right = ej-j;
  if(down<0 || right<0) return 0;
  
  else return NCR(down+right, right)%mod;
}

bool comp(pi &a, pi &b){
  ll dist1 = (a.first-1)*(a.first-1) + (a.second-1)*(a.second-1);
  ll dist2 = (b.first-1)*(b.first-1) + (b.second-1)*(b.second-1);
  return dist1 <= dist2;
}

void solve_dp_for_obstacles(vector<pi> &obstacles, ll n, ll h, ll w) {
  dp[0] = calc_ways(1, 1, obstacles[0].first, obstacles[0].second)%mod;
  for(int i=1; i<n; i++){
    dp[i] = calc_ways(1, 1, obstacles[i].first, obstacles[i].second)%mod;
    
    for(int j=0; j<i; j++){
      // ll distj = dist(obst
      dp[i] = (mod + dp[i]%mod - calc_ways(obstacles[j].first, obstacles[j].second, 
                          obstacles[i].first, obstacles[i].second)%mod)%mod;

    }
  }
  return;
}

void preprocess(){
  fact[0]=1;
  invofFact[0]=1;
  for(ll i=1; i<=200000; i++){
    fact[i] = (fact[i-1]%mod * i%mod)%mod;
    invofFact[i] = inverse(fact[i])%mod;  
  }
  return;
}

void solve(){
  ll h,w,n;
  cin>>h>>w>>n;
  
  vector<pair<int,int>>obstacles;
  loop(i, 0, n){
    ll x, y;  cin>>x>>y;
    obstacles.push_back(mp(x, y));
  }
  
  init_arr(dp, 0);
  init_arr(invofFact, -1);

  sort(obstacles.begin(), obstacles.end(), comp);
  preprocess();

  solve_dp_for_obstacles(obstacles, n, h, w);

  ll ans = calc_ways(1, 1, h, w)%mod;
  // cout<<ans<<endl;

  for(int i=0; i<n; i++) {
    ans = (mod + ans%mod - (dp[i]%mod*calc_ways(obstacles[i].first, obstacles[i].second, h, w)%mod)%mod )%mod;
  }
  // if(ans<0) ans=0;
  cout<<ans<<endl;
  return; 
}

int main(){

  fastIO;
 // take_fileIO();
  solve();
  return 0;
}