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

#CC0000047. Đếm cặp thỏa bất đẳng thức (Number of Pairs Satisfying Inequality)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm cặp thỏa bất đẳng thức (Number of Pairs Satisfying Inequality)

Number of Pairs Satisfying Inequality

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given arrays a,ba,b of equal length and integer diffdiff, count index pairs i<ji<j satisfying ai−aj≤bi−bj+diffa_i-a_j\le b_i-b_j+diff. Equality is accepted.

Input

First line: n,diffn,diff. Second line: nn values aia_i (nums1). Third line: nn values bib_i (nums2).

Output

Print the number of qualifying pairs.

Subtasks

  • Subtask 1 (20 points): 2≤n≤152\le n\le 15; −104≤ai,bi,diff≤104-10^4\le a_i,b_i,diff\le10^4.
  • Subtask 2 (30 points): 2≤n≤4202\le n\le 420; −104≤ai,bi,diff≤104-10^4\le a_i,b_i,diff\le10^4.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; −104≤ai,bi,diff≤104-10^4\le a_i,b_i,diff\le10^4.

Examples

Input

3 1
3 2 5
2 2 1

Output

3

Explanation

All three pairs (1,2), (1,3), and (2,3) satisfy the inequality for diff=1diff=1.