Loading...
Loading...
Loading...
Four lists A, B, C and D each hold n integers. Count the tuples (i, j, k, l) with A[i] + B[j] + C[k] + D[l] = 0. Different positions count as different tuples, even if the values are equal.
Example 1
Input
2 1 2 -2 -1 -1 2 0 2
Output
2
Two tuples add to zero.
Example 2
Input
1 0 0 0 0
Output
1
Try the problem first. Open one hint at a time.
Count all sums of A[i] + B[j] in a dictionary.
For every C[k] + D[l], add the count of its negative.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor