This page is still under construction.

Parts of this page are still being built. What you see may change.

Sums and Differences

Interview

Time limit1sMemory limit128 MB

Summary
Count ordered pairs from distinct positions where the difference exceeds the sum, which holds exactly when the second element is negative.
Level

Easy2 of 10

Topics
Math, Combinatorics
Solved
No attempts yet

Problem

You are given nn integers. Count how many ordered pairs (a,b)(a, b) satisfy a−b>a+ba - b > a + b, where aa and bb are two elements taken from different positions (the same position cannot be used for both aa and bb).

Input

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6). The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9) separated by spaces.

Output

Print the number of ordered pairs whose difference is greater than their sum.

Hint

When the numbers are −1,2,3-1, 2, 3, the possible ordered pairs are (−1,2),(−1,3),(2,−1),(2,3),(3,−1),(3,2)(-1, 2), (-1, 3), (2, -1), (2, 3), (3, -1), (3, 2), six in total. Among them, (2,−1)(2, -1) and (3,−1)(3, -1) satisfy the condition.

Examples3

  1. Example 1

    Input
    3
    -1 2 3
    
    Expected output
    2
    
  2. Example 2

    Input
    4
    1 2 3 4
    
    Expected output
    0
    
  3. Example 3

    Input
    3
    -1 -2 -3
    
    Expected output
    6