A festival will be held in a town's main street. There are *n* sections in the main street. The sections are numbered 1 through *n* from left to right. The distance between each adjacent sections is 1.

In the festival *m* fireworks will be launched. The *i*-th (1 ≤ *i* ≤ *m*) launching is on time *t*<sub class="lower-index">*i*</sub> at section *a*<sub class="lower-index">*i*</sub>. If you are at section *x* (1 ≤ *x* ≤ *n*) at the time of *i*-th launching, you'll gain happiness value *b*<sub class="lower-index">*i*</sub> - |*a*<sub class="lower-index">*i*</sub> - *x*| (note that the happiness value might be a negative value).

You can move up to *d* length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.

Note that two or more fireworks can be launched at the same time.
The first line contains three integers *n*, *m*, *d* (1 ≤ *n* ≤ 150000; 1 ≤ *m* ≤ 300; 1 ≤ *d* ≤ *n*).

Each of the next *m* lines contains integers *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub>, *t*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ *n*; 1 ≤ *b*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>; 1 ≤ *t*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>). The *i*-th line contains description of the *i*-th launching.

It is guaranteed that the condition *t*<sub class="lower-index">*i*</sub> ≤ *t*<sub class="lower-index">*i* + 1</sub> (1 ≤ *i* &lt; *m*) will be satisfied.
class heap:
    def __init__(self):
        self.ma=[[]]
        self.lay=0
    def add(self,n):
        self.ma[self.lay].append(n)
        indx=(len(self.ma[self.lay])-1)
        parent=self.ma[self.lay-1][indx//2]
        kid=n
        ly=self.lay
        while ly>0 and parent<kid:
            self.ma[ly-1][indx//2],self.ma[ly][indx]=self.ma[ly][indx],self.ma[ly-1][indx//2]
            ly-=1
            indx=indx//2
        if len(self.ma[-1])>=2**self.lay:
            self.lay+=1
            self.ma.append([])
    def dis(self,n):
        ii,jj=-1,-1
        for i in range(len(self.ma)):
            for j in range(len(self.ma[i])):
                if self.ma[i][j]==n:
                    ii,jj=i,j
                    break
        try:
            self.ma[ii][jj]=self.ma[-1][-1]
            parent=self.ma[ii][jj]
            self.ma[-1].pop(-1)
        except:
            self.ma[ii][jj]=self.ma[-2][-1]
            parent=self.ma[ii][jj]
        #if len(self.ma[-1])==0:
        #    self.ma.pop(-1)
        jjj=jj
        while ii<len(self.ma)-1 and jj!=-1:
            f=0
            mx=-1
            jjj=-1
            if len(self.ma[ii+1])>jj*2:
                if self.ma[ii+1][jj*2]>parent:
                    f=1
                    mx=self.ma[ii+1][jj*2]
                    jjj=jj*2
            if len(self.ma[ii+1])>jj*2+1:
                if self.ma[ii+1][jj*2+1]>parent:
                    f=1
                    if self.ma[ii+1][jj*2+1]>mx:
                        mx=self.ma[ii+1][jj*2+1]
                        jjj=jj*2+1
            if f==0:
                break
            else:
                self.ma[ii+1][jjj],self.ma[ii][jj]=self.ma[ii][jj],self.ma[ii+1][jjj]
            ii+=1
            jj=jjj
            parent=self.ma[ii][jj]
    def mxx(self):
        return self.ma[0][0]


dp=[]
for i in range(2):
    dpp=[]
    for j in range(150001):
        dpp.append(0)
    dp.append(dpp)
n,m,d=map(int,input().split())
for i in range(m):
    a,b,t=map(int,input().split())
    a-=1
    if i!=0:
        mh=heap()
        l1=0
        r1=(t-tg)*d
        if(r1>n-1):
            r=n-1
        for k in range(l1,r1+1):
            mh.add(dp[0][k])
        dp[1][0]=mh.mxx()
        for j in range(1,n):
            ll1=j-(t-tg)*d
            rr1=j+(t-tg)*d
            if ll1<0:
                ll1=0
            if rr1>n-1:
                rr1=n-1
            if r1-l1==rr1-ll1:
                mh.add(dp[0][rr1])
                mh.dis(dp[0][l1])
            elif r1-l1<rr1-ll1:
                mh.add(dp[0][rr1])
            else:
                mh.dis(dp[0][l1])
            dp[1][j]=mh.mxx()
            l1=ll1
            r1=rr1
    for j in range(n):
        dp[0][j]=dp[1][j]+b-(abs(a-j))
    tg=t
mx=dp[0][0]
for i in range(1,n):
    mx=max(mx,dp[0][i])
print(mx)




























