cswork / OA打开练习工作台

Susquehanna International GroupOA #2

Equal Difference Pairs

简单可在线判题

考点(AI 标注)哈希计数位运算

Given two integer arrays a and b of the same length, count the index pairs (i,j) such that i≤j and a[i]−b[j]=a[j]−b[i].

输入格式

The first line contains n; the second line contains n integers a[0..n−1]; the third line contains n integers b[0..n−1]. 1≤n≤200000, −10^9≤a[i],b[i]≤10^9.

输出格式

Output one integer: the number of index pairs that satisfy the condition.

样例 1

输入:

4
2 -2 5 3
1 5 -1 1

输出:

6

样例 2

输入:

2
25 0
0 25

输出:

3

样例 3

输入:

1
7
-3

输出:

1

样例说明

Example 1: a=[2,−2,5,3], b=[1,5,−1,1]. The valid pairs are (0,0), (0,1), (1,1), (2,2), (2,3), and (3,3), 6 in total; for example, for (0,1): a[0]−b[1]=−3 and a[1]−b[0]=−3. Example 2: a=[25,0], b=[0,25]; (0,0), (0,1), and (1,1) all hold, so the answer is 3. Example 3: only (0,0) holds, so the answer is 1.