Language: C++

#include "bits/stdc++.h"

using namespace std;

using ll = long long;

ll h, w, n;
int cs = 1;

template <typename T>
using matrix = std::vector<std::vector<T>>;

constexpr long long mod = 1e9+7;

template <typename T>
matrix<T> modmul(const matrix<T> &l, const matrix<T> &r)
{
    matrix<T> ret(l.size(), std::vector<T>(r[0].size()));
    for (int i = 0; i < (int)l.size(); i++)
    {
        for (int k = 0; k < (int)r.size(); k++)
        {
            for (int j = 0; j < (int)r[0].size(); j++)
            {
                ret[i][j] += l[i][k] * r[k][j] % mod;
                ret[i][j] %= mod;
            }
        }
    }
    return ret;
}

template <typename T>
std::vector<T> modmul(const matrix<T> &a, const std::vector<T> &x)
{
    const int n = a.size();
    const int m = x.size();
    std::vector<T> ret(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            ret[i] += a[i][j] * x[j] % mod;
            ret[i] %= mod;
        }
    }
    return ret;
}

template <typename T>
matrix<T> eye(const int n)
{
    matrix<T> ret(n, std::vector<T>(n));
    for (int i = 0; i < n; i++)
        ret[i][i] = 1;
    return ret;
}

template <typename T>
matrix<T> modpow(matrix<T> x, long long n)
{
    auto ret = eye<T>(x.size());
    while (n)
    {
        if (n & 1)
            ret = modmul(ret, x, mod);
        x = modmul(x, x, mod);
        n /= 2;
    }
    return ret;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (cin >> w >> h >> n, h || w || n)
    {
        cout << "Case " << cs << ": ";
        cs++;
        bool f = false;
        set<ll> st = {h};
        map<ll, vector<ll>> mp;
        for (int i = 0; i < n; i++)
        {
            ll x, y;
            cin >> y >> x;
            if (x == 1)
                continue;
            st.insert(x);
            y--;
            mp[x].push_back(y);
            if (x == h && y == w)
            {
                f = true;
            }
        }
        if (f)
        {
            cout << 0 << endl;
            continue;
        }
        vector<vector<ll>> id(w, vector<ll>(w, 0));
        for (int i = 0; i < w; i++)
        {
            id[i][i] = 1;
            if (i)
                id[i][i - 1] = 1;
            if (i + 1 < w)
                id[i][i + 1] = 1;
        }
        vector<ll> x(w, 0);
        x[0] = 1;
        ll pre = 1;
        for (auto v : st)
        {
            x = modmul(modpow(id, v - pre), x);
            for (auto y : mp[v])
                x[y] = 0;
            pre = v;
        }
        cout << x[w - 1] << endl;
    }
}



Compiler output:
a.cc: In instantiation of 'matrix<T> modpow(matrix<T>, long long int) [with T = long long int; matrix<T> = std::vector<std::vector<long long int> >]':
a.cc:119:30:   required from here
  119 |             x = modmul(modpow(id, v - pre), x);
      |                        ~~~~~~^~~~~~~~~~~~~
a.cc:66:25: error: no matching function for call to 'modmul(std::vector<std::vector<long long int> >&, matrix<long long int>&, const long long int&)'
   66 |             ret = modmul(ret, x, mod);
      |                   ~~~~~~^~~~~~~~~~~~~
a.cc:16:11: note: candidate: 'template<class T> matrix<T> modmul(matrix<T>&, matrix<T>&)'
   16 | matrix<T> modmul(const matrix<T> &l, const matrix<T> &r)
      |           ^~~~~~
a.cc:16:11: note:   candidate expects 2 arguments, 3 provided
a.cc:34:16: note: candidate: 'template<class T> std::vector<_Tp> modmul(matrix<T>&, const std::vector<_Tp>&)'
   34 | std::vector<T> modmul(const matrix<T> &a, const std::vector<T> &x)
      |                ^~~~~~
a.cc:34:16: note:   candidate expects 2 arguments, 3 provided
a.cc:67:19: error: no matching function for call to 'modmul(matrix<long long int>&, matrix<long long int>&, const long long int&)'
   67 |         x = modmul(x, x, mod);
      |             ~~~~~~^~~~~~~~~~~
a.cc:16:11: note: candidate: 'template<class T> matrix<T> modmul(matrix<T>&, matrix<T>&)'
   16 | matrix<T> modmul(const matrix<T> &l, const matrix<T> &r)
      |           ^~~~~~
a.cc:16:11: note:   candidate expects 2 arguments, 3 provided
a.cc:34:16: note: candidate: 'template<class T> std::vector<_Tp> modmul(matrix<T>&, const std::vector<_Tp>&)'
   34 | std::vector<T> modmul(const matrix<T> &a, const std::vector<T> &x)
      |                ^~~~~~
a.cc:34:16: note:   candidate expects 2 arguments, 3 provided