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