#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x;
  cin >> n >> k;
  map<int, long long> M[4];
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x % k == 0) {
      M[3][x] += M[2][x / k];
      M[2][x] += M[1][x / k];
    }
    M[1][x]++;
  }
  long long sum = 0;
  for (map<int, long long>::iterator it = M[3].begin(); it != M[3].end();
       it++) {
    sum += it->second;
  }
  cout << sum;
}
