QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB
[0]

# 9709. Interesting game

Statistics

Amy and Bob are good friends. Today they want to play a game.

Here is the process about it:

  1. There are n items in total. The ith item has ai points to Amy and bi points to Bob.
  2. Bob takes m items out of the game, so neither of them can pick these items. (0mn2)
  3. Amy picks one item first, assume she takes jth item, then she gets aj points.
  4. Bob picks one item, assume he takes kthitem, then he gets bk points.kj
  5. The game ends.

Now they are wondering what is the value of ajbk if they play optimally.

(Amy wants ajbk to be maximum, Bob wants ajbk to be minimum)

Please help them calculate the value when m is in [0,n2].

Input

The first line contains one integer,

n (1n3×105) ---

the number of items.

Each of the next n lines contains two integers,

ai and bi(1ai,bi109)---

meaning the ithitem has ai value to Amy and bi value to Bob.

Output

Output n1integers, each of them in one line.

The ithline is the value of ajbk when Bob bans exactly i1 items

(1in1)

Sample Input 1

5
2 2
3 2
4 4
5 6
6 6

Sample Output 1

0
0
0
0

Sample Input 2

3
4 100
5 98
1 100

Sample Output 2

-95
-96