Brownie Points II

Time limit1sMemory limit128 MB

Summary
Given points in the plane, Stan picks a vertical line and Ollie a horizontal line through it; find Stan's guaranteed score and the distinct best Ollie scores.
Level

Hard8 of 10

Topics
Sorting, Prefix sum, Greedy, Implementation
Solved
No attempts yet

Problem

Stan and Ollie play the game of Odd Brownie Points. Several brownie points lie in the plane at integer coordinates.

Stan moves first and draws a vertical line. This line must pass through at least one brownie point (that is, its xx-coordinate must equal the xx-coordinate of some point, and it may pass through several points that share that xx-coordinate at once). Ollie then draws a horizontal line, which must pass through one of the brownie points that already lie on Stan's vertical line.

The two lines split the plane into four quadrants. The quadrant containing points with arbitrarily large positive coordinates is the top-right quadrant. A brownie point lying exactly on either line is crossed and counts for no one.

  • Stan scores one point for every uncrossed brownie point in the top-right or bottom-left quadrant.
  • Ollie scores one point for every uncrossed brownie point in the top-left or bottom-right quadrant.

Each player tries to maximize his own score. Moving first, Stan anticipates Ollie's reply and chooses the vertical line that maximizes the smallest score he can be sure of.

Input

The input consists of several test cases. The first line of each test case contains an odd integer nn with 1<n<2000001 < n < 200000, the number of brownie points. Each of the next nn lines contains two integers xx and yy with −50000≤x,y≤50000-50000 \le x, y \le 50000, the coordinates of one brownie point. No two points share the same location. The input ends with a line containing a single 00.

Output

For each test case, print one line. First print the largest score Stan can guarantee for himself. Then, over all vertical lines that achieve this guaranteed score, print each distinct score Ollie can obtain with his best reply, in increasing order. The output format is exactly:

Stan: S; Ollie: o1 o2 ... ok;

Examples1

  1. Example 1

    Input
    11
    3 2
    3 3
    3 4
    3 6
    2 -2
    1 -3
    0 0
    -3 -3
    -3 -2
    -3 -4
    3 -7
    0
    
    Expected output
    Stan: 7; Ollie: 2 3;