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