#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; int N, M, K; int dp[2][310][310]; int P[310], Q[310], C[310]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> K; REP(i, M) cin >> P[i] >> Q[i] >> C[i]; REP(i, M) { dp[0][Q[i]][C[i]]++; } REP(i, N - 2) { REP(j, M) { REP(k, 305) { int ni = (i + 1) % 2; int nj = Q[j], bj = P[j]; int nk = k + C[j]; if (nk > K)break; dp[ni][nj][nk] += dp[i % 2][bj][k]; dp[ni][nj][nk] %= mod; } } REP(j, 310)REP(k, 310) { dp[i % 2][j][k] = 0; } } int ans = 0; REP(i, 310) { ans += dp[N % 2][i][K]; ans %= mod; } cout << ans << endl; return 0; }