Under construction

Still being built. Things may change

Efficient Evaluation

Time limit2sMemory limit1024 MB

Summary
Given a queue of m tests and n moves that each remove every other test in a position range, report the smallest and largest original index removed per move.
Level

Hard8 of 10

Topics
Segment tree, Simulation, Implementation
Solved
No attempts yet

Statement

Starting from year 20xx, the organizers of all Olympiads in informatics for high school students decided to hold their competitions online. An Organization of Online Olympiads (OOO) was created to monitor that nobody proposes an onsite competition. Such an organization needs its own contest management system. Efficient managers have already been hired, and sticks and blue tape have been bought.

To speed up solution evaluation, a new architecture was introduced. Initially, there are mm tests in the testing queue, in order from test 1 to test mm. The scheduling module performs nn moves in sequence. On the ii-th move, it picks the segment of queue positions from lil_i to rir_i inclusive and runs the solution on the tests at positions li,li+2,li+4,…,ril_i, l_i + 2, l_i + 4, \ldots, r_i (lil_i and rir_i have the same parity). After that, all tests the solution ran on are removed from the queue, and the remaining tests shift so that no gaps remain. For example, if the queue holds tests with initial indices 2, 3, 4, 5, 10, 12, 13, 20 and the move is li=3l_i = 3, ri=7r_i = 7, the solution runs on the tests at positions 3, 5, and 7, which have initial indices 4, 10, and 13. Afterward the queue looks like 2, 3, 5, 12, 20.

Your goal is to implement the part of this module that, for each of the nn moves, finds the minimum and maximum initial index of the tests the solution ran on.

Input

The first line contains two integers nn and mm (1≤n≤100 0001 \leq n \leq 100\,000, 1≤m≤10181 \leq m \leq 10^{18}), the number of moves and the number of tests initially in the queue.

Each of the following nn lines contains two integers lil_i and rir_i (1≤li≤ri≤m1 \leq l_i \leq r_i \leq m), the parameters of the ii-th move. It is guaranteed that before the ii-th move there are at least rir_i tests in the queue, and that lil_i and rir_i have the same parity.

Output

For each of the nn moves, print two integers on one line: the minimum and the maximum initial index of the test that the solution ran on (and that was then removed) during that move.

Hint

Consider the first sample. 1. Initially, all tests from 1 to 10 are in the queue: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. 2. During the first move, tests 2, 4, 6, and 8 are removed. The queue becomes 1, 3, 5, 7, 9, 10. 3. During the second move, tests 1 and 5 are removed, and the queue becomes 3, 7, 9, 10.

Examples2

  1. Example 1

    Input
    2 10
    2 8
    1 3
    
    Expected output
    2 8
    1 5
    
  2. Example 2

    Input
    4 6
    1 1
    1 1
    1 1
    2 2
    
    Expected output
    1 1
    2 2
    3 3
    5 5