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)

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           prinf("\n"}
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,n,k,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll dp[200005],inv[200005];

struct D
{
    ll x,y;
}a[100005];

bool cmp(D f,D q)
{
    if(f.x==q.x)return f.y>q.y;
    return f.x>q.x;
}

ll bigmod(ll x,ll y,ll m)
{
    if(y==0)return 1;
    ll n=bigmod(x,y>>1,m);
    n=(n*n)%m;
    if(y&1)n=(n*x)%m;
    return n;
}

int main()
{
    SPEED;
    ll var;
    dp[0]=1;
    for(i=1;i<=200003;i++)
    {
        dp[i]=dp[i-1]*i;dp[i]%=mod;
    }
    inv[200003]=bigmod(dp[200003],mod-2,mod);
    for(i=200002;i>=0;i--)
    {
        inv[i]=(inv[i+1]*(i+1))%mod;
    }
    sfl(x);sfl(y);sfl(n);
    z=(inv[y-1]*dp[y+x-2])%mod;
    z=(z*inv[x-1])%mod;

    for(i=0;i<n;i++)
    {
        sfl(a[i].x);sfl(a[i].y);
    }
    //cout<<z<<endl;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            // sob valid path add korte hbe, pore bad dbo
            if(i!=j)
            {
                l=a[i].x,r=a[i].y;
                c=(inv[r-1]*dp[r+l-2])%mod;
                c=(c*inv[l-1])%mod;
                l=a[j].x-l+1;r=a[j].y-r+1;
                if(l<=0 || r<=0)continue;

                m=(inv[r-1]*dp[r+l-2])%mod;
                m=(m*inv[l-1])%mod;

                c*=m;c%=mod;
                z=(z+c)%mod;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        l=a[i].x,r=a[i].y;
        //cout<<l<<" "<<r<<endl;
        c=(inv[r-1]*dp[r+l-2])%mod; // l,r e koita path ache!!
        c=(c*inv[l-1])%mod;
        l=x-l+1;r=y-r+1;
        //cout<<l<<" "<<r<<endl;
        m=(inv[r-1]*dp[r+l-2])%mod; // l,r theke x,y er path remove!!
        m=(m*inv[l-1])%mod;

        c*=m;c%=mod;
        z=(z-c+mod)%mod;
    }

    cout<<z<<endl;
}