Between Two Cameras

In a rectangular room there are NN sleeping cats. Each cat has a position on the floor and a weight. They do not move.

Two cameras are located at adjacent corners of the room. Each camera starts pointing toward the other camera and turns 90∘90^\circ toward the interior of the room. As it turns, it records each cat when it points directly at that cat. Each camera then creates a panoramic image showing the cats in the order it recorded them.

A control system compares the two panoramas. A pair of distinct cats {A,B}\{A,B\} is flagged if AA appears before BB in one panorama and after BB in the other. Each flagged pair needs manual review, at a cost equal to the product of the weights of those two cats.

Given the positions and weights of the cats, you must find the sum of the costs of all flagged pairs.

Input

The first line contains two integers NN (2≤N≤2×1052 \le N \le 2 \times 10^{5}) and DD (2≤D≤1092 \le D \le 10^{9}), indicating respectively the number of cats and the distance between the two cameras.

The floor is represented in the plane, with the cameras located at (0,0)(0,0) and (D,0)(D,0). The interior of the room is on the side where the second coordinate is positive.

Each of the next NN lines describes a cat with three integers XX (1≤X≤D−11 \le X \le D-1), YY (1≤Y≤1091 \le Y \le 10^{9}) and WW (1≤W≤1041 \le W \le 10^{4}), where (X,Y)(X,Y) is the position of the cat and WW is its weight.

It is guaranteed that neither camera ever points directly at two cats at once.

Output

Output a single line with an integer indicating the sum of the costs of all flagged pairs.

Examples

Input

3 10
5 2 3
5 3 4
5 1 2

Output

0

Input

3 10
5 3 2
8 3 3
2 3 1

Output

11

Input

5 12
6 5 5
2 6 2
10 7 1
4 2 3
8 3 4

Output

37

Explanation

For the configuration shown in the figure below, the flagged pairs are {5, 4}, {5, 2}, {3, 1}, {3, 2} and {1, 2}, whose costs sum to 4 ⋅ 3 + 4 ⋅ 2 + 1 ⋅ 5 + 1 ⋅ 2 + 5 ⋅ 2 = 37.