#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX_N = 200'010; const ll MOD = 1000000007; ll fac[MAX_N]; ll inv[MAX_N]; ll finv[MAX_N]; class ModInteger { public: ModInteger(int N) { fac[0] = fac[1] = 1; inv[0] = inv[1] = 1; finv[0] = finv[1] = 1; for (int i = 2; i <= N; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll combination(int n, int k) { if (n < k) return 0LL; if (n < 0 || k < 0) return 0LL; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll permutation(int n, int k = -1) { if (k == -1) k = n; if (n < k) return 0LL; if (n < 0 || k < 0) return 0LL; return fac[n] * (finv[n - k] % MOD) % MOD; } ll repeated_combination(int n, int k) { return combination(n + k - 1, k); } }; ModInteger mi(100); int K; int GX, GY; int X[5]; int Y[5]; int N[5]; ll ans; void dfs(int idx, vector counter) { if (idx == K) { int y = 0; int x = 0; int sum = 0; for (int i = 0; i < K; ++i) { int cnt = counter[i]; sum += cnt; y += cnt * Y[i]; x += cnt * X[i]; } if (GY == y && GX == x) { ll val = 1; for (int i = 0; i < K; ++i) { int cnt = counter[i]; val *= mi.combination(sum, cnt); val %= MOD; sum -= cnt; } ans += val; ans %= MOD; } } else { for (int c = 0; c <= N[idx]; ++c) { counter[idx] = c; dfs(idx + 1, counter); } } } int main() { ans = 0; cin >> GX >> GY >> K; for (int i = 0; i < K; ++i) { cin >> X[i] >> Y[i] >> N[i]; } vector counter(K, 0); dfs(0, counter); cout << ans << endl; return 0; }