#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e6;
int X[N];
int X1[N];
int X2[N];
unsigned long long L[N];
unsigned long long R[N];
map<int, unsigned long long> m;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> X[i];
    X1[i] = X[i] % k ? -1 : X[i] / k;
    X2[i] = X[i] % (k * k) ? -1 : X1[i] / k;
  }
  for (int i = n - 1; i >= 0; i--) {
    R[i] = m[X1[i]];
    m[X2[i]]++;
  }
  m.clear();
  for (int i = 0; i < n; i++) {
    L[i] = m[X1[i]];
    m[X[i]]++;
  }
  unsigned long long rez = 0;
  for (int i = 1; i < n - 1; i++) {
    if (X1[i] != -1) rez += L[i] * R[i];
  }
  cout << rez;
  return 0;
}
