CF BUDDY
← Problems·

1520D · Same Differences

1200 · data structures, hashing, math

Problem: You are given an array aa of nn integers. Count the number of pairs of indices (i,j)(i, j) such that i<ji < j and ajai=jia_j - a_i = j - i.

Input Format: The first line contains one integer tt (1t1041 \le t \le 10^4). Then tt test cases follow.

The first line of each test case contains one integer nn (1n21051 \le n \le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \le a_i \le n) — array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case output the number of pairs of indices (i,j)(i, j) such that i<ji < j and ajai=jia_j - a_i = j - i.

Sample Cases

Case 1

Input

4
6
3 5 1 4 6 6
3
1 2 3
4
1 3 3 4
6
1 6 3 4 5 6

Output

1
3
3
10

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback