#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b, long long mod) {
  a %= mod;
  if (a < 0) a += mod;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return ans;
}
long long pwr(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  while (b) {
    long long temp = a;
    a = b;
    b = temp % b;
  }
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long modularInverse(long long a, long long m) {
  assert(false);
  return pwr(a, m - 2, m);
}
const int mod = 1000000007;
map<long long, long long> cnt;
map<long long, long long> countPairs, countSolo;
int a[200001];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    cnt[a[i]] += 1;
  }
  if (k == 1) {
    long long ans = 0;
    for (map<long long, long long>::iterator i = cnt.begin(); i != cnt.end();
         ++i) {
      long long x = i->second;
      ans += x * (x - 1) * (x - 2) / 6;
    }
    cout << ans;
  } else {
    long long ans = cnt[0] * (cnt[0] - 1) * (cnt[0] - 2) / 6;
    for (int i = n - 1; i >= 0; --i) {
      long long val = a[i];
      if (val == 0) continue;
      ans += countPairs[val * k];
      countSolo[val] += 1;
      countPairs[val] += countSolo[k * val];
    }
    cout << ans;
  }
}
