This page is still under construction.

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

Make an X

Time limit1sMemory limit1024 MB

Level

Not classified yet

Solved
No attempts yet

Problem

NN thumbtacks are stuck on a board. Each thumbtack is a very small point, and the board is modeled as an infinite coordinate plane. Phoenix, who likes the letter X, wants to remove some of the thumbtacks so that the remaining ones form an X shape. An X shape is defined as follows.

  • There is a center thumbtack PP that satisfies the following conditions.
  • No other thumbtack shares an xx coordinate or a yy coordinate with PP.
  • Treat PP as the origin. In each quadrant, no two thumbtacks share an xx coordinate or a yy coordinate, and each quadrant contains at least one thumbtack.
  • Treat PP as the origin. Sort the thumbtacks in the first and third quadrants by xx coordinate. Their yy coordinates increase in that order.
  • Treat PP as the origin. Sort the thumbtacks in the second and fourth quadrants by xx coordinate. Their yy coordinates decrease in that order.

Given the positions of the thumbtacks, find the minimum number of thumbtacks that must be removed so that the remaining thumbtacks form an X shape.

Input

The first line contains NN, the number of thumbtacks. (1≤N≤3 000)(1 \le N \le 3\,000)

The next NN lines contain the position xix_i, yiy_i of the ii-th thumbtack. (−109≤xi,yi≤109)(-10^9 \le x_i, y_i \le 10^9)

All coordinates are integers, and no two thumbtacks share the same coordinates.

Output

Print the minimum number of thumbtacks to remove so that the remaining thumbtacks form an X shape. If the thumbtacks cannot form an X shape, print -1.

Examples2

  1. Example 1

    Input
    9
    1 1
    1 0
    1 -1
    0 1
    0 0
    0 -1
    -1 1
    -1 0
    -1 -1
    
    Expected output
    4
    
  2. Example 2

    Input
    5
    0 0
    1 0
    2 0
    -1 0
    -2 0
    
    Expected output
    -1