using System.Collections.Generic; using System.Linq; using System; public class P { public int q { get; set; } public int c { get; set; } } public class Hello { public static int n, m, k; public static int MOD = 1000000007; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); n = int.Parse(line[0]); m = int.Parse(line[1]); k = int.Parse(line[2]); var ps = new List

[301]; for (int i = 0; i < 301; i++) ps[i] = new List

(); var hs = new HashSet(); for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var p = int.Parse(line[0]); var q = int.Parse(line[1]); var c = int.Parse(line[2]); if (c <= k) { ps[p].Add(new P { q = q, c = c }); hs.Add(p); } } var plist = hs.ToArray(); Array.Sort(plist); getAns(ps, plist); } static void getAns(List

[] ps, int[] plist) { var dp = new int[n, 301, k + 1]; foreach (var x in plist) foreach (var y in ps[x]) { dp[1, y.q, y.c]++; dp[1, y.q, y.c] %= MOD; } for (int i = 0; i < n - 1; i++) { for (int j = 1; j <= 300; j++) { for (int L = 0; L <= k; L++) { foreach (var x in ps[j]) { var ww = L + x.c; if (ww <= k) { dp[i + 1, x.q, ww] += dp[i, j, L]; dp[i + 1, x.q, ww] %= MOD; } } } } } var ans = 0L; for (int i = 1; i <= 300; i++) { ans += dp[n - 1, i, k]; ans %= MOD; } Console.WriteLine(ans); } }