Benutzer-Werkzeuge

Webseiten-Werkzeuge


public:wettbewerbe:getconnected:aufgaben:list_sum

List Sum

Description

You are given four lists A, B, C and D containing integers. All lists have the same size n. How many quadruplets (a, b, c, d) ∈ A x B x C x D exist so that a+b+c+d = 0?

Input

The input begins with a single positive integer T on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The first line of the input file contains the size of the lists n (this value can be as large as 4000). We then have n lines containing four integer values (with absolute value as large as 228 ) that belong respectively to A, B, C and D.

Output

For each testcase you should output exactly one line containing the number of possibilities. This means your output should not contain any spaces and exactly T newline characters.

Sample Input

2

1
1 2 3 4

6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45

Sample Output

0
5

Sample Explanation: The sum of the five following quadruplets is zero: (-45, -27, 42, 30), (26, 30, -10, -46), (-32, 22, 56, -46),(-32, 30, -75, 77), (-32, -54, 56, 30).

public/wettbewerbe/getconnected/aufgaben/list_sum.txt · Zuletzt geändert: 2010-02-09 10:35 von ignaz