#include <bits/stdc++.h>
using namespace std;
const int nmax = 2 * 100000;
int n, k;
long long a[nmax + 1];
map<long long, vector<int> > ma;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (ma.find(a[i]) == ma.end()) {
      ma[a[i]] = vector<int>();
    }
    ma[a[i]].push_back(i);
  }
  for (map<long long, vector<int> >::iterator i = ma.begin(); i != ma.end();
       ++i) {
    sort(i->second.begin(), i->second.end());
  }
  long long res = 0;
  long long x, y;
  long long cx, cy;
  for (int i = 0; i < n; ++i) {
    if (a[i] % k != 0) continue;
    x = a[i] / k, y = a[i] * k;
    if (ma.find(x) == ma.end() || ma.find(y) == ma.end()) continue;
    int l = 0, r = ma[x].size() - 1, m;
    while (l <= r) {
      m = (l + r) / 2;
      if (ma[x][m] < i)
        l = m + 1;
      else
        r = m - 1;
    }
    cx = l;
    l = 0, r = ma[y].size() - 1;
    while (l <= r) {
      m = (l + r) / 2;
      if (ma[y][m] > i)
        r = m - 1;
      else
        l = m + 1;
    }
    cy = ma[y].size() - l;
    res += cx * cy;
  }
  cout << res << endl;
  return 0;
}
