Under construction

Still being built. Things may change

Secure Prison

Interview

Time limit2sMemory limit1024 MB

Summary
For each room type i, find the minimum cost to enlarge another type j so that a type i room fits inside it.
Level

Medium6 of 10

Topics
Sorting, Array, Implementation
Solved
No attempts yet

Problem

Eddie and Venom run into trouble when Carnage escapes from prison together with his host. If the prison had been more secure, nothing bad would have happened, and everyone would have lived happily ever after.

Learning from this, the new warden of San Quentin decided that the rebuilt prison will include a maximum security cell, a room placed inside another room. San Francisco law allows building rooms of exactly one of nn types. Type ii is a rectangle with side aia_i from west to east and side bib_i from north to south (and not the other way around).

Room ai×bia_i \times b_i can be placed inside room aj×bja_j \times b_j if and only if ai≤aja_i \le a_j and bi≤bjb_i \le b_j. For safety, the outer room and the inner room must be of different types (but they do not have to be different sizes).

Of course, not every pair of rooms fits one inside the other. For example, rooms of size 4×64 \times 6 and 5×35 \times 3 cannot be placed one inside the other, because 4<54 < 5 but 6>36 > 3. So if the warden wants the inner room to be of type ii and no other type, he is allowed to make an exception: he picks any type j≠ij \ne i and expands room aj×bja_j \times b_j to a×ba \times b (that is, picks any a≥aja \ge a_j and b≥bjb \ge b_j). He pays the city government (a+b)−(aj+bj)(a + b) - (a_j + b_j) money, so that a room of type ii fits inside it.

The warden wants to spend as little money as possible, but he does not want to risk safety. So before making the final choice, he wants to know the minimum amount he would have to pay the government if the inner room is of type ii, for each ii from 11 to nn.

Input

The first line contains a single integer nn, the number of room types officially allowed in San Francisco (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

Each of the next nn lines contains two space-separated integers aia_i and bib_i, the dimensions of room type ii (1≤ai,bi≤1091 \le a_i, b_i \le 10^9). The sizes of the types are not guaranteed to be distinct. If two types have the same dimensions, rooms of these types can be placed inside each other.

Output

Print nn integers separated by spaces. The ii-th integer is the minimum amount of money that must be paid to build a maximum security cell whose inner room is of type ii.

Examples2

  1. Example 1

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

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