#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long a[200005];
long long cal[3];
map<long long, long long> mp;
map<long long, long long> acc;
map<long long, bool> hamada;
vector<long long> v;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
  }
  long long ans = 0;
  if (k == 1) {
    for (int i = 0; i < n; i++) {
      if (!hamada[a[i]]) v.push_back(a[i]);
      mp[a[i]]++;
      hamada[a[i]] = true;
    }
    for (int i = 0; i < v.size(); i++) {
      long long x = mp[v[i]];
      ans += max(0ll, x * (x - 1) * (x - 2) / 6);
    }
    cout << ans;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    acc[a[i]] += mp[a[i] * k];
    mp[a[i]]++;
    if (a[i] == 0) continue;
    ans += acc[a[i] * k];
  }
  long long x = mp[0];
  ans += (x * (x - 1) * (x - 2)) / 6;
  cout << ans;
  return 0;
}
