Under construction

Still being built. Things may change

Convex Polygons

Time limit1sMemory limit1024 MB

Summary
Find the longest contiguous run of points that forms a convex polygon in counterclockwise order, and report its length.
Level

Medium7 of 10

Topics
Array, Two pointers, Geometry
Solved
No attempts yet

Problem

A set of NN points P1,P2,…,PNP_1, P_2, \ldots, P_N is given on the 2D coordinate plane. Find the maximum value of r−l+1r - l + 1 over all integers ll and rr that satisfy the following conditions.

  • 1≤l<r≤N1 \le l < r \le N, and r−l+1≥3r - l + 1 \ge 3.
  • Pl,Pl+1,…,PrP_l, P_{l+1}, \ldots, P_r form a convex polygon in counterclockwise order. Every interior angle is less than 180 degrees.

Input

The first line contains the number of points NN. (3≤N≤3000003 \le N \le 300000)

Each of the next NN lines contains two integers xix_i and yiy_i, the x and y coordinates of the ii-th point. (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9)

All given points are distinct.

Output

Print the maximum value of r−l+1r - l + 1 over all pairs ll and rr that satisfy the conditions. If no such pair exists, print −1-1.

Hint

A convex polygon is a simple polygon (one that does not cross itself) where every segment joining two points on its boundary stays inside the polygon.

Examples2

  1. Example 1

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

    Input
    5
    3 1
    4 2
    5 9
    6 2
    7 4
    
    Expected output
    3