This page is still under construction.

Parts of this page are still being built. What you see may change.

Flat Broken Lines

Time limit1sMemory limit128 MB

Summary
Given n points, find the minimum number of flat broken lines (each moving right with segment slopes between -1 and 1) needed to cover all points.
Level

Hard8 of 10

Topics
Greedy, Sorting, Geometry
Solved
No attempts yet

Problem

Imagine a Cartesian coordinate system drawn on a sheet of paper. Consider broken lines (polylines) that can be drawn with a single pencil stroke from the left edge of the sheet to the right edge. We additionally require that, for every segment of such a line, the angle between the straight line containing that segment and the OXOX axis lies in the range [−45∘,45∘][-45^\circ, 45^\circ]. A broken line that satisfies these conditions is called a flat broken line.

Equivalently, a flat broken line always moves to the right, and every one of its segments has slope between −1-1 and 11.

You are given nn distinct points with integer coordinates. Determine the minimal number of flat broken lines needed to cover all of the points. A point is covered by a line if it lies on that line.

Flat broken lines covering six points

For example, the six points (1,6)(1, 6), (10,8)(10, 8), (1,5)(1, 5), (2,20)(2, 20), (4,4)(4, 4), (6,2)(6, 2) can be covered by a minimum of 33 flat broken lines.

Write a program that reads the number of points and their coordinates from standard input, computes the minimal number of flat broken lines needed to cover all the points, and writes that number to standard output.

Input

The first line contains one positive integer nn (1≤n≤300001 \le n \le 30000), the number of points. Each of the next nn lines contains two integers xx and yy (0≤x≤300000 \le x \le 30000, 0≤y≤300000 \le y \le 30000) separated by a single space, the coordinates of one point. All points are distinct.

Output

Print a single integer: the minimal number of flat broken lines needed to cover all the points.

Examples3

  1. Example 1

    Input
    6
    1 6
    10 8
    1 5
    2 20
    4 4
    6 2
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    0 0
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    5 1
    5 2
    5 3
    
    Expected output
    3