MOD = 10 ** 9 + 7 n, m, k = map(int, input().split()) t = [[] for _ in range(300)] for _ in range(m): p, q, c = map(int, input().split()) t[p - 1].append((q - 1, c)) dp = [[[0] * (300) for _ in range(k + 1)] for _ in range(n)] for i in range(300): dp[0][0][i] = 1 for i in range(n - 1): for j in range(k + 1): for a in range(300): for b, c in t[a]: if j + c <= k: dp[i + 1][j + c][b] += dp[i][j][a] print(sum(dp[n - 1][k]))