#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let N = input!(usize); let M = input!(usize); let mut ans = ((N + N) * C(2 * N, N)) % MOD; for _ in 0..M { let t = input!(usize); let x = input!(usize); let y = input!(usize); if t == 1 { let mut d = C(x + y, x) * C(N - (x + 1) + N - y, N - y); d %= MOD; ans = ans + MOD - d; ans %= MOD; } else { let mut d = C(x + y, x) * C(N - x + N - (y + 1), N - x); d %= MOD; ans = ans + MOD - d; ans %= MOD; } } writeln!(out, "{}", ans); } const M_: usize = 4 * 100_001; const MOD: usize = 1_000_000_007; const fn comb() -> ([usize; M_], [usize; M_], [usize; M_]) { let mut f = [0; M_]; let mut f_inv = [0; M_]; let mut inv = [0; M_]; f[0] = 1; f[1] = 1; f_inv[0] = 1; f_inv[1] = 1; inv[1] = 1; let mut i = 2; while i < M_ { f[i] = (f[i - 1] * i) % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; f_inv[i] = f_inv[i - 1] * inv[i] % MOD; i += 1; } return (f, f_inv, inv); } const _F: [usize; M_] = comb().0; const _F_INV: [usize; M_] = comb().1; const _INV: [usize; M_] = comb().2; const fn C(n: usize, k: usize) -> usize { if n < k { return 0; } else { return _F[n] * (_F_INV[k] * _F_INV[n - k] % MOD) % MOD; } } struct Scanner { reader: R, buf_str: Vec, buf_iter: str::SplitWhitespace<'static>, } impl Scanner { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }