405011: GYM101741 A Three Arrays

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Three Arraystime limit per test2 secondsmemory limit per test256 mebibytesinputstandard inputoutputstandard output

You are given three arrays: a containing na elements, b containing nb elements and c containing nc elements. These arrays are sorted in non-decreasing order: that is, for every i such that 1 ≤ i < na we have ai ≤ ai + 1, for every j such that 1 ≤ j < nb we have bj ≤ bj + 1, and for every k such that 1 ≤ k < nc we have ck ≤ ck + 1.

Your task is to calculate the number of triples (i, j, k) such that |ai - bj| ≤ d, |ai - ck| ≤ d, and |bj - ck| ≤ d.

Input

The input contains one or more test cases. Each test case consists of four lines.

The first line of each test case contains four integers: d, na, nb, and nc (1 ≤ d ≤ 109, 1 ≤ na, nb, nc ≤ 5·105).

The second line contains na integers a1, a2, ..., ana: the array a ( - 109 ≤ ai ≤ 109).

The third line contains nb integers b1, b2, ..., bnb: the array b ( - 109 ≤ bi ≤ 109).

The fourth line contains nc integers c1, c2, ..., cnc: the array c ( - 109 ≤ ci ≤ 109).

All arrays are sorted in non-decreasing order. The total sum of na over all testcases does not exceed 5·105. The total sum of nb over all testcases does not exceed 5·105. The total sum of all nc over all testcases does not exceed 5·105. The test cases just follow one another without any special separators.

Output

For each test case, print a single integer: the number of triples (i, j, k) such that |ai - bj| ≤ d, |ai - ck| ≤ d, and |bj - ck| ≤ d.

ExampleInput
1 3 3 3
1 2 3
1 2 3
1 2 3
1 6 6 6
1 1 2 2 3 3
2 2 3 3 4 4
3 3 4 4 5 5
Output
15
56

加入题单

算法标签: