#include <bits/stdc++.h>
using namespace std;
long long n, k, ar[200100], ans;
int main() {
  cin >> n >> k;
  map<long long, long long> fw, bk;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    bk[ar[i]]++;
  }
  for (int i = 0; i < n; i++) {
    bk[ar[i]]--;
    if (ar[i] % k == 0) {
      ans += fw[ar[i] / k] * bk[ar[i] * k];
    }
    fw[ar[i]]++;
  }
  cout << ans;
  return 0;
}
