#include <bits/stdc++.h>
using namespace std;
map<long long, long long> pref, suff;
long long v[200005];
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &v[i]);
    suff[v[i]]++;
  }
  if (k == 1) {
    for (auto par : suff) {
      long long x = par.second;
      if (x >= 3) res += (1LL * x * (x - 1) * (x - 2)) / 6;
    }
  } else {
    for (long long i = 0; i < n; i++) {
      long long x = v[i];
      suff[x]--;
      if (x % k == 0 and pref.count(x / k) and suff.count(1LL * x * k))
        res += 1LL * pref[x / k] * suff[x * k];
      pref[x]++;
    }
  }
  printf("%lld\n", res);
  return 0;
}
