#include <bits/stdc++.h>
using namespace std;
int w[123456 * 2];
int a[123456 * 2];
int num[123456 * 2];
vector<int> v[123456 * 2];
unsigned long long cal(int n) {
  unsigned long long ret = 1ll * n * (n - 1) / 2 * (n - 2) / 3;
  return ret;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  unsigned long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    w[i] = a[i];
  }
  sort(w, w + n);
  int u = unique(w, w + n) - w;
  for (int i = 0; i < n; i++) num[i] = lower_bound(w, w + u, a[i]) - w;
  for (int i = 0; i < n; i++) v[num[i]].push_back(i);
  if (k != 1) {
    int d = lower_bound(w, w + u, 0) - w;
    if (w[d] == 0) ans = cal(v[d].size());
    for (int i = 1; i < n - 1; i++) {
      if (a[i] == 0) continue;
      if (a[i] % k) continue;
      if (1ll * a[i] * k > w[u - 1]) continue;
      if (1ll * a[i] * k < w[0]) continue;
      int d = lower_bound(w, w + u, a[i] * k) - w;
      if (w[d] != k * a[i]) continue;
      int b = lower_bound(w, w + u, a[i] / k) - w;
      if (w[b] != a[i] / k) continue;
      int x = lower_bound(v[b].begin(), v[b].end(), i) - v[b].begin() - 1;
      if (x == -1) continue;
      int y = lower_bound(v[d].begin(), v[d].end(), i) - v[d].begin();
      if (y == v[d].size())
        continue;
      else
        ans += 1ll * (x + 1) * (v[d].size() - y);
    }
  } else {
    for (int i = 0; i < u; i++) {
      ans += cal(v[i].size());
    }
  }
  printf("%I64u\n", ans);
}
