#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, K;
  long long k;
  scanf("%d%d", &n, &K);
  k = K;
  vector<int> a(n);
  map<long long, long long> rmap, fmap;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    rmap[a[i]]++;
  }
  long long ans = 0LL;
  for (int i = 0; i < n; i++) {
    rmap[a[i]]--;
    if (a[i] * k <= 1000000000 && a[i] % K == 0)
      ans += fmap[a[i] / K] * rmap[a[i] * k];
    fmap[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
