Under construction

Still being built. Things may change

One-dimensional Game

Interview

Time limit2sMemory limit1024 MB

Summary
Given n distinct segments, count for each segment the downward move paths in its containment tree, modulo 1e9+7.
Level

Medium5 of 10

Topics
Sorting, Tree, Dynamic programming
Solved
No attempts yet

Statement

Bogdan is playing a game. The game is one-dimensional. There are nn platforms located on the horizontal line. Bogdan can move between platforms. The ii-th platform is a horizontal segment [li,ri][l_i, r_i]. All segments are distinct.

Let's say that the platform jj is inside the platform ii if li≤ljl_i \le l_j and rj≤rir_j \le r_i.

At the beginning of the game, Bogdan chooses the platform from which he will start his journey. Moving between platforms is dangerous and Bogdan tries to stay away from the danger, so he can move from the platform ii to the platform jj only if the platform jj is inside the platform ii and there is no other platform kk which is inside the platform ii and the platform jj is inside the platform kk.

For each platform, Bogdan wants to know how many different paths he can take, starting from this platform and ending on any other. Two paths are different if there is a platform which is in one of the paths but not in the other one.

Help Bogdan count the number of paths from each platform. Since the number of paths can be very large, find it modulo 109+710^9 + 7.

Input

The first line contains the only integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5), the number of platforms.

The next nn lines contain the platforms' data. The ii-th of these lines contains two integers lil_i and rir_i (1≤li≤ri≤1091 \le l_i \le r_i \le 10^9), the ends of the ii-th segment of the platform.

Output

Print nn integers. The ii-th integer must be equal to the number of different paths from the platform ii, modulo 109+710^9 + 7.

Examples2

  1. Example 1

    Input
    5
    1 5
    1 4
    1 3
    1 2
    1 1
    
    Expected output
    5 4 3 2 1
    
  2. Example 2

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