Language: C++

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
vector<pair<int,int>> obstacles;
int n,m,k,fact[200001],dp1[3001],dp2[3001];

int mult(int a , int b){
	long long ret = 1;
	for(int i : a){
		ret *= i;
		ret %= 1000000007;
	}
	return ret;
}

int inv(int a , int b){
	int ret = 1;
	b -= 2;
	while(b){
		while(b % 2 == 0){
			a = mult({a,a});
			b /= 2;
		}
		ret = mult({ret,a});
		b -= 1;
	}
	return ret;
}

int add(int a , int b){
	a += b;
	if(a >= 1000000007){
		a -= 1000000007;
	}
	if(a < 0){
		a += 1000000007;
	}
	return a;
}

int main(){
	cin >> n >> m >> k;
	obstacles.resize(k);
	for(int i = 0 ; i < k ; i += 1){
		cin >> obstacles[i].first >> obstacles[i].second;
	}
	sort(obstacles.begin(),obstacles.end());
	fact[0] = 1;
	for(int i = 1 ; i <= 200000 ; i += 1){
		fact[i] = mult({fact[i-1],i});
	}
	int tot = mult(fact[n+m-2],inv(mult(fact[n-1],fact[m-1]),mod));
	for(int q = 0 ; q < k ; q += 1){
		pair<int,int> i = obstacles[q];
		dp1[q] = mult({fact[i.first+i.second-2],inv(mult({fact[i.first-1],fact[i.second-1]}),mod)});
		dp2[q] = mult({fact[n+m-i.first-i.second],inv(mult({fact[n-i.first],fact[m-i.second]}),mod)});
		tot = add(tot,-mult({dp1[q],dp2[q]}));
		for(int qq = 0 ; qq < q ; qq += 1){
			pair<int,int> j = obstacles[qq];
			if(j.second > i.second){
				continue;
			}
			tot = add(tot,mult(dp1[qq],
			mult(mult(fact[i.first+i.second-j.first-j.second],inv(mult(fact[i.first-j.first],fact[i.second-j.second]),mod)),
			dp2[q])));
		}
	}
	cout << tot << endl;
}

Compiler output:
a.cc: In function 'int mult(int, int)':
a.cc:9:21: error: 'begin' was not declared in this scope
    9 |         for(int i : a){
      |                     ^
a.cc:9:21: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1238:5: note:   'std::begin'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/14/filesystem:53,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200:
/usr/include/c++/14/bits/fs_dir.h:608:3: note:   'std::filesystem::__cxx11::begin'
  608 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
a.cc:9:21: error: 'end' was not declared in this scope
    9 |         for(int i : a){
      |                     ^
a.cc:9:21: note: suggested alternatives:
/usr/include/c++/14/valarray:1265:5: note:   'std::end'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/fs_dir.h:613:3: note:   'std::filesystem::__cxx11::end'
  613 |   end(recursive_directory_iterator) noexcept
      |   ^~~
a.cc: In function 'int inv(int, int)':
a.cc:21:33: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   21 |                         a = mult({a,a});
      |                             ~~~~^~~~~~~
      |                                 |
      |                                 <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:24:27: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   24 |                 ret = mult({ret,a});
      |                       ~~~~^~~~~~~~~
      |                           |
      |                           <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc: In function 'int main()':
a.cc:50:31: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   50 |                 fact[i] = mult({fact[i-1],i});
      |                           ~~~~^~~~~~~~~~~~~~~
      |                               |
      |                               <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:55:65: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   55 |                 dp1[q] = mult({fact[i.first+i.second-2],inv(mult({fact[i.first-1],fact[i.second-1]}),mod)});
      |                                                             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                 |
      |                                                                 <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:55:30: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   55 |                 dp1[q] = mult({fact[i.first+i.second-2],inv(mult({fact[i.first-1],fact[i.second-1]}),mod)});
      |                          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:56:67: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   56 |                 dp2[q] = mult({fact[n+m-i.first-i.second],inv(mult({fact[n-i.first],fact[m-i.second]}),mod)});
      |                                                               ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                   |
      |                                                                   <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:56:30: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   56 |                 dp2[q] = mult({fact[n+m-i.first-i.second],inv(mult({fact[n-i.first],fact[m-i.second]}),mod)});
      |                          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^
a.cc:57:36: error: cannot convert '<brace-enclosed initializer list>' to 'int'
   57 |                 tot = add(tot,-mult({dp1[q],dp2[q]}));
      |                                ~~~~^~~~~~~~~~~~~~~~~
      |                                    |
      |                                    <brace-enclosed initializer list>
a.cc:7:14: note:   initializing argument 1 of 'int mult(int, int)'
    7 | int mult(int a , int b){
      |          ~~~~^