#include <bits/stdc++.h>
using namespace std;
long long pref[200005];
long long suff[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  unordered_map<long long, long long> freq;
  for (long long i = 0; i < n; i++) {
    if (v[i] % k == 0) {
      pref[i] = freq[v[i] / k];
    }
    freq[v[i]]++;
  }
  freq.clear();
  for (long long i = n - 1; i >= 0; i--) {
    suff[i] = freq[v[i] * k];
    freq[v[i]]++;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += (pref[i] * suff[i]);
  }
  cout << ans;
}
