#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  long long ans = 0;
  map<long long, long long> A;
  map<long long, long long> B;
  for (long long i = 0; i < x; i++) {
    long long a;
    cin >> a;
    if (a % y == 0) {
      ans += A[a / y];
      A[a] += B[a / y];
    }
    B[a]++;
  }
  cout << ans;
}
