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

#TP0000020. Phân căn hộ (Apartments)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Phân căn hộ (Apartments)

Apartments

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn applicants looking for apartments and mm available apartments. Applicant ii wants an apartment of size aia_i and accepts a difference of at most kk from that size. Apartment jj has size bjb_j.

Each apartment can be assigned to at most one applicant, and each applicant may receive at most one apartment. An assignment is valid if ∣ai−bj∣≤k|a_i-b_j|\le k. Find the maximum number of applicants who can receive apartments.

Input

  • The first line contains three integers n,m,kn,m,k: the numbers of applicants and apartments, and the maximum allowed size difference.
  • The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, the desired apartment sizes.
  • The third line contains mm integers b1,b2,…,bmb_1,b_2,\ldots,b_m, the available apartment sizes.

Output

Print one integer: the maximum number of applicants who can receive an apartment.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le 8; 0≤k≤1090\le k\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.
  • Subtask 2 (30 points): 1≤n,m≤18001\le n,m\le 1800; 0≤k≤1090\le k\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.
  • Subtask 3 (50 points): 1≤n,m≤2000001\le n,m\le 200000; 0≤k≤1090\le k\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for every element.

Examples

Input

4 3 5
60 45 80 60
30 60 75

Output

2

Explanation

An apartment of size 6060 can be assigned to one applicant requesting 6060, and the apartment of size 7575 to the applicant requesting 8080, since ∣80−75∣=5|80-75|=5. The apartment of size 3030 cannot serve the applicant requesting 4545 because their difference is 1515. At most two apartments can be assigned validly, so the answer is 22.