#include using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair pdd; typedef vector vll; typedef vector> vvll; typedef vector> Graph; const ll mod = 1e9 + 7; //const ll mod = 998244353; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << #x << " = " << (x) << endl; #define spa << " " << #define fi first #define se second template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template ostream& operator << (ostream& os, const pair v){ os << "(" << v.first << ", " << v.second << ")"; return os; } template ostream& operator << (ostream& os, const vector v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os; } template ostream& operator << (ostream& os, const vector> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } template void debug(vector>&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cerr< class modint { // long long から modint を作るときは必ず正の数にしてからコンストラクタに入れること! // そうしないとバグります using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; using mint = modint; template constexpr T power(T x, U exp) { T ret = static_cast(1); while (exp) { if (exp % static_cast(2) == static_cast(1)) ret *= x; exp /= static_cast(2); x *= x; } return ::std::move(ret); } typedef vector vm; typedef vector vvm; typedef vector vvvm; struct sinko{ ll P, Q, C; }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N, M, K; cin >> N >> M >> K; vector S(M); REP(i, M){ ll P, Q, C; cin >> P >> Q >> C; P--, Q--; sinko s = {P, Q, C}; S[i] = s; } vvvm dp(N, vvm(300, vm(305, 0))); REP(i, 300) dp[0][i][0] = 1; REP(i, N-1){ REP(k, 305){ REP(j, M){ if(k+S[j].C<305){ dp[i+1][S[j].Q][k+S[j].C] += dp[i][S[j].P][k]; } } } } mint res = 0; REP(i, 300) res += dp[N-1][i][K]; cout << res.value() << endl; return 0; }