#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m, ot;
int a[200001];
int main() {
  long long n, k, i, o = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = n - 1; i >= 0; i--) {
    o += ot[a[i] * k];
    ot[a[i]] += m[a[i] * k];
    m[a[i]]++;
  }
  cout << o << endl;
}
