#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int main() {
  long long n, k, a, ans = 0;
  map<long long, long long> m1, m2;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a % k == 0) {
      ans += m1[a / k];
      m1[a] += m2[a / k];
    }
    m2[a]++;
  }
  cout << ans;
  return 0;
}
