Approach hintTry it first, then revealHide
Rewrite a_j - a_i = j - i as a_j - j = a_i - i, then count pairs of equal keys with a hash map while scanning. The count needs 64 bits.
Rewrite a_j - a_i = j - i as a_j - j = a_i - i, then count pairs of equal keys with a hash map while scanning. The count needs 64 bits.