#icpc2015summerday4i. [icpc2015summer_day4_i]Live Programming

[icpc2015summer_day4_i]Live Programming

MathJax.Hub.Config({ tex2jax: { inlineMath: [["","",""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }

Problem Statement

A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have NN different songs, mathitsong_1\\mathit{song}\_1, mathitsong_2\\mathit{song}\_2, ..., and mathitsong_N\\mathit{song}\_N. Each song has three integer parameters, t_it\_i, p_ip\_i, and f_if\_i: t_it\_i denotes the length of mathitsong_i\\mathit{song}\_i, p_ip\_i denotes the basic satisfaction points the audience will get when mathitsong_i\\mathit{song}\_i is performed, and f_if\_i denotes the feature value of mathitsong_i\\mathit{song}\_i that affects the audience's satisfaction. During the live performance, JAG48 can perform any number (but at least one) of the NN songs, unless the total length of the chosen songs exceeds the length of the live performance TT. They can decide the order of the songs to perform, but they cannot perform the same song twice or more.

The goal of this live performance is to maximize the total satisfaction points that the audience will get. In addition to the basic satisfaction points of each song, the difference between the feature values of the two songs that are performed consecutively affects the total satisfaction points. If there is no difference, the audience will feel comfortable. However, the larger the difference will be, the more frustrated the audience will be.

Thus, the total satisfaction points will be calculated as follows:

  • If mathitsong_x\\mathit{song}\_x is the first song of the live performance, the total satisfaction points just after mathitsong_x\\mathit{song}\_x is equal to p_xp\_x.
  • If mathitsong_x\\mathit{song}\_x is the second or subsequent song of the live performance and is performed just after mathitsong_y\\mathit{song}\_y, p_x(f_xf_y)2p\_x - (f\_x - f\_y)^2 is added to the total satisfaction points, because the audience will get frustrated if f_xf\_x and f_yf\_y are different.

Help JAG48 find a program with the maximum total satisfaction points.


Input

The input is formatted as follows.

NN TT
t_1t\_1 p_1p\_1 f_1f\_1
ldots\\ldots
t_Nt\_N p_Np\_N f_Nf\_N

The first line contains two integers NN and TT: the number of the available songs NN (1leNle4,0001 \\le N \\le 4{,}000), and the length of the live performance TT (1leTle4,0001 \\le T \\le 4{,}000).

The following NN lines represent the parameters of the songs. The ii-th line of them contains three integers, which are the parameters of mathitsong_i\\mathit{song}\_i: the length t_it\_i (1let_ile4,0001 \\le t\_i \\le 4{,}000), the basic satisfaction points p_ip\_i (1lep_ile1081 \\le p\_i \\le 10^8), and the feature value f_if\_i (1lef_ile1041 \\le f\_i \\le 10^4).

You can assume that there is at least one song whose length is less than or equal to TT.

Output

Output the maximum total satisfaction points that the audience can get during the live performance.


Sample Input 1

2 10
10 200 1
10 100 100```

### Output for the Sample Input 1

```plain
200```

* * *

### Sample Input 2

```plain
3 15
5 100 1
5 100 2
5 100 4```

### Output for the Sample Input 2

```plain
295```

* * *

### Sample Input 3

```plain
3 10
5 200 200
5 200 201
5 300 1```

### Output for the Sample Input 3

```plain
399```

* * *

### Sample Input 4

```plain
3 20
5 100 200
5 100 201
5 300 1```

### Output for the Sample Input 4

```plain
300```

* * *

### Sample Input 5

```plain
5 61
14 49 7
31 46 4
30 55 5
52 99 1
34 70 3```

### Output for the Sample Input 5

```plain
103```

* * *