#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, tot = 0;
  map<long long, long long> al;
  map<long long, long long> ar;
  long long a[200005] = {0};
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ar[a[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    ar[a[i]]--;
    long long right = a[i] * k;
    if (a[i] % k == 0) {
      long long left = a[i] / k;
      tot += al[left] * ar[right];
    }
    al[a[i]]++;
  }
  cout << tot << endl;
  return 0;
}
