#include <bits/stdc++.h>
using namespace std;
long long i, j, k, m, n, a[200009], jog;
map<long long, long long> kd, l;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    kd[a[i]]++;
  }
  for (int i = n; i >= 1; i--) {
    kd[a[i]]--;
    if (a[i] % k != 0) {
      l[a[i]]++;
      continue;
    }
    jog += kd[a[i] / k] * l[a[i] * k];
    l[a[i]]++;
  }
  cout << jog;
}
