codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

131B.md (2343B)


      1 Source: https://codeforces.com/problemset/problem/131/B
      2 
      3 B. Opposites Attract
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* ( - 10 ≤ *t**i* ≤ 10). Of course, one number can be assigned to any number of customers.
     22 
     23 "Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1, *t*2, ..., *t**n*. For example, if *t* = (1,  - 1, 1,  - 1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4.
     24 
     25 Of course, a client can't form a couple with him/herself.
     26 
     27 Input
     28 
     29 The first line of the input data contains an integer *n* (1 ≤ *n* ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1, *t*2, ..., *t**n* ( - 10 ≤ *t**i* ≤ 10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests.
     30 
     31 Output
     32 
     33 Print the number of couples of customs with opposite *t*. The opposite number for *x* is number  - *x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
     34 
     35 Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 5  
     43 -3 3 0 0 3
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 3
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 3  
     56 0 0 0
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 3
     63 ```
     64 
     65 Note
     66 
     67 In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
     68 
     69 In the second sample any couple of clients is opposite.