Under construction

Still being built. Things may change

Secure Prison (Basic)

Interview

Time limit2sMemory limit1024 MB

Summary
Given n room types where none fits inside another, for each type i find the least cost of enlarging some other type j so that type i fits inside it.
Level

Medium6 of 10

Topics
Sorting, Binary search, Segment tree
Solved
No attempts yet

Problem

Eddie and Venom's troubles begin 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 experience, the new warden of San Quentin decided that the restored prison will include a maximum security cell, a room placed inside another room. San Francisco law allows rooms of exactly one of nn types. The ii-th type is a rectangle with side aia_i from west to east and side bib_i from north to south (but not the other way around). A room ai×bia_i \times b_i can be placed inside a room aj×bja_j \times b_j if and only if ai⩽aja_i \leqslant a_j and bi⩽bjb_i \leqslant b_j. For safety, the outer and inner rooms must be of different types.

Unfortunately, none of the allowed room types fits inside another. For example, no two rooms of sizes 4×64 \times 6, 5×35 \times 3, and 7×17 \times 1 can be placed one inside the other. So the warden may choose any type ii for the inner room and bend the rules a little for the outer room. He may choose any type j≠ij \neq i for the outer room and expand the aj×bja_j \times b_j room to a×ba \times b (that is, choose any a⩾aja \geqslant a_j, b⩾bjb \geqslant b_j), paying the city government (a+b)−(aj+bj)(a + b) - (a_j + b_j) money, so that the room of type ii fits inside it.

The warden wants to spend as little money as possible without risking safety. So before making the final choice, he wants to know the minimum amount he must pay the government for each ii from 11 to nn, if the inner room is of type ii.

Input

The first line contains a single integer nn, the number of room types officially allowed in San Francisco (2⩽n⩽2⋅1052 \leqslant n \leqslant 2 \cdot 10^5). The ii-th of the next nn lines contains integers aia_i and bib_i separated by a space, the dimensions of the ii-th room type (1⩽ai,bi⩽1091 \leqslant a_i, b_i \leqslant 10^9). It is guaranteed that no two different room types can be placed one inside the other.

Output

Print nn integers separated by spaces. The ii-th integer is the minimum amount of money needed to build a maximum security cell with the inner room 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
    2 5
    7 2
    1 10
    
    Expected output
    1 1 1 1 5