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

#CC0000060. So sánh ba chỉ số tại buổi dạ hội (Ball)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

So sánh ba chỉ số tại buổi dạ hội (Ball)

Ball

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Each of the nn people has three attributes: beauty BiB_i, intellect IiI_i, and richness RiR_i. Count the people for whom there exists another person with all three attributes strictly greater.

Input

The first line contains nn. The next three lines contain beauty BiB_i, intellect IiI_i and richness RiR_i respectively.

Output

Print the number of people strictly dominated on all three attributes.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 0≤Bi,Ii,Ri≤1090\le B_i,I_i,R_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; 0≤Bi,Ii,Ri≤1090\le B_i,I_i,R_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤5000001\le n\le500000; 0≤Bi,Ii,Ri≤1090\le B_i,I_i,R_i\le10^9.

Examples

Input

3
1 4 2
4 3 2
2 5 3

Output

1

Explanation

Person 2 (4,3,5) strictly dominates person 3 (2,2,3). Neither of the others is dominated in all three dimensions.