Integer Points (Codeforces 1248A)
Tags: Math, geometry

DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew $$$n$$$ distinct lines, given by equations $$$y = x + p_i$$$ for some distinct $$$p_1, p_2, \ldots, p_n$$$.Then JLS drew on the same paper sheet $$$m$$$ distinct lines given by equations $$$y = -x + q_i$$$ for some distinct $$$q_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: The first line contains one integer $$$t$$$ ($$$1 \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 $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of lines drawn by DLS.The second line of a test case contains $$$n$$$ distinct integers $$$p_i$$$ ($$$0 \le p_i \le 10^9$$$) describing the lines drawn by DLS. The integer $$$p_i$$$ describes a line given by the equation $$$y = x + p_i$$$.The third line of a test case contains an integer $$$m$$$ ($$$1 \le m \le 10^5$$$), the number of lines drawn by JLS.The fourth line of a test case contains $$$m$$$ distinct integers $$$q_i$$$ ($$$0 \le q_i \le 10^9$$$) describing the lines drawn by JLS. The integer $$$q_i$$$ describes a line given by the equation $$$y = -x + q_i$$$.The sum of the values of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$. Similarly, the sum of the values of $$$m$$$ over all test cases in the input does not exceed $$$10^5$$$.In hacks it is allowed to use only one test case in the input, so $$$t=1$$$ should be satisfied.

Output: 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 Inputs:
3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1

Sample Outputs:
3
1
0

Solution (Python):
tests = int(input())
for _ in range(tests):
    d = int(input())
    dls = input()
    j = int(input())
    jls = input()
    dls = [x[-1] for x in dls.split()]
    jls = [x[-1] for x in jls.split()]
    dlsp = [x for x in dls if x in '02468']
    jlsp = [x for x in jls if x in '02468']
    ldslp = len(dlsp)
    ljslp = len(jlsp)
    lignes = ldslp * ljslp + (d - ldslp) * (j - ljslp)
    ''
    print(lignes)

Solution (Python):
for fi in range(int(input())):
    m = int(input())
    p = [int(i) % 2 for i in input().split()]
    n = int(input())
    q = [int(i) % 2 for i in input().split()]
    even_p = p.count(0)
    odd_p = p.count(1)
    even_q = q.count(0)
    odd_q = q.count(1)
    count = even_p * even_q + odd_p * odd_q
    print(count)

Solution (Python):
t = int(input())
ans = []
for _ in range(t):
    n = int(input())
    p_n = list(map(int, input().split()))
    m = int(input())
    q_m = list(map(int, input().split()))
    p_odd = sum([1 if p % 2 == 1 else 0 for p in p_n])
    p_even = n - p_odd
    q_odd = sum([1 if q % 2 == 1 else 0 for q in q_m])
    q_even = m - q_odd
    ans.append(p_odd * q_odd + p_even * q_even)
for a in ans:
    print(a)