#include using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < (n); ++i) #define rep2(i,m,n) for (int i = m; i < (n); ++i) #define all(x) (x).begin(),(x).end() template void chmin(T &a, const T &b) noexcept { if (b < a) a = b;} template void chmax(T &a, const T &b) noexcept { if (a < b) a = b;} template void drop(const T &x) { std::cout< void debug_out(const T &x, const Args &... args) { std::cout<= 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(ll 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;} bool operator==(const mint rhs) const { return x == rhs.x; } bool operator!=(const mint rhs) const { return x != rhs.x; } bool operator<(const mint &a) const{ return x>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { int n, m, k; cin >> n >> m >> k; using P = pair; vector > G(300); rep(i,m) { int p, q, c; cin >> p >> q >> c; p--; q--; G[p].emplace_back(q,c); } vector > > dp(305, vector >(305, vector(305, 0))); //つなげた数,最後のコード,複雑さの合計 rep(i,300) dp[1][i][0] = 1; rep2(i, 1, n) { rep(from, 300) { for (auto&& e : G[from]) { int to = e.first, cost = e.second; rep(j, k+1) { if (j+cost > k) break; dp[i+1][to][j+cost] += dp[i][from][j]; } } } } mint ans = 0; rep(i,300) ans += dp[n][i][k]; cout << ans << endl; return 0; }