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

#TP0000053. Các đoạn chứa đúng k bội số của x (XK Segments)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các đoạn chứa đúng k bội số của x (XK Segments)

XK Segments

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n and integers x,kx,k.

Consider an ordered pair of indices (i,j)(i,j) with 1≤i,j≤n1\le i,j\le n such that ai≤aja_i\le a_j. This pair is counted if the closed integer interval [ai,aj][a_i,a_j] contains exactly kk integers divisible by xx. Pairs (i,j)(i,j) and (j,i)(j,i) are different when i≠ji\ne j. Indices i=ji=j are allowed, and equal values at different positions still count separately.

Count all qualifying index pairs.

Input

  • The first line contains three integers n,x,kn,x,k: the array length, divisor and required count of multiples.
  • The second line contains exactly nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of valid ordered index pairs.

Subtasks

  • Subtask 1 (20 points): 1≤n≤251\le n\le 25; 1≤x≤1091\le x\le10^9; 0≤k≤1090\le k\le10^9; 1≤ai≤1091\le a_i\le10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤x≤1091\le x\le10^9; 0≤k≤1090\le k\le10^9; 1≤ai≤1091\le a_i\le10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤x≤1091\le x\le10^9; 0≤k≤1090\le k\le10^9; 1≤ai≤1091\le a_i\le10^9 for every ii.

Examples

Input

4 2 1
1 3 5 7

Output

3

Explanation

The valid ordered index pairs are (1,2)(1,2) for [1,3][1,3] containing 22, (2,3)(2,3) for [3,5][3,5] containing 44, and (3,4)(3,4) for [5,7][5,7] containing 66. Every other pair contains a different number of multiples of 22. The answer is 33.