Three Arrays

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

You are given three arrays: aa containing n_an\_a elements, bb containing n_bn\_b elements and cc containing n_cn\_c elements. These arrays are sorted in non-decreasing order: that is, for every ii such that 1i<n_a1 \le i < n\_a we have a_ia_i+1a\_i \le a\_{i + 1}, for every jj such that 1j<n_b1 \le j < n\_b we have b_jb_j+1b\_j \le b\_{j + 1}, and for every kk such that 1k<n_c1 \le k < n\_c we have c_kc_k+1c\_k \le c\_{k + 1}.

Your task is to calculate the number of triples (i,j,k)(i, j, k) such that a_ib_jd|a\_i - b\_j| \le d, a_ic_kd|a\_i - c\_k| \le d, and b_jc_kd|b\_j - c\_k| \le d.

입력

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: dd, n_an\_a, n_bn\_b, and n_cn\_c (1d1091 \le d \le 10^9, 1n_a,n_b,n_c51051 \le n\_a, n\_b, n\_c \le 5 \cdot 10^5).

The second line contains n_an\_a integers a_1,a_2,,a_n_aa\_1, a\_2, \ldots, a\_{n\_a}: the array aa (109a_i109-10^9 \le a\_i \le 10^9).

The third line contains n_bn\_b integers b_1,b_2,,b_n_bb\_1, b\_2, \ldots, b\_{n\_b}: the array bb (109b_i109-10^9 \le b\_i \le 10^9).

The fourth line contains n_cn\_c integers c_1,c_2,,c_n_cc\_1, c\_2, \ldots, c\_{n\_c}: the array cc (109c_i109-10^9 \le c\_i \le 10^9).

All arrays are sorted in non-decreasing order. The total sum of n_an\_a over all testcases does not exceed 51055 \cdot 10^5. The total sum of n_bn\_b over all testcases does not exceed 51055 \cdot 10^5. The total sum of all n_cn\_c over all testcases does not exceed 51055 \cdot 10^5. The test cases just follow one another without any special separators.

출력

For each test case, print a single integer: the number of triples (i,j,k)(i, j, k) such that a_ib_jd|a\_i - b\_j| \le d, a_ic_kd|a\_i - c\_k| \le d, and b_jc_kd|b\_j - c\_k| \le d.