ayit609第八周训练f题

The next lecture in a high school requires two topics to be discussed. The ii-th topic is interesting by aiai units for the teacher and by bibi units for the students.

The pair of topics ii and jj (ibi+bjai+aj>bi+bj (i.e. it is more interesting for the teacher).

Your task is to find the number of good pairs of topics.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of topics.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the interestingness of the ii-th topic for the teacher.

The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1091≤bi≤109), where bibi is the interestingness of the ii-th topic for the students.

Output

Print one integer — the number of good pairs of topic.

Examples

Input

5
4 8 2 6 2
4 5 4 1 3

Output

7

Input

4
1 3 2 4
1 3 2 4

Output

0

Sponsor

 

#include
#include
#include
using namespace std;
int a[1000100];
int main()
{
	int m,b,i,a1,b1;
	long long r=0;
	scanf("%d",&m);
	for(i=0;i0)
		{
            if(a1>=b1)
			break;
            r+=(b1-a1);
            b1--;
        }
        else
        a1++;
    }
    printf("%lld\n",r);
    return 0;
}

题意   就是找题中那个式子满足的对数有多少个

方法  ai+aj>bi+bj;  转化为 ai-bi-bj+aj>0;转化成c[i]=a[i-b[i],然后再排序

排序后-2 -1 0 3 5
对于-2 有 3 5 使得和大于0    对于-1有 3 5  对于0 有3 5  对于3 有5
所以答案是7

排序后 如果现在是大于0得数 就加上后一位若小于0变化下标让ai+aj>0个数是n-j+1;

你可能感兴趣的:(ayit609第八周训练f题)