CF BUDDY
← Problems·

1248A · Integer Points

1000 · geometry, math

Problem: DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew nn distinct lines, given by equations y=x+piy = x + p_i for some distinct p1,p2,,pnp_1, p_2, \ldots, p_n.

Then JLS drew on the same paper sheet mm distinct lines given by equations y=x+qiy = -x + q_i for some distinct q1,q2,,qmq_1, q_2, \ldots, q_m.

DLS and JLS are interested in counting how many line pairs have integer intersection points, i.e. points with both coordinates that are integers. Unfortunately, the lesson will end up soon, so DLS and JLS are asking for your help.

Input Format: The first line contains one integer tt (1t10001 \le t \le 1000), the number of test cases in the input. Then follow the test case descriptions.

The first line of a test case contains an integer nn (1n1051 \le n \le 10^5), the number of lines drawn by DLS.

The second line of a test case contains nn distinct integers pip_i (0pi1090 \le p_i \le 10^9) describing the lines drawn by DLS. The integer pip_i describes a line given by the equation y=x+piy = x + p_i.

The third line of a test case contains an integer mm (1m1051 \le m \le 10^5), the number of lines drawn by JLS.

The fourth line of a test case contains mm distinct integers qiq_i (0qi1090 \le q_i \le 10^9) describing the lines drawn by JLS. The integer qiq_i describes a line given by the equation y=x+qiy = -x + q_i.

The sum of the values of nn over all test cases in the input does not exceed 10510^5. Similarly, the sum of the values of mm over all test cases in the input does not exceed 10510^5.

In hacks it is allowed to use only one test case in the input, so t=1t=1 should be satisfied.

Output Format: For each test case in the input print a single integer — the number of line pairs with integer intersection points.

Note: The picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates.

Sample Cases

Case 1

Input

3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1

Output

3
1
0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback