#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const unsigned long long MOD = 1000000007;
const int NR_CIFRE = 100005;
int main() {
  int n, k, k2;
  unsigned long long sol = 0;
  cin >> n >> k;
  k2 = k * k;
  unordered_map<long long, unsigned long long> m, sub;
  vector<long long> v;
  unsigned long long zero = 0;
  for (int i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    m[a]++;
    if (a != 0) {
      if (k != 1) {
        if (a % k == 0) {
          sub[a] += m[a / k];
        }
        if (a % k2 == 0) {
          sol += sub[a / k];
        }
      } else {
        v.push_back(a);
      }
    } else
      zero++;
  }
  while (zero >= 3) {
    zero--;
    sol += (zero - 1) * zero / 2;
  }
  if (k != 1) return cout << sol, 0;
  if (v.size()) {
    unsigned long long nr = 1;
    sort(v.begin(), v.end());
    for (int i = 0; i < n - 1; i++) {
      if (v[i] == v[i + 1])
        nr++;
      else {
        while (nr >= 3) {
          nr--;
          sol += (nr - 1) * nr / 2;
        }
        nr = 1;
      }
    }
    while (nr >= 3) {
      nr--;
      sol += (nr - 1) * nr / 2;
    }
  }
  cout << sol;
  return 0;
}
