#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
map<pair<int, int>, long long> m;
long long get(pair<int, int> p) {
  if (!m.count(p))
    return 0;
  else
    return m[p];
}
void sum(pair<int, int> p, long long x) {
  if (!m.count(p))
    m[p] = x;
  else
    m[p] += x;
}
int v[200100];
int main() {
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) {
    if (v[i] % k == 0) {
      sum(make_pair(v[i], 3), get(make_pair(v[i] / k, 2)));
      sum(make_pair(v[i], 2), get(make_pair(v[i] / k, 1)));
    }
    sum(make_pair(v[i], 1), 1);
  }
  long long ans = 0;
  for (auto& p : m) {
    if (p.first.second == 3) ans += p.second;
  }
  cout << ans << endl;
}
