欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

A Tale of Two Lands (二分)

程序员文章站 2024-03-06 20:16:02
...

The legend of the foundation of Vectorland talks of two integers xx and yy. Centuries ago, the array king placed two markers at points |x||x| and |y||y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points |x−y||x−y| and |x+y||x+y| and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.

Here |z||z| denotes the absolute value of zz.

Now, Jose is stuck on a question of his history exam: "What are the values of xx and yy?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to nn integers a1,a2,…,ana1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these nnintegers such that the legend could be true if xx and yy were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105)  — the number of choices.

The second line contains nn pairwise distinct integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the choices Jose is considering.

Output

Print a single integer number — the number of unordered pairs {x,y}{x,y} formed by different numbers from Jose's choices that could make the legend true.

Examples

Input

3
2 5 -3

Output

2

Input

2
3 6

Output

1

Note

Consider the first sample. For the pair {2,5}{2,5}, the situation looks as follows, with the Arrayland markers at |2|=2|2|=2 and |5|=5|5|=5, while the Vectorland markers are located at |2−5|=3|2−5|=3 and |2+5|=7|2+5|=7:

A Tale of Two Lands (二分)

The legend is not true in this case, because the interval [2,3][2,3] is not conquered by Vectorland. For the pair {5,−3}{5,−3} the situation looks as follows, with Arrayland consisting of the interval [3,5][3,5] and Vectorland consisting of the interval [2,8][2,8]:

A Tale of Two Lands (二分)

As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair {2,−3}{2,−3}, for a total of two pairs.

In the second sample, the only pair is {3,6}{3,6}, and the situation looks as follows:

A Tale of Two Lands (二分)

Note that even though Arrayland and Vectorland share 33 as endpoint, we still consider Arrayland to be completely inside of Vectorland.

思路:

不管这个数是正还是负,都按照正数存进去,

从小到大排序,

假设a<b,那么满足a*2>b就符合题意,(是区间里面任意一个a都满足)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200000+5],n;
ll sum;
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        a[i]=abs(a[i]);
    }
    sort(a,a+n);
    for(int i=0; i<n; i++)
    {
        int l=0,r=i,s=-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(a[mid]*2>=a[i])
            {
                r=mid-1;
                s=mid;
            }
            else
            {
                l=mid+1;
            }
        }
        if(s!=-1)
        {
            sum+=(i-s);
        }
    }
    cout<<sum<<endl;
    return 0;
}