#d2496. 魔法阵传送

魔法阵传送

Magic Array Teleport

Problem Description

There are NN integer points (both coordinates are integers) on the plane, called "magic arrays".

A teleport works as follows:

  1. You start from some magic array.
  2. You may choose a magic (A,B)(A, B), where A,BA, B are integers. Applying this magic once to any integer point (X,Y)(X, Y) moves it to (X+A,Y+B)(X + A, Y + B).
  3. Throughout the whole teleport from the starting magic array to the next magic array, you may use only one kind of magic, but you may use it any number of times.

Find the minimum number of magics you must master so that, starting from any magic array, you can directly teleport to any other magic array without passing through another magic array in between.

Input Format

The first line contains an integer NN.

The next NN lines each contain two integers Xi,YiX_i, Y_i, the coordinates of the ii-th magic array.

Output Format

Output one integer: the answer.

Sample Input 1

3
1 1
4 5
1 4

Sample Output 1

6

Sample Explanation

The directions that need to be covered are: from (1,1)(1,1) to (4,5)(4,5) and (1,4)(1,4); from (4,5)(4,5) to (1,1)(1,1) and (1,4)(1,4); from (1,4)(1,4) to (1,1)(1,1) and (4,5)(4,5).

Note that you cannot reach (4,5)(4,5) from (1,1)(1,1) by combining (0,3)+(3,1)(0,3) + (3,1), because a single teleport may use only one kind of magic.

Of course, you may also learn the magic (0,1)(0,1), in which case going from (1,1)(1,1) to (1,4)(1,4) requires using this magic 33 times.

Sample Input 2

3
1 1
2 2
1000000000 1000000000

Sample Output 2

2

Constraints

  • 10≤N≤50010 \le N \le 500
  • 0≤Xi,Yi≤1090 \le X_i, Y_i \le 10^9, and all coordinates are pairwise distinct.