import sys input = sys.stdin.readline N,M,A=map(int,input().split()) L=[list(map(int,input().split())) for i in range(M)] for i in range(M): L[i][1]+=1 LLIST=[[] for i in range(N+2)] for x,y,z in L: LLIST[x].append([y,z]) DP=[0]*(N+2) USE=[0]*(N+2) USE[1]=1 USE[N+1]=1 for i in range(N+2): if DP[i-1]>=DP[i]: DP[i]=DP[i-1] USE[i]=0 USE[1]=1 for y,z in LLIST[i]: if USE[i]==1 and y==N+1: DP[y]=max(DP[y],DP[i]+z) elif USE[i]==0 and y==N+1: DP[y]=max(DP[y],DP[i]+z-A) elif USE[i]==1: DP[y]=max(DP[y],DP[i]+z-A) USE[y]=1 elif USE[i]==0: DP[y]=max(DP[y],DP[i]+z-2*A) USE[y]=1 #print(DP) print(DP[-1])