#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  map<long long, long long> rt, lf;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    rt[a[i]]++;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] % k == 0) {
      long long l = a[i] / k;
      rt[a[i]]--;
      long long r = a[i] * k;
      ans += rt[r] * lf[l];
    }
    lf[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
