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

#BS0000139. Giá trị khoảng cách giữa hai mảng (Find the Distance Value Between Two Arrays)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Giá trị khoảng cách giữa hai mảng (Find the Distance Value Between Two Arrays)

Find the Distance Value Between Two Arrays

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given integer arrays AA (length nn) and BB (length mm), and a nonnegative integer dd, an element AiA_i is considered far if ∣Ai−Bj∣>d|A_i-B_j|>d for every BjB_j. Count the positions of AA containing far elements. Equal elements at different positions count separately.

Input

The first line contains n,m,dn,m,d. The second line contains nn integers of AA, and the third line contains mm integers of BB.

Output

Print one integer, the number of far positions in AA.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 1≤m≤151\le m\le 15; 0≤d≤1000\le d\le 100; −1000≤Ai≤1000-1000\le A_i\le1000 for every 1≤i≤n1\le i\le n; −1000≤Bj≤1000-1000\le B_j\le1000 for every 1≤j≤m1\le j\le m.
  • Subtask 2 (30 points): 1≤n≤5001\le n\le 500; 1≤m≤5001\le m\le 500; 0≤d≤00\le d\le 0; −1000≤Ai≤1000-1000\le A_i\le1000 for every 1≤i≤n1\le i\le n; −1000≤Bj≤1000-1000\le B_j\le1000 for every 1≤j≤m1\le j\le m.
  • Subtask 3 (50 points): 1≤n≤5001\le n\le 500; 1≤m≤5001\le m\le 500; 0≤d≤1000\le d\le 100; −1000≤Ai≤1000-1000\le A_i\le1000 for every 1≤i≤n1\le i\le n; −1000≤Bj≤1000-1000\le B_j\le1000 for every 1≤j≤m1\le j\le m.

Examples

Input

3 4 2
4 5 8
10 9 1 8

Output

2

Explanation

For A1=4A_1=4, the nearest element of BB is 11 and the distance is 3>23>2. For A2=5A_2=5, the nearest is 88 with distance 3>23>2. For A3=8A_3=8, there is a value 88 in BB at distance 0≤20\le2. Thus two positions are far.