#include <bits/stdc++.h>
using namespace std;
map<long long, long long> vis;
long long ans1[200010], ans2[200010];
int main() {
  long long n, k;
  int i;
  cin >> n >> k;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    if (a[i] % k == 0) {
      if (vis.find(a[i] / k) != vis.end()) {
        ans1[i] = vis[a[i] / k];
      }
    }
    vis[a[i]] += 1;
  }
  vis.clear();
  for (i = n - 1; i >= 0; i--) {
    if (vis.find(a[i] * k) != vis.end()) {
      ans2[i] = vis[a[i] * k];
    }
    vis[a[i]] += 1;
  }
  long long sum = 0;
  for (i = 0; i < n; i++) {
    sum += ans1[i] * ans2[i];
  }
  cout << sum;
}
