4 Values whose Sum is 0
Time Limit: 15000MS Memory Limit: 228000K
Total Submissions: 20385 Accepted: 6116
Case Time Limit: 5000MS
Description
The SUM problem can be formulated as follows: given four lists A, B, C, D ofinteger values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b + c + d = 0 . In the following, we assume that all lists have the same size n .
Input
The firstlineofthe input filecontainsthe size ofthe lists n (this value can be as large as4000). We then have n lines containing fourinteger values (with absolute valueas large as228 ) that belong respectively to A, B, C and D .
Output
For each input file, your program has towritethenumber quadruplets whose sum is zero.
Sample Input
6
-452242 -16
-41 -275630
-3653 -3777
-3630 -75 -4626 -38 -1062
-32 -54 -645
Sample Output
5
Hint
Sample Explanation: Indeed, thesumofthefive following quadruplets is zero: (-45, -27, 42, 30), (26, 30, -10, -46), (-32, 22, 56, -46),(-32, 30, -75, 77), (-32, -54, 56, 30).
4 Values whose Sum is 0Time Limit: 15000MS Memory Limit: 228000KTotal Submissions: 20385 Accepted: 6116Case Time Limit: 5000MSDescriptionThe SUM problem can be formulated as follows: gi