#DSU0000052. Phải tạo thành hình chữ nhật (Must Be Rectangular!)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 distinct points with integer coordinates in the plane. You may add new points using an axis-aligned rectangle rule.
Choose two distinct -coordinates and two distinct -coordinates . The points , , and 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 . Each of the following lines contains distinct positive integer coordinates .
Output
Print the maximum number of additional points.
Subtasks
- Subtask 1 (20 points): ; ; the coordinates are pairwise distinct.
- Subtask 2 (30 points): ; ; the coordinates are pairwise distinct.
- Subtask 3 (50 points): ; ; the coordinates are pairwise distinct.
Examples
Input
3
1 1
1 2
2 1
Output
1
Explanation
The existing three corners permit adding the fourth point .