n,m,a=map(int,input().split()) dp = [0]*(n+1) edge = [[] for i in range(n)] for i in range(m) : x,y,z=map(int,input().split()) edge[y-1].append([x-1,z]) ans = 0 for i in range(n) : dp[i+1] = ans - a for p in edge[i] : dp[i+1] = max(dp[i+1], dp[p[0]]+p[1]-(a if i != n-1 else 0)) ans = max(ans, dp[i+1]) print(ans)