Susquehanna International GroupOA #2
Equal Difference Pairs
EasyJudge-ready
Topics (AI-labelled)HashingBits & Math
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].
Input
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
Output one integer: the number of index pairs that satisfy the condition.
Example 1
Input:
4
2 -2 5 3
1 5 -1 1
Output:
6
Example 2
Input:
2
25 0
0 25
Output:
3
Example 3
Input:
1
7
-3
Output:
1
Example notes
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.
Editorial
Loading solution…