Make an X
Time limit1sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
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 that satisfies the following conditions.
- No other thumbtack shares an coordinate or a coordinate with .
- Treat as the origin. In each quadrant, no two thumbtacks share an coordinate or a coordinate, and each quadrant contains at least one thumbtack.
- Treat as the origin. Sort the thumbtacks in the first and third quadrants by coordinate. Their coordinates increase in that order.
- Treat as the origin. Sort the thumbtacks in the second and fourth quadrants by coordinate. Their 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 , the number of thumbtacks.
The next lines contain the position , of the -th thumbtack.
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.