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

#PS0000213. Đồng cỏ hình chữ nhật (Rectangular Pasture)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đồng cỏ hình chữ nhật (Rectangular Pasture)

Rectangular Pasture

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cows at integer grid cells (xi,yi)(x_i,y_i). All x-coordinates are distinct, and all y-coordinates are distinct. A rectangular region of cells with sides parallel to the axes encloses a subset of cows, including cows in boundary cells. Count the distinct subsets that can be enclosed. Different rectangles enclosing the same cows count only once. Include the empty subset.

Input

The first line contains NN. Each of the next NN lines contains two integers xi,yix_i,y_i.

Output

Print the number of distinct subsets, including the empty subset. The result fits in a signed 64-bit integer.

Subtasks

  • Subtask 1 (10 points): 1≤N≤201\le N\le 20; 0≤xi,yi≤1090\le x_i,y_i\le10^9; all x-coordinates are distinct and all y-coordinates are distinct.
  • Subtask 2 (15 points): 1≤N≤1001\le N\le 100; 0≤xi,yi≤1090\le x_i,y_i\le10^9; all x-coordinates are distinct and all y-coordinates are distinct.
  • Subtask 3 (30 points): 1≤N≤5001\le N\le 500; 0≤xi,yi≤1090\le x_i,y_i\le10^9; all x-coordinates are distinct and all y-coordinates are distinct.
  • Subtask 4 (45 points): 1≤N≤25001\le N\le 2500; 0≤xi,yi≤1090\le x_i,y_i\le10^9; all x-coordinates are distinct and all y-coordinates are distinct.

Example 1

Input

4
0 2
1 0
2 3
3 5

Output

13

Explanation

Of the 16 subsets, {1,2,4}, {2,4}, and {1,4} cannot be isolated: their bounding rectangles also contain cow 3. The other 13 are feasible.

Example 2

Input

3
10 10
30 30
20 20

Output

7

Explanation

In x-order, every feasible nonempty subset is contiguous. There are 3 singletons, 2 pairs, 1 triple, and the empty subset.