#include using namespace std; using i64 = long long; using u64 = unsigned long long; #define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i) #ifdef ENABLE_DEBUG template void debug(T value) { cerr << value; } template void debug(T value, Ts... args) { cerr << value << ", "; debug(args...); } #define DEBUG(...) \ do { \ cerr << " \033[33m (L" << __LINE__ << ") "; \ cerr << #__VA_ARGS__ << ":\033[0m "; \ debug(__VA_ARGS__); \ cerr << endl; \ } while (0) #else #define debug(...) #define DEBUG(...) #endif const i64 MOD = 1'000'000'007; struct mint { long long x; mint(long long x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, K; cin >> N >> M >> K; vector> nextc; REP(i, M) { int p, q, c; cin >> p >> q >> c; p--; q--; nextc.emplace_back(p, q, c); } vector>> dp( N + 1, vector>(300, vector(K + 1))); REP(j, 300) { dp[1][j][0] = 1; } for (int i = 2; i <= N; ++i) { REP(j, M) { auto [p, q, c] = nextc[j]; REP(k, K + 1) { mint x = dp[i - 1][p][k]; if (k + c <= K) dp[i][q][k + c] += x; } } } mint ans = 0; REP(j, 300) { ans += dp[N][j][K]; } cout << ans << endl; }