Under construction

Still being built. Things may change

Ćevapi

Time limit3sMemory limit128 MB

Summary
Each day a new raft joins; simulate Goran's run across both banks under L meters and report meters on each bank and the portions eaten.
Level

Medium5 of 10

Topics
Simulation, Sorting, Array
Solved
No attempts yet

Problem

Goran lives in a small town on a big river. The river can be drawn as a number line. Goran's house is at coordinate 00, and the river flows toward increasing coordinates. Call the bank Goran lives on bank A, and the far bank bank B.

Starting tomorrow, rafters go to work on the river. For a small fee each one carries people from one bank to the other and grills warm ćevapi for the passengers on the way. The first raft enters service tomorrow, the second one the day after, the third one three days from now, and so on. A raft that has entered service keeps running on every later day, so on day ii the first ii rafts are all in service.

Nobody works on a raft except the rafter, so a raft carries passengers in one direction only. On the way back the rafter grills for the next trip and takes no passengers. A raft that carries passengers from bank A to bank B runs in direction 1, and a raft that carries passengers from bank B to bank A runs in direction 2.

Goran's friends run along the river every evening to stay in shape, and Goran has found his own way to get fit: running with ćevapi.

Every day he starts at his house on bank A and runs exactly LL meters downstream along the river, and he never passes up warm ćevapi. Whenever he reaches the dock of a raft that carries passengers from the bank he is standing on to the far bank, he waits for the raft, boards it, and rests over one portion of ćevapi while it crosses. He gets off at the same coordinate on the other bank and runs on. A raft that carries passengers toward the bank he is already standing on is no help to him, so he runs past its dock. The distance he covers on the water does not count toward the LL meters he runs that day.

You are given the rafts in the order they enter service. For each raft you know the direction it runs in (1 or 2) and the distance of its dock from Goran's house. Write a program that finds, for each day, how many meters Goran runs on bank A, how many meters he runs on bank B, and how many portions of ćevapi he eats.

The pictures below show the three days of the first example in order.


On the first day Goran runs 500 meters on bank A and 100 meters on bank B, and eats 1 portion of ćevapi.


On the second day Goran runs 150 meters on bank A and 450 meters on bank B, and eats 1 portion of ćevapi.


On the third day Goran runs 350 meters on bank A and 250 meters on bank B, and eats 3 portions of ćevapi.

Input

The first line has two positive integers NN and LL, the number of days and the distance Goran has to run every day. (1≤N≤100 0001 \le N \le 100\,000, N<L<109N < L < 10^9)

Each of the next NN lines describes the raft that started running that day. The description has two positive integers SS and DD, the direction the raft runs in and the distance of its dock from Goran's house. (1≤S≤21 \le S \le 2, 0<D<L0 < D < L)

No two rafts have their docks at the same distance from Goran's house.

Output

For each of the NN days print three integers on one line, separated by single spaces: the meters run on bank A, the meters run on bank B, and the number of portions of ćevapi eaten that day.

Examples2

  1. Example 1

    Input
    3 600
    1 500
    1 150
    2 300
    
    Expected output
    500 100 1
    150 450 1
    350 250 3
    
  2. Example 2

    Input
    5 5000
    2 1000
    2 3000
    1 4000
    1 2000
    1 500
    
    Expected output
    5000 0 0
    5000 0 0
    4000 1000 1
    3000 2000 3
    2500 2500 5