#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-9;
const int maxn = 2e5 + 5;
long long n, k, a[maxn];
map<long long, long long> all, front;
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], all[a[i]]++;
  long long ans = 0;
  if (k == 1) {
    for (int i = 1; i <= n; ++i) {
      ans += front[a[i]] * (all[a[i]] - 1 - front[a[i]]);
      front[a[i]]++;
    }
  } else {
    for (int i = 1; i <= n; ++i) {
      if (a[i] % k == 0) {
        if (a[i] != 0)
          ans += (front[a[i] / k] * (all[a[i] * k] - front[a[i] * k]));
        else
          ans += (front[0] * (all[0] - front[0] - 1));
      }
      front[a[i]]++;
    }
  }
  cout << ans << endl;
  return 0;
}
