Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.

He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.

A subsequence of length three is a combination of three such indexes i_1, i_2, i_3, that 1 ≤ i_1 < i_2 < i_3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.

A geometric progression with common ratio k is a sequence of numbers of the form b·k^0, b·k^1, ..., b·k^{r} - 1.

Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.


-----Input-----

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·10^5), showing how many numbers Polycarp's sequence has and his favorite number.

The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9) — elements of the sequence.


-----Output-----

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.


-----Examples-----
Input
5 2
1 1 2 2 4

Output
4
Input
3 1
1 1 1

Output
1
Input
10 3
1 2 6 2 3 6 9 18 3 9

Output
6


-----Note-----

In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

Difficulty: MEDIUM_HARD

Solutions:
import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	tc = 1
	for _ in range(tc):
		(n, k) = ria()
		a = ria()
		pos = {}
		ans = 0
		if k == 1:
			d = Counter(a)
			for i in d:
				if d[i] >= 3:
					t = d[i]
					ans += t * (t - 1) * (t - 2) // 6
		else:
			for i in range(n):
				if a[i] in pos:
					pos[a[i]].append(i)
				else:
					pos[a[i]] = [i]
			for i in range(1, n - 1):
				if a[i] % k == 0:
					x = a[i] // k
					y = a[i] * k
					if x in pos and y in pos:
						px = bisect.bisect_left(pos[x], i - 1)
						py = bisect.bisect_left(pos[y], i + 1)
						if px != len(pos[x]):
							if pos[x][px] > i - 1:
								px -= 1
							px += 1
						ans += px * (len(pos[y]) - py)
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


(n, k) = map(int, input().split())
a = map(int, input().split())
b = [dict(), dict()]
ans = 0
for x in a:
	if x % k == 0:
		y = x // k
		ans += b[1].get(y, 0)
		b[1][x] = b[0].get(y, 0) + b[1].get(x, 0)
	b[0][x] = b[0].get(x, 0) + 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
d2 = {}
result = 0
for x in a:
	cur = d2.get(x)
	if cur is not None:
		result += cur
	cur = d.get(x)
	if cur is not None:
		d2[k * x] = d2.get(k * x, 0) + cur
	d[k * x] = d.get(k * x, 0) + 1
print(result)


import collections
k = int(input().split()[1])
d = [collections.defaultdict(int) for _ in '123']
for x in map(int, input().split()):
	d[2][k * x] += d[1][x]
	d[1][k * x] += d[0][x]
	d[0][k * x] += 1
print(sum(d[2].values()))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = array()
C = Counter(a)
cur = defaultdict(int)
ans = 0
for i in range(n):
	mid = a[i]
	if mid % k:
		cur[mid] += 1
		continue
	prev = cur[mid // k]
	cur[mid] += 1
	next = C[mid * k] - cur[mid * k]
	ans += prev * next
print(ans)


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')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd
from heapq import heappush, heappop
from bisect import bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
d = defaultdict(int)
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[0 for _ in range(n)] for _ in range(3)]
for j in arr:
	d[j] += 1
ans = 0
if k != 1:
	d1 = defaultdict(int)
	ans = 0
	for i in range(n):
		dp[0][i] = d1[arr[i] / k]
		dp[1][i] = 1
		dp[2][i] = d[arr[i] * k]
		if arr[i] == 0 and dp[2][i] > 0:
			dp[2][i] -= 1
		d[arr[i]] -= 1
		d1[arr[i]] += 1
	for l in range(n):
		ans += dp[0][l] * dp[1][l] * dp[2][l]
elif k == 1:
	for i in d:
		ans += d[i] * (d[i] - 1) * (d[i] - 2) // 6
print(ans)


