Language: C++

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

template<typename T>
struct combinatorics {
    vector<T> fac_, ifac_;

    combinatorics(i64 n): fac(n + 1), ifac(n + 1) {
        fac[0] = ifac[n] = 1;
        for (i64 i = 0; i < n; i++) fac[i + 1] = fac[i] * (i + 1);
        ifac[n] /= fac[n];
        for (i64 i = n; i > 0; i--) ifac[i - 1] = ifac[i] * i;
    }

    T p(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] * ifac[n - k];
    }

    T c(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return p(n, k) * ifac[k];
    }

    T h(i64 n, i64 k) const {
        return c(n + k - 1, k);
    }
};

void solve() {
    i64 h, w, n;
    cin >> h >> w >> n;

    vector<p64> b(n);
    for (auto& [ r, c ] : b) cin >> r >> c;
    b.emplace_back(1, 1);
    b.emplace_back(h, w);
    sort(all(b));

    vector<m64> dp(n + 2);
    dp[0] = 1;
    combinatorics<m64> c(h + w);
    for (i64 i = 0; i < n + 2; i++) {
        for (i64 j = i + 1; j < n + 2; j++) {
            auto& [ xb, yb ] = b[i];
            auto& [ xe, ye ] = b[j];
            if (yb > ye) continue;
            dp[j] -= dp[i] * c.c(xe - xb + ye - yb, xe - xb);
        }
    }
    cout << -dp[n + 1] << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Compiler output:
a.cc: In constructor 'combinatorics<T>::combinatorics(i64)':
a.cc:73:27: error: class 'combinatorics<T>' does not have any field named 'fac'
   73 |     combinatorics(i64 n): fac(n + 1), ifac(n + 1) {
      |                           ^~~
a.cc:73:39: error: class 'combinatorics<T>' does not have any field named 'ifac'
   73 |     combinatorics(i64 n): fac(n + 1), ifac(n + 1) {
      |                                       ^~~~
a.cc:74:9: error: 'fac' was not declared in this scope; did you mean 'fac_'?
   74 |         fac[0] = ifac[n] = 1;
      |         ^~~
      |         fac_
a.cc:74:18: error: 'ifac' was not declared in this scope; did you mean 'ifac_'?
   74 |         fac[0] = ifac[n] = 1;
      |                  ^~~~
      |                  ifac_
a.cc: In member function 'T combinatorics<T>::p(i64, i64) const':
a.cc:82:16: error: 'fac' was not declared in this scope; did you mean 'fac_'?
   82 |         return fac[n] * ifac[n - k];
      |                ^~~
      |                fac_
a.cc:82:25: error: 'ifac' was not declared in this scope; did you mean 'ifac_'?
   82 |         return fac[n] * ifac[n - k];
      |                         ^~~~
      |                         ifac_
a.cc: In member function 'T combinatorics<T>::c(i64, i64) const':
a.cc:87:26: error: 'ifac' was not declared in this scope; did you mean 'ifac_'?
   87 |         return p(n, k) * ifac[k];
      |                          ^~~~
      |                          ifac_