#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
long long a[maxn];
map<long long, long long> mp, show;
int main() {
  long long n, k, ans = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", a + i);
  for (int i = n - 1; i >= 0; i--) {
    ans += mp[a[i]];
    if (a[i] % k == 0) mp[a[i] / k] += show[a[i] * k];
    show[a[i]]++;
  }
  printf("%lld\n", ans);
}
