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

#CT00049. Ghép đội (Team Matching)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ghép đội (Team Matching)

Team Matching

Version: Phuoc Hung OJ Extended

Problem Statement

There are two groups of students, AA and BB. Group AA has NN students with scores a1,a2,…,aNa_1,a_2,\ldots,a_N; group BB has MM students with scores b1,b2,…,bMb_1,b_2,\ldots,b_M.

A team consists of exactly one student from each group. A pair with scores ai,bja_i,b_j may be formed if ai≤bj≤ai+Ka_i\le b_j\le a_i+K. Each student may belong to at most one team.

Find the maximum number of teams.

Input

The first line contains N,M,KN,M,K.

The second line contains NN integers a1,a2,…,aNa_1,a_2,\ldots,a_N.

The third line contains MM integers b1,b2,…,bMb_1,b_2,\ldots,b_M.

Output

Print one integer: the maximum number of teams.

Subtasks

1≤ai,bj≤1091\le a_i,b_j\le10^9, 0≤K≤1090\le K\le10^9.

  • Subtask 1 (30 points): 1≤N,M≤121\le N,M\le12.
  • Subtask 2 (30 points): 1≤N,M≤20001\le N,M\le2000; both arrays are nondecreasing.
  • Subtask 3 (40 points): 1≤N,M≤2⋅1051\le N,M\le2\cdot10^5.

Examples

Example 1

Input

5 6 2
1 4 7 10 12
2 3 6 8 11 15

Output

4

Explanation

With K=2K=2, pair scores (1,2)(1,2), (4,6)(4,6), (7,8)(7,8), and (10,11)(10,11); the differences are 1,2,1,11,2,1,1. The remaining 1212 and 1515 differ by 3>23>2, yielding four teams.

Example 2

Input

4 4 0
1 2 2 5
2 2 3 5

Output

3

Explanation

With K=0K=0, paired scores must be equal. Two students with score 22 and one with score 55 can be paired, giving 2+1=32+1=3 teams. Scores 11 and 33 remain unmatched.

Example 3

Input

3 3 1
10 20 30
1 2 3

Output

0

Explanation

All group-AA scores are at least 1010, while all group-BB scores are at most 33. No pair can satisfy ai≤bja_i\le b_j, so the answer is zero.