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

#CT0000057. Cùng nhịp (Same Rhythm)

Bài tập này chưa được xếp vào lộ trình.

Cùng nhịp (Same Rhythm)

Same Rhythm

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer sequence A1,A2,…,ANA_1,A_2,\ldots,A_N and an integer KK.

For two positions i<ji<j, the pair (i,j)(i,j) is called a same-rhythm pair if

Aj−Aij−i=K.\frac{A_j-A_i}{j-i}=K.

Count the number of same-rhythm pairs.

Input

The first line contains NN and KK.

The second line contains A1,A2,…,ANA_1,A_2,\ldots,A_N.

Output

Print one integer: the number of valid pairs (i,j)(i,j).

Subtasks

  • Subtask 1 (30%): 1≤N≤20001\le N\le2000, ∣K∣≤109|K|\le10^9, ∣Ai∣≤109|A_i|\le10^9.
  • Subtask 2 (30%): K=0K=0, 1≤N≤2⋅1051\le N\le2\cdot10^5, ∣Ai∣≤109|A_i|\le10^9.
  • Subtask 3 (40%): 1≤N≤2⋅1051\le N\le2\cdot10^5, ∣K∣≤109|K|\le10^9, ∣Ai∣≤109|A_i|\le10^9.

Examples

Example 1

Input

5 2
3 5 8 9 11

Output

6

Explanation

The valid pairs are (1,2),(1,4),(1,5),(2,4),(2,5),(4,5)(1,2),(1,4),(1,5),(2,4),(2,5),(4,5).

Example 2

Input

4 0
7 7 8 7

Output

3

Explanation

When K=0K=0, both endpoints must have equal values. The three positions containing 77 form (32)=3\binom{3}{2}=3 pairs.

Example 3

Input

4 -1
5 4 3 10

Output

3

Explanation

Pairs (1,2),(1,3),(2,3)(1,2),(1,3),(2,3) all have average change −1-1.