#include #include #include #include using namespace std; long long modpow(long long a, long long b, long long m) { long long p = 1, q = a; for (int i = 0; i < 30; i++) { if ((b / (1LL << i)) % 2LL == 1) { p *= q; p %= m; } q *= q; q %= m; } return p; } long long Div(long long a, long long b, long long m) { return (a * modpow(b, m - 2, m)) % m; } long long mod = 1000000007; long long N, M; long long A[1 << 18], B[1 << 18], C[1 << 18]; long long fact[1 << 20], factinv[1 << 20]; map, int> Map; long long ncr(long long n, long long r) { return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod; } long long keiro(long long a, long long b) { // (0, 0) から (a, b) まで移動する方法の総数 return ncr(a + b, b); } int main() { // Step #1. Input cin >> N >> M; for (int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i]; assert(1 <= N && N <= 200000); assert(0 <= M && M <= 200000); for (int i = 1; i <= M; i++) { assert(1 <= A[i] && A[i] <= 2); assert(Map[make_tuple(A[i], B[i], C[i])] == 0); Map[make_tuple(A[i], B[i], C[i])] = 1; if (A[i] == 1) { assert(0 <= B[i] && B[i] <= N - 1); assert(0 <= C[i] && C[i] <= N); } if (A[i] == 2) { assert(0 <= B[i] && B[i] <= N); assert(0 <= C[i] && C[i] <= N - 1); } } // Step #2. Prepare fact[0] = 1; for (int i = 1; i <= 1000000; i++) fact[i] = (1LL * i * fact[i - 1]) % mod; for (int i = 0; i <= 1000000; i++) factinv[i] = Div(1, fact[i], mod); // Step #3. Solve long long Answer = (2LL * N) * keiro(N, N) % mod; for (int i = 1; i <= M; i++) { if (A[i] == 1) { long long p1 = keiro(B[i], C[i]); long long p2 = keiro(N - (B[i] + 1LL), N - C[i]); Answer -= p1 * p2 % mod; Answer = (Answer + mod) % mod; } if (A[i] == 2) { long long p1 = keiro(B[i], C[i]); long long p2 = keiro(N - B[i], N - (C[i] + 1LL)); Answer -= p1 * p2 % mod; Answer = (Answer + mod) % mod; } } // Step #4. Output cout << Answer << endl; return 0; }