#Lutece1132. 酱神赏花

酱神赏花

Migrated from Lutece 1132 酱神赏花

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

酱神去杭州赏花。

花展在一条街道上举行,这条街道上有一共有n个节点,自左而右从11nn编号,11号和nn号是左右两个端点,两个相邻端点之间的距离为11.本次花展一共要展出mm朵花,在第titi时刻,有一朵颜值为bibi的花将在第aiai个节点展出,如果酱神在titi时刻处于第xx个节点,那么他能获得的开心值为bixaibi-|x-ai|,注意这个值可能为负。

t=1t=1的时刻,酱神可以随意从11nn选出一个节点作为赏花的起点。在接下来的每个单位时间段中,酱神最多能移动dd的距离。酱神每秒只能移动整数个距离,且任何时刻不能超出街道的范围。

他能获得的最大开心值为多少?

Input

第一行33个数n,m,dn,m,d

接下来mm行,每行33个数ai,bi,tiai,bi,ti

1n1051\leq n\leq {10}^{5},1m1001\leq m\leq 100

1ain1\leq {a}_{i}\leq n

1bi1091\leq {b}_{i}\leq {10}^{9}

1ti1091\leq {t}_{i}\leq {10}^{9}

1d1091\leq d\leq {10}^{9}

Output

输出一个数,酱神的最大开心值。

Samples

30 4 2
27 3 1
11 4 1
11 4 1
1 2 20
-3

Resources

2015 UESTC Training for Dynamic Programming