Sphere Online Judge

SPOJ Problem Set (classical)

1296. 4 values whose sum is 0

Problem code: SUMFOUR

The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) belongs to 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 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

Output should be printed on a single line.

Example

Input:
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
Output:
5

Added by:Abhilash I
Date:2007-02-06
Time limit:10s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: ERL JS NODEJS PERL 6
Resource:South western 05-06

hide comments
2013-05-21 03:10:16 Neo
n may be greater than 4000 for some test cases ... O(2(n^2)*log(n)) got AC
2013-05-17 08:28:41 Looney Lupin
I don't understand why I get wrong answer . Sorry, could someone help?
ID: 9281609
2013-03-25 22:57:17 lets_begin
is it neccesary to take a element from a column?
2013-03-25 20:18:32 karan173
seems the test data is specifically designed for qsort to fail. use stl sort.
2013-01-11 21:19:03 Snehasish Roy ;)
@Vikas_pandey: upper_bound() and lower_bound() works fine here !!!
2013-01-07 19:31:00 saket diwakar
got AC in first attempt....:)
2012-11-17 16:09:03 Một Bạn Trai Giấu Tên
4000^4 = 256.000.000.000.000
2012-09-20 00:48:52 koi_na


Last edit: 2012-10-02 01:59:27
2012-09-18 21:49:00 temerario
@Albert Gevorgyan(Quantum): nice algorithm ...carry on....:P

Last edit: 2012-09-18 21:49:57
2012-07-11 22:34:04 Parag gupta
I am getting SIGABRT runtime error after running for around 0.75 sec.
Can someone tell me why am I getting this ?
Solution ID : 7300697 ( please check )
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.