#include <bits/stdc++.h>
using namespace std;
long long a, b[200000], k, l;
map<long long, int> M;
map<long long, int> M1;
int main() {
  cin >> a >> k;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
    M[b[i]]++;
  }
  for (int i = 0; i < a; i++) {
    M[b[i]]--;
    if (b[i] % k == 0) {
      l += (unsigned long long)M1[b[i] / k] * (unsigned long long)M[b[i] * k];
    }
    M1[b[i]]++;
  }
  cout << l;
}
