While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.

In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).


-----Input-----

The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.

The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.


-----Output-----

Print one integer — the answer to the problem.


-----Examples-----
Input
4 2 1
1 3 5 7

Output
3

Input
4 2 0
5 3 1 7

Output
4

Input
5 3 1
3 3 3 3 3

Output
25



-----Note-----

In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).

In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).

In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.

Difficulty: MEDIUM_HARD
Tags: Sorting

Amortized analysis

Mathematics
Skill types: Sorting

Amortized analysis

Starter code:

Solutions:
import bisect
import math
(n, x, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0
for i in a:
	l = math.ceil(i / x) * x + (k - 1) * x
	r = l + x - 1
	if l < i:
		l = i
	else:
		l = l
	ans += bisect.bisect_right(a, r) - bisect.bisect_left(a, l)
print(ans)


(n, x, k) = list(map(int, input().split()))
sorted_array = sorted(list(map(int, input().split())))
summ = i = j = 0
for val in sorted_array:
	dis = (val // x - k) * x
	if i < n or j < n:
		while i < n and sorted_array[i] <= min(dis, val):
			i += 1
		while j < n and sorted_array[j] <= min(dis + x, val):
			j += 1
	summ += j - i
print(summ)


(n, x, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
(ans, l, r) = (0, 0, 0)
for y in a:
	kol = (y // x - k) * x
	ml = min(kol, y)
	mr = min(kol + x, y)
	while l < n:
		if a[l] > ml:
			break
		l += 1
	while r < n:
		if a[r] > mr:
			break
		r += 1
	ans += r - l
print(ans)


(n, x, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import Counter
ans = 0
if k != 0:
	dn = Counter()
	un = Counter()
	for i in a:
		dn[i // x] += 1
		un[(i - 0.1) // x] += 1
	for (item, kol) in list(un.items()):
		ans += kol * dn[item + k]
	print(ans)
else:
	dn = Counter()
	un = Counter()
	s = set()
	for i in a:
		if i % x != 0:
			un[i] += 1
			dn[i // x] += 1
	for (item, kol) in list(dn.items()):
		ans += kol * (kol + 1) // 2
	for (item, kol) in list(un.items()):
		ans += kol * (kol - 1) // 2
	print(ans)


from bisect import bisect_left
R = lambda : map(int, input().split())
(n, x, k) = R()
a = sorted(R())
z = zip(a, (((u - 1) // x + k) * x for u in a))
print(sum((bisect_left(a, l + x) - bisect_left(a, max(u, l)) for (u, l) in z)))


import math
import sys
import getpass
import bisect

def ria():
	return [int(i) for i in input().split()]
files = True
if getpass.getuser().lower() == 'frohenk' and files:
	sys.stdin = open('test.in')
(n, x, k) = ria()
ar = ria()
ar = sorted(ar)
suma = 0
for i in ar:
	l = math.ceil(i / x) * x + x * (k - 1)
	r = math.ceil(i / x) * x + x * k - 1
	if k == 0:
		l = i
		r = math.ceil(i / x) * x + x * k - 1
	suma -= bisect.bisect_left(ar, l) - bisect.bisect_right(ar, r)
print(suma)
sys.stdout.close()


from bisect import bisect_left
R = lambda : map(int, input().split())
(n, m, k) = R()
a = sorted(R())
s = 0
for i in a:
	l = ((i - 1) // m + k) * m
	s += bisect_left(a, l + m) - bisect_left(a, max(i, l))
print(s)


from bisect import bisect_left
R = lambda : list(map(int, input().split()))
(n, x, k) = R()
a = sorted(R())
cnt = 0
for u in a:
	l = ((u + x - 1) // x + k - 1) * x
	cnt += bisect_left(a, l + x) - bisect_left(a, max(u, l))
print(cnt)


def bina(arr, i, n, x, k, j):
	(l, h, ans) = (i, n - 1, n)
	while l <= h:
		m = (l + h) // 2
		cnt = arr[m] // x - (arr[i] - 1) // x
		if cnt <= k:
			l = m + 1
		else:
			ans = m
			h = m - 1
	(l, h, ans2) = (j, ans - 1, j - 1)
	while l <= h:
		m = (l + h) // 2
		cnt = arr[m] // x - (arr[i] - 1) // x
		if cnt < k:
			ans2 = m
			l = m + 1
		else:
			h = m - 1
	return (ans, ans2)
(n, x, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
j = 0
(ind, ind2) = bina(arr, 0, n, x, k, 0)
ans = ind - ind2 - 1
for i in range(1, n):
	if arr[i] > arr[j]:
		j = i
		(ind, ind2) = bina(arr, i, n, x, k, j)
	ans += ind - ind2 - 1
print(ans)


import sys
sys.setrecursionlimit(100000000)

def iin():
	return int(input())

def impin():
	return list(map(int, input().split()))

def irrin():
	return [int(x) for x in input().split()]

def imrin(n):
	return [int(input()) for _ in range(n)]

def c(n, k):
	if n < k:
		return 0
	s = 1
	for i in range(1, k + 1):
		s *= n - i + 1
		s //= i
	return s
(n, x, k) = impin()
arr = irrin()
if k == 0:
	trr = {}
	frr = {}
	for a in arr:
		if a % x != 0:
			p = a // x
			if p in trr:
				trr[p] += 1
			else:
				trr[p] = 1
			if a in frr:
				frr[a] += 1
			else:
				frr[a] = 1
	s = 0
	for p in trr:
		s += c(trr[p] + 1, 2)
	for a in frr:
		s += c(frr[a], 2)
	print(s)
else:
	urr = {}
	lrr = {}
	for a in arr:
		u = (a - 1) // x + 1
		l = a // x
		if u in urr:
			urr[u] += 1
		else:
			urr[u] = 1
		if l in lrr:
			lrr[l] += 1
		else:
			lrr[l] = 1
	s = 0
	for u in urr:
		l = u + k - 1
		if l in lrr:
			s += urr[u] * lrr[l]
	print(s)


from bisect import bisect_left, bisect_right
(n, x, k) = [int(i) for i in input().split(' ')]
ar = sorted([int(i) for i in input().split(' ')])
(lk, nk) = (-1, 0)
n_tup = 0
if x != 1 or k != 0:
	for i in range(len(ar)):
		nk = ar[i]
		if lk != nk:
			xf = k + (ar[i] - 1) // x
			lo = bisect_left(ar, ar[i])
			lt = bisect_left(ar, (xf + 1) * x, lo)
			gt = bisect_right(ar, xf * x - 1, lo)
		n_tup += lt - gt
		lk = nk
print(n_tup)


import bisect

def lower_bound(A, x):
	low = 0
	high = len(A)
	while low < high:
		mid = (low + high) // 2
		if int(A[mid]) < x:
			low = mid + 1
		else:
			high = mid
	return low

def upper_bound(A, x):
	low = 0
	high = len(A)
	while low < high:
		mid = (low + high) // 2
		if int(A[mid]) <= x:
			low = mid + 1
		else:
			high = mid
	return low
line = input().split()
n = int(line[0])
x = int(line[1])
k = int(line[2])
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in a:
	left = (i + x - 1) // x * x
	right = left + x * k - 1
	left = left + (k - 1) * x
	left = max(left, i)
	ans = ans + bisect.bisect_right(a, right) - bisect.bisect_left(a, left)
print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
from bisect import bisect_right as bi
(n, x, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b = {}
c = {}
for i in range(n):
	if a[i] // x not in b:
		b[a[i] // x] = []
	if (a[i] - 1) // x not in c:
		c[(a[i] - 1) // x] = []
	b[a[i] // x].append(a[i])
	c[(a[i] - 1) // x].append(a[i])
s = 0
for i in b:
	if i - k in c:
		for j in range(len(b[i])):
			s += bi(c[i - k], b[i][j])
print(s)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify, heappush, heappop, heappushpop
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
(n, x, k) = R()
a = sorted(R())
ans = 0
val = x * k
for i in a:
	if k == 0 and (not i % x):
		continue
	p = i + x - i % x - 1 + val - (x if i % x == 0 else 0)
	ans += bisect(a, p) - bisect_left(a, max(i, p - (x - 1)))
print(ans)


(n, x, k) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
ans = 0
from bisect import bisect_left as b
for i in range(n):
	if arr[i] % x == 0:
		l = arr[i] + (k - 1) * x
	else:
		l = (arr[i] // x + k) * x
	r = l + x
	if k == 0:
		if arr[i] % x == 0:
			continue
		else:
			l = arr[i]
			r = (arr[i] // x + 1) * x
	ans += b(arr, r) - b(arr, l)
print(ans)


(n, x, k) = map(int, input().split())
array = list(map(int, input().split()))

def next_x(n):
	return (n + x - 1) // x * x
valcount = {}
for a in array:
	valcount[a] = valcount.get(a, 0) + 1
begs = {}
pairs = 0
for (val, count) in sorted(valcount.items()):
	if k > 0 or val % x != 0:
		beg = next_x(val)
		begs[beg] = begs.get(beg, 0) + count
		from_ = next_x(val - k * x + 1)
		pairs += count * begs.get(from_, 0)
print(pairs)


import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right

def solution(li, x, k):
	li.sort()
	s = 0
	tot = 0
	for i in range(len(li)):
		l = math.ceil(li[i] / x) * x + (k - 1) * x
		r = l + x - 1
		l = max(l, li[i])
		mid = bisect_left(li, l)
		up = bisect_right(li, r)
		tot += up - mid
	return tot

def input_test():
	(n, x, k) = map(int, input().strip().split(' '))
	li = list(map(int, input().strip().split(' ')))
	out = solution(li, x, k)
	print(out)
input_test()


f = lambda : map(int, input().split())
(n, x, k) = f()
t = sorted(f())
s = i = j = 0
for y in t:
	d = (y // x - k) * x
	while i < n and t[i] <= min(d, y):
		i += 1
	while j < n and t[j] <= min(d + x, y):
		j += 1
	s += j - i
print(s)


import bisect

def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
[n, x, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n):
	l = (a[i] + x - 1) // x
	r = l + k - 1
	val_lower = max(a[i], r * x)
	val_upper = max(a[i], (r + 1) * x)
	lower = bisect.bisect_left(a, val_lower)
	upper = bisect.bisect_left(a, val_upper) - 1
	if lower > upper:
		continue
	res += upper - lower + 1
print(res)


from bisect import bisect_left as b
f = lambda : map(int, input().split())
(n, x, k) = f()
(s, t) = (0, sorted(f()))
p = [(q, ((q - 1) // x + k) * x) for q in t]
for (q, d) in p:
	s += b(t, d + x) - b(t, max(q, d))
print(s)


from bisect import bisect_left
(n, x, k) = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
ranges = []
for a in arr:
	if k == 0:
		a1 = ((a - 1) // x + 1) * x
		l = a
		r = a1 + x * (k - 1) + x
	else:
		a1 = ((a - 1) // x + 1) * x
		l = a1 + x * (k - 1)
		r = a1 + x * (k - 1) + x
	ranges.append((min(l, r), max(l, r)))
res = 0
for (l, r) in ranges:
	left_index = bisect_left(arr, l)
	right_index = bisect_left(arr, r)
	res += right_index - left_index
print(res)


(n, x, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
ans = 0
(s, t) = (0, 0)
for j in range(n):
	cur = (a[j] // x - k) * x
	while s < n and a[s] <= min(cur, a[j]):
		s += 1
	while t < n and a[t] <= min(cur + x, a[j]):
		t += 1
	ans += t - s
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, X, K) = map(int, input().split())
A = [int(x) for x in input().split()]
if X == 1 and K == 0:
	print(0)
	return
A.sort()

def right(start):
	x = start // X if start % X != 0 else start // X - 1
	endmin = max((x + K) * X, start)
	endmax = (x + K + 1) * X - 1
	return (endmin, endmax)
ans = 0
for (i, v) in enumerate(A):
	(rmin, rmax) = right(v)
	rl = bisect.bisect_left(A, rmin)
	rr = bisect.bisect_right(A, rmax)
	ans += rr - rl
print(ans)


from bisect import bisect_left
from bisect import bisect_right
from math import ceil

def next_line(a, x):
	return x * ceil(a / x)

def num_of(arr, a, x, k):
	if k == -1:
		return 0
	return bisect_left(arr, next_line(a, x) + k * x) - bisect_left(arr, a)

def find(arr, a, x, k):
	return num_of(arr, a, x, k) - num_of(arr, a, x, k - 1)
(n, x, k) = input().split(' ')
(n, x, k) = (int(n), int(x), int(k))
t = input().split(' ')
t = [int(a) for a in t]
t.sort()
sum = 0
for a in t:
	sum += find(t, a, x, k)
print(sum)


import sys
from bisect import *
import math
(N, X, K) = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))

def get(l, r):
	return r // X - (l - 1) // X
p = sorted(p)
mp = {}
n = len(p)
for i in range(n):
	if p[i] in mp:
		continue
	else:
		mp[p[i]] = i
x = 5
ans = 0
mx = 0
for i in range(0, n):
	x = p[i]
	a = x // X
	mn = 0
	mx = 0
	if x % X == 0:
		mn = x + (K - 1) * X
		mx = mn + X - 1
	else:
		mn = x // X * X + K * X
		mx = mn + X - 1
	if K == 0:
		if x % X == 0:
			continue
		mn = x
		mx = x // X * X + X - 1
	if mn > mx:
		continue
	ans = ans + bisect_right(p, mx) - bisect_left(p, mn)
print(ans)


import math

def count(a, sums, i, j, x):
	if a[i] % x == 0:
		return sums[j] - sums[i] + 1
	else:
		return sums[j] - sums[i]
(n, x, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = 0
sums = [a[i] // x for i in range(n)]
i = 0
j = 0
while i < n and j < n:
	cnt = count(a, sums, i, j, x)
	if cnt == k:
		if a[i] == a[j]:
			while j < n and cnt == k and (a[i] == a[j]):
				j += 1
			ans += (j - i) * (j - i)
		else:
			j1 = j + 1
			while j1 < n and sums[j1] - sums[j] == 0:
				j1 += 1
			while i < j1 and count(a, sums, i, j1 - 1, x) == k:
				if i >= j:
					i1 = i + 1
					while i1 < j1 and a[i1] == a[i]:
						i1 += 1
					ans += (i1 - i) * (i1 - i)
					ans += (j1 - i1) * (i1 - i)
					i = i1
				else:
					ans += min(j1 - j, j1 - i)
					i += 1
			j = j1
	elif cnt < k:
		j += 1
	else:
		i += 1
print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, x, k) = map(int, input().split())
l = list(map(int, input().split()))

def calc():
	l.sort()
	ans = 0
	aq = []
	for i in range(n):
		aq.append(l[i])
		b = l[i]
		a = l[i] - l[i] % x + 1
		rt = binarySearchCount(aq, len(aq), b) - 1
		rt1 = len(aq) - countGreater(aq, len(aq), a)
		ans += rt - rt1 + 1
	aq = deque([])
	for i in range(n - 1, -1, -1):
		b = l[i]
		a = l[i] - l[i] % x + 1
		rt = binarySearchCount(aq, len(aq), b) - 1
		rt1 = len(aq) - countGreater(aq, len(aq), a)
		ans += rt - rt1 + 1
		aq.appendleft(l[i])
	print(ans)
if k == 0:
	calc()
	sys.exit()
l.sort()
aq = []
ans = 0
for i in range(n):
	aq.append(l[i])
	st = l[i] - l[i] % x
	b = st - x * k + x
	a = b - x + 1
	rt = binarySearchCount(aq, len(aq), b) - 1
	rt1 = len(aq) - countGreater(aq, len(aq), a)
	ans += rt - rt1 + 1
aq = deque([])
for i in range(n - 1, -1, -1):
	st = l[i] - l[i] % x
	b = st - x * k + x
	a = b - x + 1
	rt = binarySearchCount(aq, len(aq), b) - 1
	rt1 = len(aq) - countGreater(aq, len(aq), a)
	ans += rt - rt1 + 1
	aq.appendleft(l[i])
print(ans)


from bisect import bisect_left as b
R = lambda : list(map(int, input().split()))
(n, x, k) = R()
a = sorted(R())
print(sum((b(a, l + x) - b(a, max(u, l)) for (u, l) in ((u, ((u - 1) // x + k) * x) for u in a))))