module Main; // import BinaryHeap; // import BoolArray; // import CPLib.Arithmetic; // import CPLib.Bipartite; // import CPLib.Bits; // import CPLib.Convolution; // import CPLib.DSegtree; // import CPLib.Graph; import CPLib.IO; // import CPLib.LDSegtree; // import CPLib.LSegtree; // import CPLib.MaxFlow; // import CPLib.Memoize; // import CPLib.MinCostFlow; // import CPLib.Misc; // import CPLib.Monoid; // import CPLib.Segtree; // import CPLib.String; // import CPLib.Trait; // import CPLib.TwoSat; // import CPLib.UnionFind; import CPLib.ZP; // import HashMap; // import HashSet; // import Math; type Z = ZP P1000000007; facts : Array Z = ( let n = 5e5; range(1, n).fold([zp(1)], |i, facts| let v = facts.@(facts.@size-1); facts.push_back(v * zp(i)) ) ); fact_inv : Array Z = facts.map(inv); binom : I64 -> I64 -> Z = |n, k| ( facts.@(n) * fact_inv.@(k) * fact_inv.@(n-k) ); main : IO () = ( let n = *read_i; let m = *read_i; let free = fill(n+1, fill(n+1, 0)); let free = *range(0, m).fold_m(free, |_, free| let t = *read_i; let x = *read_i; let y = *read_i; let free = free[x][y].iset(t); free.pure ); let dp = fill(n+1, fill(n+1, zp(0) : Z)); let dp = range(0, n+1).fold(dp, |x, dp| range(0, n+1).fold(dp, |y, dp| let v = zp(0); let v = v + if x > 0 { let (px, py) = (x - 1, y); let free = free.@(px).@(py) == 1; dp[px][py].iget + if free { zp(0) } else { binom(px+py, px) } } else { zp(0) }; let v = v + if y > 0 { let (px, py) = (x, y - 1); let free = free.@(px).@(py) == 2; dp[px][py].iget + if free { zp(0) } else { binom(px+py, px) } } else { zp(0) }; dp[x][y].iset(v) ) ); dp[n][n].iget.@value.to_string.println;; pure() );