PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000052. Phải tạo thành hình chữ nhật (Must Be Rectangular!)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phải tạo thành hình chữ nhật (Must Be Rectangular!)

Must Be Rectangular!

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn distinct points with integer coordinates in the plane. You may add new points using an axis-aligned rectangle rule.

Choose two distinct xx-coordinates a,ca,c and two distinct yy-coordinates b,db,d. The points (a,b)(a,b), (a,d)(a,d), (c,b)(c,b) and (c,d)(c,d) form the four corners of an axis-aligned rectangle. If three corners are already occupied and the fourth is not, you may add the missing point. Newly added points may be used in subsequent operations. No point may be moved or removed.

After any finite number of such additions, determine the maximum number of new points that can be created. Do not count points present initially.

Input

The first line contains nn. Each of the following nn lines contains distinct positive integer coordinates xi,yix_i,y_i.

Output

Print the maximum number of additional points.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12; 1≤xi,yi≤1051\le x_i,y_i\le10^5; the coordinates (xi,yi)(x_i,y_i) are pairwise distinct.
  • Subtask 2 (30 points): 1≤n≤5001\le n\le500; 1≤xi,yi≤1051\le x_i,y_i\le10^5; the coordinates (xi,yi)(x_i,y_i) are pairwise distinct.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤xi,yi≤1051\le x_i,y_i\le10^5; the coordinates (xi,yi)(x_i,y_i) are pairwise distinct.

Examples

Input

3
1 1
1 2
2 1

Output

1

Explanation

The existing three corners permit adding the fourth point (2,2)(2,2).