Under construction

Still being built. Things may change

Triangle Containment

Time limit4sMemory limit1024 MB

Summary
For each treasure point, sum the values of the other points strictly inside the triangle it forms with the barn wall endpoints (0,0) and (x,0).
Level

Medium7 of 10

Topics
Geometry, Sorting, Segment tree
Solved
No attempts yet

Problem

You recently discovered there is treasure buried on your farm land. A lot of treasure! You quickly decide to put a fence around the land.

Alas, you have but a single fence post! You will have to drive to town to get more fencing material. But you can't leave the land as open as it is, so you decide to build a makeshift fence to protect some of the treasure while you are gone. You will place the post in the ground and run wire in a straight line from the post to each of two sides of your barn wall, which encloses a triangular area. The ground is very hard: only places that were dug up to bury treasure are soft enough for you to place the fence post quickly.

To figure out the best option, you first calculate the following. For each treasure in your field, suppose you place the fence post at that treasure and complete the fence as described. What is the total value of all treasures enclosed by the fence? The treasure under the post is not considered enclosed, since someone could dig around the post and reach it.

Input

The first line contains two integers nn (1≤n≤1051 \le n \le 10^5) and xx (1≤x≤1091 \le x \le 10^9), where nn is the number of treasure points and xx places the two corners of the barn wall at (0,0)(0,0) and (x,0)(x,0).

Each of the next nn lines contains three integers xx, yy, and vv (−109≤x≤109-10^9 \le x \le 10^9, 1≤y≤1091 \le y \le 10^9, 1≤v≤1091 \le v \le 10^9), giving the location (x,y)(x,y) and value vv of one treasure point. All points are distinct. For each point, the triangle formed with the barn wall does not contain any other treasure point on its boundary.

Output

Output nn lines, one for each treasure point in input order. For each point, output a single integer: the total value of all points in the interior of the triangle that the point forms with the barn wall. The value of the point itself is excluded from this sum.

Examples2

  1. Example 1

    Input
    5 8
    -8 1 1
    -1 10 2
    0 3 4
    7 1 8
    8 2 16
    
    Expected output
    0
    12
    0
    0
    8
    
  2. Example 2

    Input
    6 6
    0 1 1
    2 3 10
    2 5 100
    3 1 1000
    3 5 10000
    4 5 100000
    
    Expected output
    0
    1000
    1010
    0
    1010
    1000