cswork / OAOpen practice workspace

SalesforceOA #21

Get Perfect Pairs Count

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersBits & MathBinary Search

Count the index pairs with 0≤i<j<n that satisfy both min(|x−y|,|x+y|)≤min(|x|,|y|) and max(|x−y|,|x+y|)≥max(|x|,|y|), where x=a[i] and y=a[j]. Repeated values are counted separately by index.

Input

The input gives n and n integers. Full original bounds: 2≤n≤200000, −10^9≤a[i]≤10^9; the raw source restores the i<j condition that the catalog's HTML filtering swallowed.

Output

Output one integer answer.

Example 1

Input:

3
2 5 -3

Output:

2

Example 2

Input:

3
0 0 1

Output:

1

Example 3

Input:

3
-2 4 -5

Output:

2

Example notes

The outputs of the three public examples are, in order: 2; 1; 2. They have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…