#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<long long, long long> mp1, mp2;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] % (k * k) == 0) {
      ans += mp1[a[i] / k];
    }
    if (a[i] % k == 0) {
      mp1[a[i]] += mp2[a[i] / k];
    }
    mp2[a[i]]++;
  }
  cout << ans << '\n';
  return 0;
}
