#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; const ll MOD=1e8+7; ll powmod(ll a, ll k){ ll ap=a, ans=1; while(k>0){ if(k%2==1){ ans*=ap; ans%=MOD; } ap=ap*ap; ap%=MOD; k/=2; } return ans; } ll inv(ll a){ return powmod(a, MOD-2); } int main() { ll f[200001]; f[0]=1; for(ll i=1; i<=200000; i++) f[i]=f[i-1]*i%MOD; ll invf[200001]; invf[200000]=inv(f[200000]); for(ll i=200000-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD; int h, w, k; cin>>h>>w>>k; int a[20], b[20]; P q[20]; int ind[20]; for(int i=0; i>a[i]>>b[i], q[i]=P(a[i], b[i]), ind[i]=i; sort(ind, ind+k, [&](int i, int j){ return q[i]=pr.first && p.second>=pr.second){ c0*=(f[p.first-pr.first+p.second-pr.second]*invf[p.first-pr.first]%MOD*invf[p.second-pr.second]%MOD); c0%=MOD; pr=p; }else{ c0=0; } } if(c0!=0){ c0=(c0*f[h-pr.first+w-pr.second]%MOD*invf[h-pr.first]%MOD*invf[w-pr.second]%MOD); } c[i0]=c0; } for(int i=0; i