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

#FT0000159. Ada và các giống rau (Ada and Species)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ada và các giống rau (Ada and Species)

Ada and Species

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Ada has nn vegetable species, each with four attributes Xi,Yi,Zi,WiX_i,Y_i,Z_i,W_i; smaller values are better. Species ii is worse than species jj exactly when all four attributes of ii are strictly larger: Xj<XiX_j<X_i, Yj<YiY_j<Y_i, Zj<ZiZ_j<Z_i, and Wj<WiW_j<W_i. Ada removes any species that is worse than at least one other species. Count how many remain. Each attribute column is independently a permutation of 1,2,…,n1,2,\ldots,n, so all strict inequalities have no ties.

Input

The first line contains nn. Each of the next nn lines gives the four attributes Xi,Yi,Zi,WiX_i,Y_i,Z_i,W_i of a species.

Output

Print one integer: the number of species that are not removed.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le 10; Each coordinate lies in [1,n][1,n], and each of the four coordinate columns X,Y,Z,WX,Y,Z,W is separately a permutation of 1,2,…,n1,2,\ldots,n (no ties).
  • Subtask 2 (30 points): 1≤n≤25001\le n\le 2500; Each coordinate lies in [1,n][1,n], and each of the four coordinate columns X,Y,Z,WX,Y,Z,W is separately a permutation of 1,2,…,n1,2,\ldots,n (no ties).
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; Each coordinate lies in [1,n][1,n], and each of the four coordinate columns X,Y,Z,WX,Y,Z,W is separately a permutation of 1,2,…,n1,2,\ldots,n (no ties).

Examples

Example 1

Input

3
1 1 1 1
2 2 2 2
3 3 3 3

Output

1

Explanation

The first species has smaller values in all four attributes than species 2 and 3, so both are removed; the first remains. Answer: 1.

Example 2

Input

4
1 4 1 4
2 3 2 3
3 2 3 2
4 1 4 1

Output

4

Explanation

Whenever one species has a smaller XX, it has a larger YY. Thus no species is strictly better than another in all four attributes, and all four remain.