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