Under construction

Still being built. Things may change

Rocky Mountain

Time limit3sMemory limit1024 MB

Summary
Given a mountain range as a polyline, find the lowest site on each side of the highest peak that a straight cable can reach without crossing the range.
Level

Medium6 of 10

Topics
Geometry, Stack
Solved
No attempts yet

Problem

The Rocky Mountain Cable (RMC) company plans to run cables from the top peak of the Rocky Mountains down to lower points in the range. Cable cars will carry tourists to the highest peak.

Each cable must run in a straight line from one of the candidate sites to the highest peak, and it cannot cross any part of the mountain range. However, the cable may coincide with a slope.

To serve the most tourists, the cable should go from the highest peak down to the lowest possible site. Find the best site on the left of the highest peak and the best site on the right. If there is a tie, choose the leftmost site on the left and the rightmost site on the right.

The mountain range is given by NN sites (xi,yi)(x_i, y_i). One of these sites is the unique highest peak (xp,yp)(x_p, y_p), where 1<p<N1 < p < N and yp>yiy_p > y_i for all i≠pi \neq p. The highest peak cannot be the first or the last site. The range is drawn by straight segments joining (xi,yi)(x_i, y_i) and (xi+1,yi+1)(x_{i+1}, y_{i+1}) for 1≤i<N1 \leq i < N, where xi<xi+1x_i < x_{i+1}.

Input

The first line contains an integer NN (3≤N≤5⋅1053 \leq N \leq 5 \cdot 10^5), the number of sites. Each of the next NN lines contains two integers xix_i and yiy_i, the coordinates of a site. The coordinates satisfy 0≤xi,yi≤1090 \leq x_i, y_i \leq 10^9. The input guarantees a unique highest peak and xi<xi+1x_i < x_{i+1} for all 1≤i<N1 \leq i < N.

Output

On the first line, print the coordinates of the best site to the left of the highest peak. On the second line, print the coordinates of the best site to the right of the highest peak.

Examples3

  1. Example 1

    Input
    5
    10 10
    20 20
    30 40
    40 30
    50 0
    
    Expected output
    10 10
    40 30
    
  2. Example 2

    Input
    5
    10 10
    20 20
    30 30
    40 20
    50 10
    
    Expected output
    10 10
    50 10
    
  3. Example 3

    Input
    10
    10 10
    20 35
    30 20
    40 40
    50 45
    60 40
    70 30
    80 40
    90 20
    1000 10
    
    Expected output
    20 35
    1000 10