(n, k) = map(int, input().split())
nums = [int(x) for x in input().split()]
zero = {}
one = {}
ans = 0
for i in range(n):
	x = nums[i]
	if x % k == 0:
		if x // k in one:
			ans += one[x // k]
		if x // k in zero:
			if x not in one:
				one[x] = 0
			one[x] += zero[x // k]
	if x not in zero:
		zero[x] = 0
	zero[x] += 1
print(ans)


(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = list(map(int, input().split()))
Count = 0
(H, F) = ({}, {})
for i in range(n):
	if arr[i] % k != 0 or not arr[i] // k in H:
		H[arr[i]] = 0
	else:
		Count += H[arr[i] // k]
		H[arr[i]] = H.get(arr[i], 0) + F.get(arr[i] // k, 0)
	F[arr[i]] = F.get(arr[i], 0) + 1
print(Count)


s = 0
m = {}
o = {}
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
for a in l:
	o[a / k] = m[a / k] = m[a] = o[a] = 0
for a in l:
	if a % k == 0:
		s += m[a / k]
		m[a] += o[a / k]
	o[a] += 1
print(s)


d = {}
data = input().split()
k = int(data[1])
data = input().split()
ans = 0
for el in data:
	v = int(el)
	p = [0, 0]
	if v in d.keys():
		p = d[v]
	if v % k == 0 and v / k in d.keys():
		ans += d[v / k][1]
		p[1] += d[v / k][0]
	p[0] += 1
	d[v] = p
print(ans)


from collections import Counter
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
lk = {}
ans = 0
rk = Counter(a)
for x in a:
	rk[x] -= 1
	if x % k == 0:
		ans += lk.get(x / k, 0) * rk.get(x * k, 0)
	lk[x] = 1 + lk.get(x, 0)
print(ans)


s = input()
s1 = s.split()
k = int(s1[1])
s = input()
s1 = s.split()
l = [int(i) for i in s1]
d = {}
for i in range(len(l)):
	if l[i] not in d:
		d[l[i]] = [i]
	else:
		d[l[i]].append(i)

def findl(x, arr):
	l = 0
	r = len(arr) - 1
	while r > l:
		mid = (l + r + 1) // 2
		if arr[mid] > x:
			r = mid - 1
		else:
			l = mid
	mid = (l + r + 1) // 2
	if arr[mid] < x:
		return mid + 1
	elif arr[mid] == x:
		return mid
	else:
		return 0

def findr(x, arr):
	l = 0
	r = len(arr) - 1
	while r > l:
		mid = (l + r) // 2
		if arr[mid] > x:
			r = mid
		else:
			l = mid + 1
	mid = (l + r) // 2
	if arr[mid] > x:
		return len(arr) - mid
	elif arr[mid] == x:
		return len(arr) - mid - 1
	else:
		return 0
res = 0
for i in range(1, len(l) - 1):
	left = 0
	right = 0
	if l[i] / k in d:
		left = findl(i, d[l[i] / k])
	if l[i] * k in d:
		right = findr(i, d[l[i] * k])
	res = res + left * right
print(res)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
a = {}
for i in range(len(l)):
	if not l[i] in a:
		a[l[i]] = 1
	else:
		a[l[i]] += 1
b = {}
for i in a:
	b[i] = 0
b[l[0]] = 1
a[l[0]] -= 1
count = 0
for i in range(1, len(l)):
	a[l[i]] -= 1
	if l[i] % k == 0:
		if l[i] // k in b and l[i] * k in a:
			count += b[l[i] // k] * a[l[i] * k]
	b[l[i]] += 1
print(count)


from collections import defaultdict
import functools

def main():
	(N, K) = tuple((int(n) for n in input().split()))
	NS = tuple((int(n) for n in input().split()))
	nst = defaultdict(lambda : [0, 0, 0])
	for n in NS:
		if n == 0:
			nst[0][2] += nst[0][1]
			nst[0][1] += nst[0][0]
			nst[0][0] += 1
		else:
			(d, m) = divmod(n, K)
			if d != 0 and m == 0:
				nst[n][2] += nst[n // K][1]
				nst[n][1] += nst[n // K][0]
			nst[n][0] += 1
	print(functools.reduce(lambda x, y: x + y[2], nst.values(), 0))
main()


from collections import defaultdict as dd
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
hm1 = dd(int)
hm2 = dd(int)
ans = 0
for i in a:
	if i % k == 0:
		ans += hm2[i // k]
	if i % k == 0:
		hm2[i] += hm1[i // k]
	hm1[i] += 1
print(ans)


from collections import defaultdict
from sys import stdin
inp = stdin.readline
(n, k) = map(int, inp().split())
a = list(map(int, inp().split()))
left = [0] * n
freq_left = defaultdict(int)
right = [0] * n
freq_right = defaultdict(int)
ans = 0
for i in range(n):
	if a[i] % k == 0 and freq_left[a[i] // k] > 0:
		left[i] = freq_left[a[i] // k]
	freq_left[a[i]] += 1
for i in range(n - 1, -1, -1):
	if freq_right[a[i] * k] > 0:
		right[i] = freq_right[a[i] * k]
	freq_right[a[i]] += 1
for i in range(n):
	if left[i] > 0 and right[i] > 0:
		ans += left[i] * right[i]
print(ans)


import collections
import bisect

def solve1(dp):
	count = 0
	for num in dp.values():
		n = len(num)
		if n >= 3:
			count += n * (n - 1) * (n - 2) // 6
	return count

def solve(n, k, As, dp):
	count = 0
	for (i, ak) in enumerate(As):
		if ak % k:
			continue
		if ak == 0:
			continue
		a = ak // k
		akk = ak * k
		n_left = bisect.bisect_left(dp[a], i)
		n_right = len(dp[akk]) - bisect.bisect_left(dp[akk], i)
		count += n_left * n_right
	n0 = len(dp[0])
	if n0 >= 3:
		count += n0 * (n0 - 1) * (n0 - 2) // 6
	return count
(n, k) = map(int, input().split())
As = list(map(int, input().split()))
dp = collections.defaultdict(list)
for (i, a) in enumerate(As):
	dp[a].append(i)
if n < 3:
	print(0)
elif k == 1:
	print(solve1(dp))
else:
	print(solve(n, k, As, dp))


(n, k) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
ans = 0
c = {}
c2 = {}
for i in s:
	if i in c:
		c[i] += 1
	else:
		c[i] = 1
	if i % k == 0:
		if i in c2:
			if i // k in c:
				c2[i] += c[i // k]
		elif i // k in c:
			c2[i] = c[i // k]
		else:
			c2[i] = 0
	if i % (k * k) == 0:
		if i // (k * k) == i // k:
			ans += (c[i // (k * k)] - 1) * (c[i // (k * k)] - 2) // 2
		elif i // k in c2:
			ans += c2[i // k]
print(ans)


__author__ = 'taras-sereda'
from collections import Counter
(n, k) = map(int, input().split())
map_obj = map(int, input().split())
sequence = list(map_obj)
r = Counter(sequence)
l = Counter()
res = 0
for i in sequence:
	r[i] -= 1
	if i % k == 0:
		res += r.get(i * k, 0) * l.get(i / k, 0)
	l[i] += 1
print(res)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
e = {}
ans = 0
for i in range(n - 1, -1, -1):
	try:
		e[l[i]] += d[k * l[i]]
	except:
		try:
			e[l[i]] = d[k * l[i]]
		except:
			pass
	try:
		d[l[i]] += 1
	except:
		d[l[i]] = 1
	try:
		if l[i] == 0:
			pass
		else:
			ans += e[k * l[i]]
	except:
		pass
if k == 1:
	ans = 0
	for i in d.values():
		ans += i * (i - 1) * (i - 2) // 6
	print(ans)
else:
	try:
		x = d[0]
	except:
		x = 0
	ans += x * (x - 1) * (x - 2) // 6
	print(ans)


l = {}
r = {}
str = input()
a = [int(x) for x in str.split()]
n = a[0]
k = a[1]
str = input()
a = [int(x) for x in str.split()]
for x in a:
	if r.get(x, -1) == -1:
		r[x] = 1
	else:
		r[x] = r[x] + 1
ans = 0
for x in a:
	r[x] = r[x] - 1
	if x % k == 0:
		ans += l.get(x / k, 0) * r.get(x * k, 0)
	if l.get(x, 0) == 0:
		l[x] = 1
	else:
		l[x] = l[x] + 1
print(ans)


(n, k) = map(int, input().split())
main = list(map(int, input().split()))
(freq, kolgeom, kolvo) = ({}, {}, 0)
for a in main:
	if not a in freq:
		freq[a] = 0
	if a % k == 0:
		if a / k in kolgeom:
			kolvo += kolgeom[a / k]
		if not a in kolgeom:
			kolgeom[a] = 0
		if a / k in freq:
			kolgeom[a] += freq[a / k]
	freq[a] += 1
print(kolvo)


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt

def geti():
	return map(int, input().strip().split())

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

def getis():
	return map(str, input().strip().split())

def getls():
	return list(map(str, input().strip().split()))

def gets():
	return input().strip()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	(n, k) = geti()
	a = getl()
	index = dd(int)
	for i in range(n):
		index[a[i]] += 1
	ans = 0
	occur = dd(int)
	occur[a[0]] += 1
	index[a[0]] -= 1
	for i in range(1, n):
		index[a[i]] -= 1
		if a[i] % k == 0:
			prev = a[i] // k
			new = a[i] * k
			left = occur[prev]
			right = index[new]
			ans += left * right
		occur[a[i]] += 1
	print(ans)
solve()


from collections import defaultdict
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
d = defaultdict(list)
for i in range(n):
	d[arr[i]].append(i)
ans = 0
for i in range(n):
	if arr[i] % k == 0:
		first = int(arr[i] // k)
		third = arr[i] * k
		idx1 = lower_bound(d[first], i)
		idx3 = lower_bound(d[third], i + 1)
		p1 = idx1
		p3 = len(d[third]) - idx3
		ans += p1 * p3
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
otv = 0
mp1 = {}
mp2 = {}
for x in a:
	if x in mp2:
		mp2[x] += 1
	else:
		mp2[x] = 1
for i in range(n):
	mp2[a[i]] -= 1
	if a[i] % k == 0 and a[i] // k in mp1 and (a[i] * k in mp2):
		otv += mp1[a[i] // k] * mp2[a[i] * k]
	if a[i] in mp1:
		mp1[a[i]] += 1
	else:
		mp1[a[i]] = 1
print(otv)


from collections import Counter

def solve(n, k, arr):
	c1 = Counter()
	c2 = Counter()
	total = 0
	for a in reversed(arr):
		total += c2[a * k]
		c2[a] += c1[a * k]
		c1[a] += 1
	return total
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
print(solve(n, k, arr))


def get_sequence(a_indices, b_indices, c_indices):
	(a_i, b_i, c_i) = (0, 0, 0)
	i = 0
	total = len(a_indices) + len(b_indices) + len(c_indices)
	a_indices = a_indices[:]
	b_indices = b_indices[:]
	c_indices = c_indices[:]
	a_indices.append(1000005001)
	b_indices.append(1000005001)
	c_indices.append(1000005001)
	sequence = []
	while i < total:
		minimum = calculate_minimum(a_indices[a_i], b_indices[b_i], c_indices[c_i])
		if minimum == 'a':
			a_i += 1
		elif minimum == 'b':
			b_i += 1
		elif minimum == 'c':
			c_i += 1
		sequence.append(minimum)
		i += 1
	return sequence

def calculate(a_indices, b_indices, c_indices):
	sequence = get_sequence(a_indices, b_indices, c_indices)
	(a_stack, b_stack, c_stack) = (0, 0, 0)
	for ch in sequence:
		if ch == 'a':
			a_stack += 1
		elif ch == 'b':
			b_stack += a_stack
		elif ch == 'c':
			c_stack += b_stack
	return c_stack

def calculate_minimum(a_index, b_index, c_index):
	if a_index < b_index:
		if a_index < c_index:
			return 'a'
		else:
			return 'c'
	elif b_index < c_index:
		return 'b'
	else:
		return 'c'

def main():
	(n, k) = [int(t) for t in input().split()]
	a_list = [int(t) for t in input().split()]
	hash_map = {}
	for (index, a) in enumerate(a_list):
		if a in hash_map:
			hash_map[a].append(index)
		else:
			hash_map[a] = [index]
	total_gp = 0
	if k != 1:
		for a1 in hash_map.keys():
			a2 = a1 * k
			a3 = a2 * k
			if a2 in hash_map and a3 in hash_map:
				total_gp += calculate(hash_map[a1], hash_map[a2], hash_map[a3])
	else:
		for a in hash_map.keys():
			count = len(hash_map[a])
			if count >= 3:
				nc3 = count * (count - 1) / 2 * (count - 2) / 3
				total_gp += int(nc3)
	print(total_gp)
main()


from collections import *
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
pref = defaultdict(int)
curr = defaultdict(int)
ans = 0
for i in l:
	if not i % k:
		ans += curr[i // k]
		curr[i] += pref[i // k]
	pref[i] += 1
print(ans)


(n, k) = map(int, input().split())
from bisect import *
from collections import defaultdict
z = list(map(int, input().split()))
count = 0
al = defaultdict(list)
for i in range(len(z)):
	al[z[i]].append(i)
for i in range(len(z)):
	if z[i] % k == 0:
		x = al[z[i] // k]
		r = bisect_left(x, i)
		x = al[z[i] * k]
		t = bisect_right(x, i)
		count += (len(x) - t) * r
print(count)


(n, k) = [int(x) for x in input().split()]
mas = [int(x) for x in input().split()]
dictyCount = {}
dictyAns = {}
ans = 0
for x in mas[::-1]:
	ans += dictyAns.get(x * k, 0)
	dictyAns[x] = dictyAns.get(x, 0) + dictyCount.get(x * k, 0)
	dictyCount[x] = dictyCount.get(x, 0) + 1
print(ans)


def process(A, k):
	answer = 0
	k2 = k * k
	counts = {}
	counts2 = {}
	for x in A:
		if x % k2 == 0:
			if x // k2 in counts2:
				answer += counts2[x // k2]
		if x % k == 0:
			if x // k in counts:
				if x // k not in counts2:
					counts2[x // k] = 0
				counts2[x // k] += counts[x // k]
		if x not in counts:
			counts[x] = 0
		counts[x] += 1
	return answer
(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
print(process(A, k))


(inp, inp1) = map(int, input().split())
inp2 = list(map(int, input().split()))
dictionary = {}
dictionaryFNums = {}
k = inp1
res = 0
for n in range(inp):
	element = inp2[n]
	if element % k == 0:
		res += dictionary.get(element / k, 0)
		dictionary[element] = dictionary.get(element, 0) + dictionaryFNums.get(element / k, 0)
	dictionaryFNums[element] = dictionaryFNums.get(element, 0) + 1
print(res)


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
D = {}
amount = 0
for x in a:
	if not x in D:
		D[x] = [0, 0]
	t = D[x // k] if x % k == 0 and x // k in D else [0, 0]
	D[x][1] += t[0]
	D[x][0] += 1
	if x != 0:
		amount += t[1]
C_k_3 = lambda n: n * (n - 1) * (n - 2) // 6
if k != 1:
	print(amount + C_k_3(D.get(0, [0, 0])[0]))
else:
	print(sum([C_k_3(D[x][0]) for x in D]))


l = input().split()
n = int(l[0])
k = int(l[1])
l = input().split()
li = [int(i) for i in l]
hashipref = dict()
hashisuff = dict()
for i in range(n - 1, 0, -1):
	if li[i] not in hashisuff:
		hashisuff[li[i]] = 1
	else:
		hashisuff[li[i]] += 1
ans = 0
for i in range(1, n):
	if li[i - 1] not in hashipref:
		hashipref[li[i - 1]] = 0
	hashipref[li[i - 1]] += 1
	hashisuff[li[i]] -= 1
	if li[i] % k == 0 and li[i] // k in hashipref and (li[i] * k in hashisuff):
		ans += hashipref[li[i] // k] * hashisuff[li[i] * k]
print(ans)


def main():
	import sys
	from collections import defaultdict
	tokens = [int(i) for i in sys.stdin.read().split()]
	tokens.reverse()
	(n, k) = (tokens.pop(), tokens.pop())
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	result = 0
	for i in tokens:
		result += d2[i * k]
		d2[i] += d1[i * k]
		d1[i] += 1
	print(result)
main()


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')
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
from collections import defaultdict, Counter
d1 = defaultdict(int)
c = Counter(l)
ans = 0
for i in range(n):
	if l[i] % k == 0:
		a = d1[l[i] // k]
		b = c[l[i] * k] - d1[l[i] * k]
		if l[i] * k == l[i]:
			b -= 1
		if a > 0 and b > 0:
			ans += a * b
	d1[l[i]] += 1
print(ans)


from collections import defaultdict, Counter

def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	(n, k) = [int(x) for x in input().split()]
	series = [int(x) for x in input().split()]
	ct = Counter(series)
	ct2 = defaultdict(lambda : 0)
	ct2[series[0]] += 1
	ans = 0
	for i in range(1, n - 1):
		x = series[i]
		lefts = 0
		rights = 0
		if x % k == 0:
			lefts = ct2[x // k]
		ct2[x] += 1
		rights = ct[x * k] - ct2[x * k]
		ans += lefts * rights
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
counter = 0
element_occurrence = {}
element_counter = {}
for i in range(n):
	element = arr[i]
	if element % k == 0:
		counter += element_counter.get(element / k, 0)
		element_counter[element] = element_counter.get(element, 0) + element_occurrence.get(element / k, 0)
	element_occurrence[element] = element_occurrence.get(element, 0) + 1
print(counter)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
lf = {}
rt = {}
for x in a:
	lf[x] = 0
	try:
		rt[x] += 1
	except KeyError:
		rt[x] = 1
prog = 0
for x in a:
	try:
		if x % k == 0:
			rt[x] -= 1
			prog += lf[x // k] * rt[x * k]
	except KeyError:
		pass
	finally:
		lf[x] += 1
print(prog)


from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
(cnt, pre) = ({}, {})
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * n
if k == 1:
	d = Counter(a)
	ans1 = 0
	for key in d:
		ans1 += max(d[key] * (d[key] - 1) * (d[key] - 2) // 6, 0)
	print(ans1)
else:
	ans = 0
	for i in range(n):
		cnt[a[i]] = cnt.get(a[i], 0) + 1
		if a[i] != 0:
			dp[i] = pre.get(a[i] // k, 0)
			pre[a[i]] = pre.get(a[i], 0) + cnt.get(a[i] // k, 0)
	for i in range(n):
		if a[i] != 0:
			if a[i] % k == 0 and a[i] % (k * k) == 0:
				ans += dp[i]
	zer = cnt.get(0, 0)
	ans += max(zer * (zer - 1) * (zer - 2) // 6, 0)
	print(ans)


import sys
from collections import defaultdict
input = sys.stdin.readline
first = defaultdict(lambda : 0)
second = defaultdict(lambda : 0)
cnt = 0
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(0, n):
	if a[i] % k == 0:
		cnt += second[a[i] // k]
		second[a[i]] += first[a[i] // k]
	first[a[i]] += 1
print(cnt)


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
ans = 0
mp = {}
for i in range(n):
	if arr[i] in mp:
		mp[arr[i]] += 1
	else:
		mp[arr[i]] = 1
mp2 = {}
for i in range(n - 1, -1, -1):
	a = 0
	mp[arr[i]] -= 1
	if arr[i] * k in mp2:
		a = mp2[arr[i] * k]
	b = 0
	if arr[i] % k == 0:
		if arr[i] // k in mp:
			b = mp[arr[i] // k]
	ans += a * b
	if arr[i] in mp2:
		mp2[arr[i]] += 1
	else:
		mp2[arr[i]] = 1
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(dp_left, dp_right) = ({}, {})
for i in l:
	if i in dp_right:
		dp_right[i] += 1
	else:
		dp_right[i] = 1
dp_right[l[0]] -= 1
if n < 3:
	print(0)
else:
	ans = 0
	for i in range(1, n - 1):
		if l[i - 1] in dp_left:
			dp_left[l[i - 1]] += 1
		else:
			dp_left[l[i - 1]] = 1
		dp_right[l[i]] -= 1
		if l[i] % k:
			continue
		t1 = dp_left[l[i] // k] if l[i] // k in dp_left else 0
		t2 = dp_right[l[i] * k] if l[i] * k in dp_right else 0
		ans += t1 * t2
	print(ans)


import bisect
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
new_a = set(a)
ans = 0
p = {}
for i in range(n):
	p[a[i]] = []
for i in range(n):
	p[a[i]].append(i)
for i in range(n):
	if a[i] % k == 0:
		first = a[i] // k
		second = a[i] * k
		if first == second and second == a[i]:
			pos = bisect.bisect_left(p[a[i]], i)
			ans += pos * (len(p[a[i]]) - pos - 1)
		else:
			f = 0
			s = 0
			if first in new_a:
				f = bisect.bisect_right(p[first], i)
			if second in new_a:
				s = len(p[second]) - bisect.bisect_right(p[second], i)
			ans += f * s
print(ans)


(n, k) = map(int, input().split())
arr = [int(z) for z in input().split()]

def binsearch(nums, target):
	left = 0
	right = len(nums) - 1
	while left <= right:
		mid = (left + right) // 2
		if nums[mid] == target:
			return mid
		elif nums[mid] > target:
			right = mid - 1
		elif nums[mid] < target:
			left = mid + 1
	return left
occ = {}
for i in range(n):
	occ[arr[i]] = []
for i in range(n):
	occ[arr[i]].append(i)
res = 0
for i in range(n):
	e = arr[i]
	if e % k:
		continue
	if not occ.get(e // k) or not occ.get(e * k):
		continue
	pl1 = min(len(occ[e // k]), binsearch(occ[e // k], i - 0.1))
	pl2 = max(0, len(occ[e * k]) - binsearch(occ[e * k], i + 0.1))
	res += pl1 * pl2
print(res)


from collections import defaultdict
(n, k) = map(int, input().split())
d = [defaultdict(int) for _ in range(3)]
arr = list(map(int, input().split()))
for x in arr:
	d[2][k * x] += d[1][x]
	d[1][k * x] += d[0][x]
	d[0][k * x] += 1
print(sum(d[2].values()))


__author__ = 'taras-sereda'
from collections import Counter
(n, k) = list(map(int, input().split()))
sequence = list(map(int, input().split()))
r = Counter(sequence)
l = dict.fromkeys(r, 0)
res = 0
for i in sequence:
	r[i] -= 1
	if i % k == 0 and int(i * k) in r and (int(i / k) in l):
		res += r[i * k] * l[i / k]
	l[i] += 1
print(res)


import collections
(numOfSequence, favNum) = map(int, input().split())
dic = [collections.defaultdict(int) for _ in '123']
for elementInSeq in map(int, input().split()):
	dic[2][favNum * elementInSeq] += dic[1][elementInSeq]
	dic[1][favNum * elementInSeq] += dic[0][elementInSeq]
	dic[0][favNum * elementInSeq] += 1
print(sum(dic[2].values()))


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
dp = [{} for i in range(3)]
zeros = arr.count(0)
if k == 1:
	dp = {}
	for i in arr:
		if i in dp:
			dp[i] += 1
		else:
			dp[i] = 1
	ans = 0
	for i in dp:
		ans += dp[i] * (dp[i] - 1) * (dp[i] - 2) // 6
	print(ans)
else:
	arr = [i for i in arr if i != 0]
	for i in arr:
		p = i / k
		if i not in dp[0]:
			dp[0][i] = 1
		else:
			dp[0][i] += 1
		if int(p) == p:
			p = int(p)
			if i not in dp[1]:
				dp[1][i] = dp[0].get(p, 0)
			else:
				dp[1][i] += dp[0].get(p, 0)
			if i not in dp[2]:
				dp[2][i] = dp[1].get(p, 0)
			else:
				dp[2][i] += dp[1].get(p, 0)
	ans = 0
	for i in dp[2]:
		ans += dp[2][i]
	print(ans + zeros * (zeros - 1) * (zeros - 2) // 6)


from sys import stdin, stdout
from collections import defaultdict
(n, k) = [int(x) for x in stdin.readline().rstrip().split()]
nums = [int(x) for x in stdin.readline().rstrip().split()]
a = defaultdict(lambda : 0)
b = defaultdict(lambda : 0)
ans = 0
for i in range(n):
	num = nums[i]
	if num % k == 0:
		ans += b[int(num / k)]
		b[num] += a[int(num / k)]
	a[num] += 1
print(ans)


import bisect
import collections
import copy
import enum
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
cs = collections.Counter(arr)
pre = collections.Counter()
cs[arr[0]] -= 1
ans = 0
for i in range(1, len(arr) - 1):
	pre[arr[i - 1]] += 1
	cs[arr[i]] -= 1
	if arr[i] % k == 0:
		ans += pre[arr[i] // k] * cs[arr[i] * k]
print(ans)


import collections
maxa = 10 ** 9

def main():
	(n, k) = [int(s) for s in input().split()]
	alist = [int(s) for s in input().split()]
	if k == 1:
		a_ct = collections.Counter(alist)
		print(sum((c * (c - 1) * (c - 2) // 6 for (a, c) in a_ct.items())))
		return
	ca = collections.Counter()
	caak = collections.Counter()
	ans = 0
	for a in alist:
		if a % k == 0 and a // k % k == 0:
			ans += caak[a // k // k]
		if a % k == 0:
			caak[a // k] += ca[a // k]
		ca[a] += 1
	print(ans)
main()


(n, k) = [int(i) for i in input().split()]
input_ = [int(i) for i in input().split()]
left = {}
right = {}
for i in input_[1:]:
	a = right.get(i, None)
	if not a:
		right[i] = 1
	else:
		right[i] += 1
left[input_[0]] = 1
ans = 0
for i in input_[1:-1]:
	right[i] -= 1
	if i % k == 0:
		cl = left.get(i // k, 0)
		cr = right.get(i * k, 0)
		ans += cl * cr
	a = left.get(i, None)
	if not a:
		left[i] = 1
	else:
		left[i] += 1
print(ans)


from bisect import *
import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
d = dict()
for i in range(n):
	if lis[i] in d:
		d[lis[i]].append(i)
	else:
		d[lis[i]] = [i]
ans = 0
if k == 1:
	for i in d.values():
		p = len(i)
		ans += p * (p - 1) * (p - 2) // 6
else:
	for i in range(n):
		x = lis[i]
		if x != 0 and x % k == 0 and (x // k in d and x * k in d):
			(y, z) = (x // k, x * k)
			v1 = bisect_right(d[y], i)
			v2 = len(d[z]) - bisect_left(d[z], i + 1)
			ans += v1 * v2
	if 0 in d:
		p = len(d[0])
		ans += p * (p - 1) * (p - 2) // 6
print(ans)


import math

def main(arr, k):
	left = {}
	right = {}
	for e in arr:
		if e not in right:
			right[e] = 0
		right[e] += 1
	ans = 0
	for i in range(len(arr)):
		right[arr[i]] -= 1
		val_l = arr[i] / k
		val_r = arr[i] * k
		if val_l == int(val_l):
			val_l = int(val_l)
			if val_l in left and val_r in right:
				ans += left[val_l] * right[val_r]
		if arr[i] not in left:
			left[arr[i]] = 0
		left[arr[i]] += 1
	return ans
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(main(arr, k))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(l, r) = ({}, {})
for i in arr:
	r[i] = r.get(i, 0) + 1
ans = 0
for i in arr:
	r[i] -= 1
	if i % k == 0:
		ans += l.get(i / k, 0) * r.get(i * k, 0)
	l[i] = l.get(i, 0) + 1
print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
d = {}
ans = 0
for i in arr:
	temp = [0, 0]
	if i in d:
		temp = d[i]
	if i % k == 0 and i // k in d:
		ans += d[i // k][1]
		temp[1] += d[i // k][0]
	temp[0] += 1
	d[i] = temp
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
dleft = {}
dright = {}
for i in a:
	if i in dright:
		dright[i] += 1
	else:
		dright[i] = 1
dleft[a[0]] = 1
ans = 0
dright[a[0]] = max(0, dright[a[0]] - 1)
for i in range(1, n - 1):
	dright[a[i]] = max(0, dright[a[i]] - 1)
	if a[i] / k in dleft and a[i] * k in dright:
		ans += dleft[a[i] / k] * dright[a[i] * k]
	if a[i] in dleft:
		dleft[a[i]] += 1
	else:
		dleft[a[i]] = 1
print(ans)


import sys
from collections import defaultdict

def main():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	current_sequence = defaultdict(list)
	total_subsequences = 0
	default = [0, 0]
	for elem in a:
		previous = elem / k
		if elem not in current_sequence:
			current_sequence[elem] = default.copy()
		total_subsequences += current_sequence.get(previous, default)[0]
		current_sequence[elem][0] += current_sequence.get(previous, default)[1]
		current_sequence[elem][1] += 1
	print(total_subsequences)
main()


(n, k) = list(map(int, input().split(' ')))
a = input().split(' ')
arr = {}
zeroes = 0
lst = {}
ans = 0
for i in a:
	i = int(i)
	if i == 0:
		zeroes += 1
	else:
		if i in list(arr.keys()):
			arr[i][0] += 1
			if i % k == 0 and i // k in list(lst.keys()):
				arr[i][1] += arr[i // k][0]
		else:
			arr[i] = [1, 0]
			if i % k == 0 and i // k in list(lst.keys()):
				arr[i][1] = arr[i // k][0]
			lst[i] = True
		if i % k == 0 and i // k in list(lst.keys()):
			ans += arr[i // k][1]
if k == 1:
	ans = 0
	for i in lst:
		ans += arr[i][0] * (arr[i][0] - 1) * (arr[i][0] - 2) // 6
ans += zeroes * (zeroes - 1) * (zeroes - 2) // 6
print(ans)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
left = dict()
right = dict()
for i in range(n):
	if a[i] in right:
		right[a[i]] += 1
	else:
		right.update({a[i]: 1})
		left.update({a[i]: 0})
ans = 0
for i in range(n):
	right[a[i]] -= 1
	if not a[i] % k:
		if a[i] // k in left and a[i] * k in right:
			ans += left[a[i] // k] * right[a[i] * k]
	left[a[i]] += 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d1 = {a[0]: 1}
d2 = {}
dp1 = [0]
dp2 = [0, 0]
for i in range(1, n):
	if a[i] % k == 0 and a[i] // k in d1:
		dp1.append(d1[a[i] // k])
		if a[i] % k ** 2 == 0 and a[i] // k in d2:
			dp2.append(d2[a[i] // k])
		else:
			dp2.append(0)
	else:
		dp1.append(0)
		dp2.append(0)
	if a[i] in d1:
		d1[a[i]] += 1
	else:
		d1[a[i]] = 1
	if a[i] in d2:
		d2[a[i]] += dp1[i]
	else:
		d2[a[i]] = dp1[i]
print(sum(dp2))


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from bisect import bisect_left as binary

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n < 3:
		print(0)
		exit()
	if k == 1:
		d = Counter(a)
		ans = 0
		for item in d.values():
			ans += item * (item - 1) * (item - 2) // 6
		print(ans)
	else:
		d = defaultdict(list)
		ans = 0
		for (i, item) in enumerate(a):
			d[item].append(i)
		for item in d.keys():
			if item * k in d and item * k * k in d and item:
				zero = d[item]
				one = d[item * k]
				two = d[item * k * k]
				for z in one:
					temp = binary(zero, z)
					temp2 = len(two) - binary(two, z)
					ans += temp * temp2
		item = len(d[0])
		ans += item * (item - 1) * (item - 2) // 6
		print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
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')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


from collections import defaultdict
import time
(n, k) = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
left = [0] * len(nums)
predict = defaultdict(int)
for i in range(len(nums)):
	num = nums[i]
	if num % k == 0:
		left[i] = predict[num // k]
	predict[num] += 1
right = [0] * len(nums)
nextdict = defaultdict(int)
for i in range(len(nums) - 1, -1, -1):
	num = nums[i]
	right[i] = nextdict[num * k]
	nextdict[num] += 1
print(sum([left[i] * right[i] for i in range(len(nums))]))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, K) = getInts()
	A = getInts()
	if N < 3:
		return 0
	left_counter = col.defaultdict(int)
	geom_left = [0]
	right_counter = col.defaultdict(int)
	geom_right = [0]
	left_counter[A[0]] = 1
	for i in range(1, N):
		el = A[i]
		if el % K > 0:
			geom_left.append(0)
		else:
			geom_left.append(left_counter[el // K])
		left_counter[el] += 1
	right_counter[A[-1]] = 1
	for i in range(N - 2, -1, -1):
		el = A[i]
		geom_right.append(right_counter[el * K])
		right_counter[el] += 1
	geom_right.reverse()
	ans = 0
	for i in range(N):
		ans += geom_left[i] * geom_right[i]
	return ans
print(solve())


from collections import Counter
(n, k) = map(int, input().split(' '))
vals = list(map(int, input().split(' ')))
cntrl = Counter(vals)
cntrr = {}
ans = 0
for i in vals:
	cntrl[i] -= 1
	if i % k == 0 and i // k in cntrr and (i * k in cntrl):
		ans += cntrr[i // k] * cntrl[i * k]
	if i in cntrr:
		cntrr[i] += 1
	else:
		cntrr[i] = 1
print(ans)


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = set()
d = {i: 0 for i in l}
z = {i: 0 for i in l}
count = 0
if k != 1:
	for i in range(n - 1, -1, -1):
		if l[i] == 0:
			count += d[l[i]] * (d[l[i]] - 1) // 2
		elif l[i] * k in d:
			z[l[i]] += d[l[i] * k]
			count += z[l[i] * k]
		d[l[i]] += 1
else:
	for i in range(n - 1, -1, -1):
		count += d[l[i]] * (d[l[i]] - 1) // 2
		d[l[i]] += 1
print(count)


def main():
	from collections import Counter
	(n, k) = map(int, input().split())
	if k == 1:
		c = Counter(map(int, input().split()))
		print(sum((v * (v - 1) * (v - 2) for v in c.values())) // 6)
		return
	(c1, c2, res) = (Counter(), Counter(), 0)
	for x in reversed(list(map(int, input().split()))):
		kx = k * x
		res += c1[kx]
		c1[x] += c2[kx]
		c2[x] += 1
	print(res)
main()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
z = dict()
s = 0
for i in range(n):
	if not a[i] in z:
		z[a[i]] = [0, 0, 0]
	if a[i] % (k * k) == 0 and a[i] // k in z:
		q = z[a[i] // k][1]
		z[a[i]][2] += z[a[i] // k][1]
		s += q
	if a[i] % k == 0 and a[i] // k in z:
		z[a[i]][1] += z[a[i] // k][0]
	z[a[i]][0] += 1
print(s)


from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
left = {}
ans = 0
right = Counter(a)
for i in range(n):
	if right[a[i]] > 0:
		right[a[i]] -= 1
	if a[i] % k == 0:
		t1 = a[i] // k
		t2 = a[i] * k
		if t1 in left and t2 in right:
			ans += left[t1] * right[t2]
	try:
		left[a[i]] += 1
	except:
		left[a[i]] = 1
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
start = Counter(a[:1])
end = Counter(a[1:])
sum_ = 0
for x in a[1:-1]:
	end[x] -= 1
	if not x % k:
		sum_ += start[x // k] * end[x * k]
	start[x] += 1
print(sum_)


from collections import defaultdict
from sys import stdin

def main():
	(n, k) = map(int, stdin.readline().split())
	ar = list(map(int, stdin.readline().split()))
	ans = 0
	pre = {}
	suf = {}
	for i in ar:
		if suf.__contains__(i):
			suf[i] += 1
		else:
			suf[i] = 1
	for i in range(n):
		suf[ar[i]] -= 1
		if ar[i] % k == 0:
			ans += pre.get(ar[i] // k, 0) * suf.get(ar[i] * k, 0)
		if pre.__contains__(ar[i]):
			pre[ar[i]] += 1
		else:
			pre[ar[i]] = 1
	print(ans)
main()


from collections import defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
freq = defaultdict(int)
d = defaultdict(int)
ans = 0
for i in range(n):
	if a[i] % k == 0:
		ans += d[a[i] // k]
		d[a[i]] += freq[a[i] // k]
	freq[a[i]] += 1
print(ans)


from collections import Counter
from collections import defaultdict

def mp():
	return map(int, input().split())

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

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def listring(l):
	return ' '.join([str(x) for x in l])

def printlist(l):
	print(' '.join([str(x) for x in l]))
(n, k) = mp()
a = lt()
c = Counter(a)
result = 0
A = defaultdict(int)
B = defaultdict(int)
C = defaultdict(int)
if k == 1:
	for i in set(a):
		result += c[i] * (c[i] - 1) * (c[i] - 2)
	print(result // 6)
	exit()
for i in range(n):
	x = a[i]
	if x == 0:
		temp = A[0]
		temp1 = B[0]
		(A[0], B[0], C[0]) = (A[0] + 1, B[0] + temp, C[0] + temp1)
	else:
		A[x] += 1
		B[x] += A[x / k]
		C[x] += B[x / k]
for i in C:
	result += C[i]
print(result)


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[n, k] = get()
	a = get()
	b = set(a)
	d = {}
	s = [0] * n
	for j in b:
		d[j] = [0] * 2
	if a[0] * k in b:
		d[a[0] * k][1] += 1
	for i in range(1, n):
		if d[a[i]][0] > 0:
			s[i] += d[a[i]][0]
		if a[i] * k in b:
			if d[a[i]][1] > 0:
				d[a[i] * k][0] += d[a[i]][1]
			d[a[i] * k][1] += 1
		s[i] += s[i - 1]
	print(s[-1])
	if mode == 'file':
		f.close()
main()


(m, k) = map(int, input().split())
a = list(map(int, input().split()))
(p, n, x, y, ans) = ({}, {}, 0, 0, 0)
for i in range(2, m):
	if a[i] in n:
		n[a[i]] += 1
	else:
		n[a[i]] = 1
p[a[0]] = 1
for i in range(1, m - 1):
	x = a[i] // k if a[i] % k == 0 else '0'
	y = a[i] * k
	if x in p and y in n:
		ans += p[x] * n[y]
	if a[i] in p:
		p[a[i]] += 1
	else:
		p[a[i]] = 1
	n[a[i + 1]] -= 1
	if n[a[i + 1]] == 0:
		n.pop(a[i + 1])
print(ans)


import math
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
import time
count = defaultdict(lambda : 0)
till = defaultdict(lambda : 0)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if k != 1:
	for i in a:
		count[i] += 1
		if i % k == 0 and i != 0:
			till[i] += count[i // k]
		if i % (k * k) == 0 and i != 0:
			ans += till[i // k]
	t = count[0]
	ans += max(t * (t - 1) * (t - 2) // 6, 0)
	print(ans)
else:
	for i in a:
		count[i] += 1
	for i in count.keys():
		t = count[i]
		ans += max(t * (t - 1) * (t - 2) // 6, 0)
	print(ans)


from math import inf
from sys import stdin
input = stdin.readline
from collections import defaultdict

def put():
	return map(int, input().split())
(n, k) = put()
li = list(put())
one = defaultdict()
two = defaultdict()
ans = 0
for i in li:
	if i not in one:
		one[i] = 0
	if i % k == 0:
		j = i // k
		if j in one:
			if i not in two:
				two[i] = one[j]
			else:
				two[i] += one[j]
		if j in two:
			ans += two[j]
		if i == j:
			ans -= one[j]
	one[i] += 1
print(ans)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
N = 5 * 10 ** 6
(n, k) = Ri()
a = Ri()
dp1 = {}
dp2 = {}
dp3 = {}
ans = 0
ans = 0
for i in range(n - 1, -1, -1):
	dp3[a[i]] = dp2.get(a[i] * k, 0)
	dp2[a[i]] = dp2.get(a[i], 0) + dp1.get(a[i] * k, 0)
	dp1[a[i]] = dp1.get(a[i], 0) + 1
	ans += dp3[a[i]]
print(ans)


from collections import defaultdict as dd
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
right_d = dd(int)
left_d = dd(int)
for i in range(n):
	right_d[arr[i]] += 1
ans = 0
pre = 0
next = 0
for i in range(n):
	right_d[arr[i]] -= 1
	if arr[i] % k == 0:
		pre = arr[i] // k
		next = arr[i] * k
		ans += left_d[pre] * right_d[next]
	left_d[arr[i]] += 1
print(ans)


from bisect import bisect_right, bisect_left
from collections import defaultdict
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
store = defaultdict(list)
for i in range(n):
	store[arr[i]].append(i)

def findFreq(arr, left, right, element):
	a = bisect_left(store[element], left)
	b = bisect_right(store[element], right)
	return b - a
m = 0
for i in range(1, n - 1):
	current = arr[i]
	if current % k == 0:
		a = findFreq(arr, 0, i - 1, current // k)
		b = findFreq(arr, i + 1, n, current * k)
		m += a * b
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s1 = {}
s2 = {}
ans = 0
for aa in a:
	if aa % k == 0:
		ans += s1.get(aa // k, 0)
		s1[aa] = s1.get(aa, 0) + s2.get(aa // k, 0)
	s2[aa] = s2.get(aa, 0) + 1
print(ans)


from collections import defaultdict
(n, k) = map(int, input().split())
l = [float(i) for i in input().split()]
d1 = defaultdict(int)
d = defaultdict(int)
d2 = defaultdict(int)
for i in l:
	d2[i] += d1[i / k]
	d1[i] += d[i / k]
	d[i] += 1
print(sum(d2.values()))


o = {}
mp = {}
s = 0
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
for i in ar:
	if i % k == 0:
		s += mp.get(i / k, 0)
		mp[i] = mp.get(i, 0) + o.get(i / k, 0)
	o[i] = o.get(i, 0) + 1
print(s)


line = input().split()
N = int(line[0])
K = int(line[1])
line = input().split()
numbers = []
dictionary2 = {}
dictionary1 = {}
for i in range(N):
	numbers.append(int(line[i]))
	if numbers[i] in dictionary1:
		dictionary1[numbers[i]] += 1
	else:
		dictionary1[numbers[i]] = 1
sol = 0
for i in numbers:
	dictionary1[i] -= 1
	if i % K == 0:
		sol += (dictionary2[i / K] if i / K in dictionary2 else 0) * (dictionary1[i * K] if i * K in dictionary1 else 0)
	if i in dictionary2:
		dictionary2[i] += 1
	else:
		dictionary2[i] = 1
print(sol)


(n, k) = list(map(int, input().split(' ')))
mas = list(map(int, input().split(' ')))
di = dict()
res = 9999999999999999999999999999999999999
for i in mas:
	a = i * k
	a3 = str(a) + '_3'
	a2 = str(a) + '_2'
	s1 = str(i) + '_1'
	s2 = str(i) + '_2'
	s3 = str(i) + '_3'
	if di.get(s3):
		res += di.get(s3)
	if di.get(s2):
		if di.get(a3):
			di[a3] += di.get(s2)
		else:
			di[a3] = di.get(s2)
	if di.get(s1):
		if di.get(a2):
			di[a2] += 1
		else:
			di[a2] = 1
		di[s1] += 1
	else:
		if di.get(a2):
			di[a2] += 1
		else:
			di[a2] = 1
		di[s1] = 1
print(res - 9999999999999999999999999999999999999)


import sys
from collections import defaultdict
input = sys.stdin.readline
(n, k) = map(int, input().split())
(s, res) = (list(map(int, input().split())), 0)
(d1, d2) = (defaultdict(int), defaultdict(int))
for i in range(n):
	if s[i] % k == 0:
		res += d1[s[i] // k]
		d1[s[i]] += d2[s[i] // k]
	d2[s[i]] += 1
print(res)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
k = nextInt()
a = [nextInt() for i in range(n)]
left = {}
right = {}
for i in a:
	if i not in right:
		right[i] = 0
	right[i] += 1
res = 0
for i in a:
	right[i] -= 1
	if i % k == 0 and i / k in left and (i * k in right):
		res += left[i / k] * right[i * k]
	if not i in left:
		left[i] = 0
	left[i] += 1
print(res)


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ways = 0
	nums = {}
	gp = {}
	for i in arr:
		if i % k ** 2 == 0:
			first = i // k ** 2
			second = i // k
			if (first, second) in gp.keys():
				ways += gp[first, second]
		if i % k == 0:
			first = i // k
			if first in nums.keys():
				if (first, i) not in gp.keys():
					gp[first, i] = 0
				gp[first, i] += nums[first]
		if i not in nums.keys():
			nums[i] = 0
		nums[i] += 1
	if k == 1:
		pass
	print(ways)
main()


def main(arr, k, l=3):
	dp = [[0 for i in range(l + 1)] for j in range(len(arr))]
	vals = {}
	for i in range(len(dp)):
		dp[i][1] = 1
	for i in range(len(dp)):
		for j in range(2, len(dp[0])):
			val = arr[i]
			val_n = arr[i] / k
			if val_n == int(val_n):
				val_n = int(val_n)
				if (val_n, j - 1) in vals:
					dp[i][j] += vals[val_n, j - 1]
			prev = dp[i][j - 1]
			prev_val = arr[i]
			if (prev_val, j - 1) not in vals:
				vals[prev_val, j - 1] = 0
			vals[prev_val, j - 1] += prev
	ans = 0
	for i in range(len(dp)):
		ans += dp[i][l]
	return ans
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(main(arr, k))


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
for _ in range(T):
	(n, k) = map(int, input().split())
	d = dd(int)
	freq = dd(int)
	pos = dd(int)
	l = list(map(int, input().split()))
	for i in l:
		d[i] += 1
	ans = 0
	for i in range(0, n - 1):
		if l[i] % k == 0:
			y = l[i] // k
			yk = l[i] * k
			x = freq[y]
			z = d[yk] - freq[yk]
			if k == 1 or l[i] == 0:
				z -= 1
			ans += z * x
		freq[l[i]] += 1
	print(ans)


from sys import stdin, stdout
from collections import defaultdict
import math
I = stdin.readline
P = stdout.write
(n, k) = map(int, I().split())
r = defaultdict(lambda : 0)
l = defaultdict(lambda : 0)
arr = []
ans = 0
zero = 0
for i in I().split():
	i = int(i)
	if i != 0:
		arr.append(i)
		r[i] += 1
	if i == 0:
		zero += 1
ans += zero * (zero - 1) * (zero - 2) // 6
if k != 1:
	for i in arr:
		(k1, k2) = (0, 0)
		if i % k == 0:
			k1 = l[i // k]
			k2 = r[i * k]
			ans += k1 * k2
		r[i] -= 1
		l[i] += 1
	print(ans)
if k == 1:
	for j in r:
		i = r[j]
		ans += i * (i - 1) * (i - 2) // 6
	print(ans)


import sys
input = sys.stdin.readline
from collections import *
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = defaultdict(lambda : defaultdict(int))
for ai in a:
	if ai % k == 0:
		cnt[ai][2] += cnt[ai // k][1]
		cnt[ai][1] += cnt[ai // k][0]
	cnt[ai][0] += 1
ans = 0
for k in cnt:
	ans += cnt[k][2]
print(ans)


from collections import defaultdict
import bisect
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == 1:
	a.sort()
	ans = 0
	i = 0
	while i < n:
		t = a[i]
		c = 0
		while t == a[i]:
			c = c + 1
			i = i + 1
			if i == n:
				break
		ans = ans + c * (c - 1) * (c - 2) // 6
	print(ans)
else:
	d1 = [0] * n
	s1 = {}
	s2 = defaultdict(list)
	z = a.count(0)
	ans = z * (z - 1) * (z - 2) // 6
	for i in range(n):
		if a[i] != 0:
			s2[a[i]].append(i)
			s1[a[i]] = s1.get(a[i], 0) + 1
			if a[i] % k == 0:
				d1[i] = s1.get(a[i] // k, 0)
				if len(s2[a[i]]) > 1:
					d1[i] = d1[i] + d1[s2[a[i]][-2]]
	for i in range(n):
		if a[i] != 0:
			if a[i] % k == 0 and a[i] % k ** 2 == 0 and (len(s2[a[i] // k]) != 0) and (len(s2[a[i] // k ** 2]) != 0):
				j = bisect.bisect_right(s2[a[i] // k], i)
				if j > 0:
					ans = ans + d1[s2[a[i] // k][j - 1]]
	print(ans)


import heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from itertools import accumulate
R = lambda : map(int, input().split())
(n, k) = R()
arr = list(R())
(acc, dp_l, dp_r) = (0, Counter(), Counter(arr))
for (i, num) in enumerate(arr):
	dp_r[num] -= 1
	acc += (dp_l[num / k] if num % k == 0 else 0) * dp_r[num * k]
	dp_l[num] += 1
print(acc)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d1 = {}
for i in a:
	d1[i] = 1 if i not in d1 else d1[i] + 1
d2 = {}
ans = 0
for i in a:
	d1[i] -= 1
	if i % k == 0:
		if i // k in d2 and i * k in d1:
			ans += d2[i // k] * d1[i * k]
	d2[i] = 1 if i not in d2 else d2[i] + 1
print(ans)