/** * author: tomo0608 * created: 09.07.2021 21:44:08 **/ #pragma GCC optimize("Ofast") #include using namespace std; #if __has_include() #include using namespace atcoder; #endif typedef long long ll; typedef long double ld; template using V = vector; template using VV = V>; template using VVV = V>; typedef pair pii; typedef pair pll; #define all(x) x.begin(),x.end() #define rep1(a) for(long long i = 0; i < a; i++) #define rep2(i, a) for(long long i = 0; i < a; i++) #define rep3(i, a, b) for(long long i = a; i < b; i++) #define rep4(i, a, b, c) for(long long i = a; i < b; i += c) #define drep1(a) for(long long i = a-1; i >= 0; i--) #define drep2(i, a) for(long long i = a-1; i >= 0; i--) #define drep3(i, a, b) for(long long i = a-1; i >= b; i--) #define drep4(i, a, b, c) for(long long i = a-1; i >= b; i -= c) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define drep(...) overload4(__VA_ARGS__, drep4, drep3, drep2, drep1)(__VA_ARGS__) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) templatevoid input(T&... a){(cin >> ... >> a);}; #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) #define STRING(...) string __VA_ARGS__; input(__VA_ARGS__) void print(){cout << '\n';} templatevoid print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';} template using priority_queue_rev = priority_queue, greater >; template inline bool chmax(T &a, const U &b) { if (a inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template istream &operator>>(istream &is, vector &v) { for (auto &e : v) is >> e; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } template ostream& operator << (ostream& os, set& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template ostream &operator<<(ostream &os, map &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} #ifdef __LOCAL void debug_out(){ cerr << endl;} template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif template inline int count_between(vector &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; // input and output of modint #include istream &operator>>(istream &is, atcoder::modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const atcoder::modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, atcoder::modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const atcoder::modint1000000007 &a) { return os << a.val(); } template istream &operator>>(istream &is, atcoder::static_modint &a) { long long v; is >> v; a = v; return is; } template ostream &operator<<(ostream &os, const atcoder::static_modint &a) { return os << a.val(); } template istream &operator>>(istream &is, atcoder::dynamic_modint &a) { long long v; is >> v; a = v; return is; } template ostream &operator<<(ostream &os, const atcoder::dynamic_modint &a) { return os << a.val(); } // Binomial Coefficient of modint template struct BiCoef { vector fact_, inv_, finv_; constexpr BiCoef() {} constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1){ init(n); } constexpr void init(int n) noexcept { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); int MOD = fact_[0].mod(); for(int i = 2; i < n; i++){ fact_[i] = fact_[i-1]*i; inv_[i] = -inv_[MOD%i]*(MOD/i); finv_[i] = finv_[i-1]*inv_[i]; } } constexpr T com(int n, int k) const noexcept { if(n < k || n < 0 || k < 0)return 0; return fact_[n]*finv_[k]*finv_[n-k]; } constexpr T perm(int n, int k) const noexcept { if(n < k || n < 0 || k < 0)return 0; return fact_[n]*finv_[n-k]; } constexpr T fact(int n) const noexcept { if(n < 0)return 0; return fact_[n]; } constexpr T inv(int n) const noexcept { if(n < 0)return 0; return inv_[n]; } constexpr T finv(int n) const noexcept { if(n < 0)return 0; return finv_[n]; } }; typedef atcoder::modint1000000007 mint; //typedef atcoder::modint998244353 mint; mint interpolation(const std::vector &y, ll T){ // y = [f(0),\ldots, f(n)]として, f(T)を求める int n = y.size()-1; if(T <= n)return y[T]; mint ret = 0; std::vector L(n+1, 1), R(n+1, 1); for(int i = 0; i < n; i++)L[i+1] = L[i] * (T - i); for(int i = n; i > 0; i--)R[i-1] = R[i] * (T - i); std::vector fact(n+1,1),ifact(n+1,1); for(int i = 1; i <= n; i++)fact[i] = fact[i-1] * i; ifact[n] = fact[n].inv(); for(int i = n; i > 0; i--)ifact[i-1] = ifact[i] * i; for(int i = 0; i <= n; i++){ mint tmp = y[i] * L[i] * R[i] * ifact[i] * ifact[n - i]; if((n - i) & 1)ret -= tmp; else ret += tmp; } return ret; } void solve(){ INT(n,m); BiCoef B(400040); mint ans = 2*n; ans *= B.com(n*2, n); rep(i,m){ INT(t,x,y); if(t == 1)ans -= B.com(x+y, x) * B.com(n*2-x-y-1, n-y); else ans -= B.com(x+y, x) * B.com(n*2-x-y-1, n-x); } print(ans); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } return 0; }