#include <bits/stdc++.h>
using namespace std;
long long k, ans = 0, i, n, a[300005];
map<long long, long long> ma, mama;
long long pa[300005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    if (a[i] % k == 0) pa[i] = ma[a[i] / k];
    ma[a[i]]++;
  }
  for (i = n - 1; i >= 0; i--) {
    pa[i] = pa[i] * mama[a[i] * k];
    mama[a[i]]++;
    ans += pa[i];
  }
  cout << ans;
  return 0;
}
