import sys

sys.stdin = open("game.in", "r")
sys.stdout = open("game.out", "w")

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


a.sort()
b = []
for i in range(n):
    if i == 0 or a[i] != a[i - 1]:
        b.append([a[i], 1])
    else:
        b[-1][1] += 1

m = len(b)
ans = 0

#print("!")

# count 3 different
j = 0
for i in range(2, m):
    while j < i and b[j][0] * k < b[i][0]:
        j += 1
    ans += 6 * (i - j) * (i - j - 1) // 2

# count 2 different
# higher has 2
j = 0
for i in range(1, m):
    while j < i and b[j][0] * k < b[i][0]:
        j += 1
    if b[i][1] > 1:
        ans += 3 * (i - j)

# lower has 2
j = m - 1
for i in range(m - 2, -1, -1):
    while j > i and b[i][0] * k < b[j][0]:
        j -= 1
    if b[i][1] > 1:
        ans += 3 * (j - i)

# count all same
for x, y in b:
    if y >= 3:
        ans += 1

print(ans)