Language: C++

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000009;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator >(const Edge& e) const { return cost > e.cost; }
};

/*--------------------template--------------------*/
typedef ll Data;
typedef vector<Data> Array;
typedef vector<Array> Matrix;

bool is_zero(Data dat) { return (abs(dat) < EPS); }

Matrix modulo(Matrix mat)
{
	Matrix res;
	REP(i, mat.size())REP(j, mat[0].size()) res[i][j] = mat[i][j] % MOD;
	return res;
}

Matrix operator-(Matrix mat) 
{
	REP(i, mat.size()) REP(j, mat[0].size()) mat[i][j] = -mat[i][j];
	return modulo(res);
}

Matrix operator+(Matrix lhs, const Matrix &rhs) 
{
	REP(i, lhs.size()) REP(j, lhs[0].size()) lhs[i][j] = lhs[i][j] + rhs[i][j];
	return modulo(res);
}

Matrix operator-(Matrix lhs, const Matrix &rhs) 
{
	REP(i, lhs.size()) REP(j, lhs[0].size()) lhs[i][j] = lhs[i][j] - rhs[i][j];
	return modulo(res);
}

Matrix operator*(const Matrix &lhs, const Matrix &rhs) 
{
	Matrix res(lhs.size(), Array(rhs[0].size(), 0));
	REP(i, lhs.size()) REP(j, rhs[0].size()) REP(k, rhs.size())
		res[i][j] = fma(lhs[i][k], rhs[k][j], res[i][j]);
	return modulo(res);
}

Array operator+(const Array &lhs, const Array &rhs) 
{
	Array res = lhs;
	REP(i, rhs.size()) res[i] = res[i] + rhs[i];
	return res;
}

Array operator*(const Matrix &lhs, const Array &rhs) 
{
	Array res(lhs.size());
	REP(i, lhs.size())
		res[i] = inner_product(begin(lhs[i]), end(lhs[i]), begin(rhs), Data(0));
	return res;
}

Array operator*(Data scalar, const Array &rhs) 
{
	Array res(rhs.size());
	REP(i, rhs.size())
		res[i] = scalar * rhs[i];
	return res;
}

Matrix scalar(int size, Data k) {
	Matrix mat(size, Array(size, 0));
	REP(i, size) mat[i][i] = k;
	return modulo(res);
}

Matrix operator^(const Matrix &lhs, const int n) {
	if (n == 0) return scalar(lhs.size(), 1);
	Matrix res = (lhs * lhs) ^ (n / 2);
	if (n % 2) res = res * lhs;
	return modulo(res);
}

Data det(Matrix A) {
	const int n = A.size();
	Data D = Data(1);
	for (int i = 0; i < n; ++i) {
		int pivot = i;
		for (int j = i + 1; j < n; ++j)
			if (abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
		swap(A[pivot], A[i]);
		D = D * A[i][i] * Data(i != pivot ? -1 : 1);
		if (is_zero(A[i][i])) break;
		for (int j = i + 1; j < n; ++j)
			for (int k = n - 1; k >= i; --k)
				A[j][k] = A[j][k] - A[i][k] * A[j][i] / A[i][i];
	}
	return D;
}

int main()
{
	ll w, h, n;
	for (int cs = 0; cin >> w >> h >> n&&w; cs++)
	{
		vector<pair<ll,ll>> v;
		REP(i, n)
		{
			ll x, y; cin >> x >> y;
			x--; y--;
			if (y == 0) continue;
			v.emplace_back(y, x);
		}
		n = v.size();
		sort(ALL(v));
		Array ary(w); ary[0] = 1;
		Matrix mat(w, Array(w));
		REP(i, w)REP(j, w)
		{
			if (abs(i - j) <= 1) mat[i][j] = 1;
		}
		ll tmp = 0, p = 0;
		while (1)
		{
			ll next;
			if (p < n) next = v[p].first;
			else next = h;
			ary = (mat ^ (next - tmp - 1))*ary;
			if (next == h) break;
			vi obj; obj.push_back(v[p].second);
			p++;
			while (p < n && v[p].first == v[p-1].first)
			{
				obj.push_back(v[p].second);
				p++;
			}
			Array zero(w);
			Matrix objmat = mat;
			REP(i, obj.size()) objmat[obj[i]] = zero;
			ary = objmat*ary;
			tmp = next;
		}
		cout << "Case " << cs+1 << ": " << ary.back() << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'Matrix operator-(Matrix)':
a.cc:43:23: error: 'res' was not declared in this scope
   43 |         return modulo(res);
      |                       ^~~
a.cc: In function 'Matrix operator+(Matrix, const Matrix&)':
a.cc:49:23: error: 'res' was not declared in this scope; did you mean 'rhs'?
   49 |         return modulo(res);
      |                       ^~~
      |                       rhs
a.cc: In function 'Matrix operator-(Matrix, const Matrix&)':
a.cc:55:23: error: 'res' was not declared in this scope; did you mean 'rhs'?
   55 |         return modulo(res);
      |                       ^~~
      |                       rhs
a.cc: In function 'Matrix scalar(int, Data)':
a.cc:92:23: error: 'res' was not declared in this scope
   92 |         return modulo(res);
      |                       ^~~