All problems

Problem 576

Find the Distance Value Between Two Arrays

Easy · 10 pts · Array, Binary Search, Sorting

Problem

Given two arrays A and B and an integer D, the distance value is the number of elements x of A such that there is no element y of B with |x - y| <= D. In other words, count the elements of A that are far from every element of B. Sort B, and for each x binary search for the first element of B that is at least x - D; x counts if that element does not exist or is greater than x + D.

Input

The first line contains N, M and D. The second line contains A. The third line contains B.

Output

Print the distance value.

Constraints

1 <= N, M <= 100000; -1000 <= values <= 1000; 0 <= D <= 100

Example input

3 4 2
4 5 8
10 9 1 8

Example output

2

Explanation

With A = 4 5 8, B = 10 9 1 8 and D = 2: 4 is more than 2 away from every element of B, and so is 5, but 8 is within 2 of 10, 9 and 8. So the answer is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Maximum Distance Between a Pair of Values Next: Sliding Window Median