// {{{ Templates #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 100; // }}} constexpr int MAX = 100; ll combi[MAX + 1][MAX + 1]; ll comb(ll i, ll j, ll k, ll l, ll m) { ll prod = 1; ll sum = i + j + k + l + m; prod = (prod * combi[sum][i]) % MOD; sum -= i; prod = (prod * combi[sum][j]) % MOD; sum -= j; prod = (prod * combi[sum][k]) % MOD; sum -= k; prod = (prod * combi[sum][l]) % MOD; return prod; } int main() { cin.tie(0); ios::sync_with_stdio(false); combi[0][0] = 1; for (ll i = 1; i <= MAX; i++) { for (ll j = 0; j <= MAX; j++) { if (j == 0) { combi[i][j] = 1; } else { combi[i][j] = (combi[i - 1][j - 1] + combi[i - 1][j]) % MOD; } } } ll gx, gy; cin >> gx >> gy; ll k; cin >> k; array x; array y; array num; for (ll i = 0; i < 5; i++) { if (i < k) { cin >> x[i] >> y[i] >> num[i]; } else { x[i] = 0; y[i] = 0; num[i] = 0; } } ll cnt = 0; for (ll i = 0; i <= num[0]; i++) { const ll x0 = x[0] * i; const ll y0 = y[0] * i; for (ll j = 0; j <= num[1]; j++) { const ll x1 = x[1] * j; const ll y1 = y[1] * j; for (ll k = 0; k <= num[2]; k++) { const ll x2 = x[2] * k; const ll y2 = y[2] * k; for (ll l = 0; l <= num[3]; l++) { const ll x3 = x[3] * l; const ll y3 = y[3] * l; for (ll m = 0; m <= num[4]; m++) { const ll X = x0 + x1 + x2 + x3 + x[4] * m; const ll Y = y0 + y1 + y2 + y3 + y[4] * m; if (X == gx and Y == gy) { cnt += comb(i, j, k, l, m); cnt = cnt % MOD; } } } } } } cout << cnt << endl; return 0; }