#include #include using namespace std; #define MOD 1000000007 #define CON_MAX 75 long long int inv[ CON_MAX ] = {}; long long int con[ CON_MAX ][ CON_MAX ]; long long int gx, gy, k; vector< long long int > x, y, n; long long int ans = 0; void kansu( long long int a, vector< long long int > v, long long int px, long long int py ) { if ( a == k ) { if ( px == gx && py == gy ) { long long int ma = 0; long long int cnt = 1; for ( long long int i = 0; i < k; i++ ) { ma += v[i]; cnt *= con[v[i]][ma]; cnt %= MOD; } ans += cnt; } return; } for ( long long int i = 0; i <= n[a]; i++ ) { kansu( a + 1, v, px, py ); px += x[a]; py += y[a]; v[a]++; } return; } int main() { inv[1] = 1; for ( long long int i = 2; i <= CON_MAX; i++ ) { inv[i] = MOD - ( MOD / i ) * inv[ MOD % i ] % MOD; } for ( long long int i = 0; i < CON_MAX; i++ ) { con[0][i] = 1; for ( long long int j = 1; j < CON_MAX; j++ ) { con[j][i] = con[j-1][i] * ( i - j + 1 ); con[j][i] %= MOD; con[j][i] *= inv[j]; con[j][i] %= MOD; } } cin >> gx >> gy >> k; vector< long long int > v; for ( long long int i = 0; i < k; i++ ) { long long int inx, iny, inn; cin >> inx >> iny >> inn; x.push_back( inx ); y.push_back( iny ); n.push_back( inn ); v.push_back( 0 ); } kansu( 0, v, 0, 0 ); cout << ans << endl; return 0; }