PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000130. Những cặp chỉ số đẹp (Another Problem about Beautiful Pairs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những cặp chỉ số đẹp (Another Problem about Beautiful Pairs)

Another Problem about Beautiful Pairs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn positive integers a1,…,ana_1,\ldots,a_n, count pairs (i,j)(i,j) satisfying 1≤i<j≤n1\le i<j\le n and aiaj=j−ia_i a_j=j-i.

PHOJ single-case adaptation: Each input file contains one case, without the leading test-case count tt used in the original Codeforces statement. The full per-case size limits remain unchanged.

Input

  • First line: nn.
  • Second line: nn integers a1,…,ana_1,\ldots,a_n.

Output

One integer: the number of valid pairs.

Subtasks

  • Subtask 1 (10 points): 2≤n≤1002\le n\le100, 1≤ai≤1031\le a_i\le10^3.
  • Subtask 2 (20 points): 2≤n≤30002\le n\le3000, 1≤ai≤1061\le a_i\le10^6.
  • Subtask 3 (30 points): 2≤n≤500002\le n\le50000, 1≤ai≤1091\le a_i\le10^9.
  • Subtask 4 (40 points): 2≤n≤2000002\le n\le200000, 1≤ai≤1091\le a_i\le10^9 (full single-case limits).

Examples

Example 1

Input

5
1 1 2 100 4

Output

3

Explanation: The pairs are (1,2),(1,3),(1,5)(1,2),(1,3),(1,5).

Example 2

Input

6
2 2 1 1 2 2

Output

7

Explanation: The pairs are (1,3),(1,5),(2,4),(2,6),(3,4),(3,5),(4,6)(1,3),(1,5),(2,4),(2,6),(3,4),(3,5),(4,6).

Example 3

Input

10
1 1 2 3 4 1 1 7 3 9

Output

10

Explanation: The ten valid pairs are (1,2)(1,2), (1,3)(1,3), (1,4)(1,4), (1,5)(1,5), (1,8)(1,8), (1,10)(1,10), (3,9)(3,9), (4,7)(4,7), (6,7)(6,7), and (6,9)(6,9).

Example 4

Input

2
1000000000 1000000000

Output

0

Explanation: The product for the only pair is 101810^{18}, while its index distance is 11.