//GIVE ME AC!!!!!!!!!!!!!!!!! //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include #define ll long long #define ld long double #define floatset() fixed<; using vi=vector; using vs=vector; using vc=vector; using vvl=vector; using P=pair; using vvc=vector; using vd=vector; using vp=vector

; using vb=vector; using P=pair; const int dx[8]={1,0,-1,0,1,-1,-1,1}; const int dy[8]={0,1,0,-1,1,1,-1,-1}; const ll inf =1e18; const ll MOD=1000000007; const ll mod=998244353; const double pi=acos(-1); template ostream &operator<<(ostream&os,const pair&p) { os< istream &operator>>(istream&is,pair&p) { is>>p.first>>p.second; return is; } template ostream &operator<<(ostream&os,const vector&v) { for(int i=0;i<(int)v.size();i++) { os< istream &operator>>(istream&is,vector&v) { for(T &in:v)is>>in; return is; } void scan(){} template void scan(Head&head,Tail&... tail) { cin>>head; scan(tail...); } template void print(const T &t) { cout << t << '\n'; } template void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } template void fin(const T &... a) { print(a...); exit(0); } template ll sum_(vector&v){ ll res=0; for(auto &e:v)res+=e; return res; } template inline bool chmax(T1&a,T2 b){return a inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);} ll fac[400100],inv[400100],facinv[400100]; void init(){ fac[0]=1; fac[1]=1; inv[1]=1; facinv[0]=1; facinv[1]=1; for(int i=2;i<=400010;i++){ fac[i]=(fac[i-1]*i)%MOD; inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD; facinv[i]=facinv[i-1]*inv[i]%MOD; } } ll COM(ll n,ll k) {return fac[n]*(facinv[k]*facinv[n-k]%MOD)%MOD;} int main(){ init(); LL(n,m); ll ans=(COM(2*n,n)*2*n)%MOD; rep(i,0,m){ LL(t,x,y); ll now=COM(x+y,x); if(t==1)x++; else y++; ll now1=COM(2*n-x-y,n-x); now*=now1; now%=MOD; ans-=now; if(ans<0)ans+=MOD; } cout<