##################################### # nCr % 10**9+7 n = 10**6 ##################################### class Combination: def __init__(self, mod=10**9+7): self.mod = mod self.max_n = 1 self.factorial = [1, 1] self.inverse = [None, 1] self.f_inverse = [1, 1] def __preprocessing(self, max_n): fac = self.factorial inv = self.inverse finv = self.f_inverse mod = self.mod fac += [-1] * (max_n - self.max_n) inv += [-1] * (max_n - self.max_n) finv += [-1] * (max_n - self.max_n) for i in range(self.max_n + 1, max_n + 1): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod self.max_n = max_n def fac(self, n): if n < 0: return 0 if n > self.max_n: self.__preprocessing(n) return self.factorial[n] def nCr(self, n, r): if n < r or n < 0 or r < 0: return 0 if n > self.max_n: self.__preprocessing(n) return self.factorial[n] * (self.f_inverse[r] * self.f_inverse[n - r] % self.mod) % self.mod def nPr(self, n, r): if n < r or n < 0 or r < 0: return 0 if n > self.max_n: self.__preprocessing(n) return self.factorial[n] * self.f_inverse[n - r] % self.mod def nHr(self, n, r): return self.nCr(n-1+r, n-1) mod = 1000000007 cmb = Combination(mod) # cmb.nCr(n, j) n, m = map(int, input().split()) total = (2*n*cmb.nCr(2*n, n)) % mod for _ in range(m): t, x, y = map(int, input().split()) if t == 1: total -= cmb.nCr(x+y, x) * cmb.nCr(2*n-x-y-1, n-x-1) if t == 2: total -= cmb.nCr(x+y, x) * cmb.nCr(2*n-x-y-1, n-x) total %= mod print(total)