#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  map<long long, long long> lt, rt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    rt[a[i]]++;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long ans1 = 0, ans2 = 0;
    if (a[i] % k == 0) {
      ans1 = lt[a[i] / k];
    }
    rt[a[i]]--;
    ans2 = rt[a[i] * k];
    ans += ans1 * ans2;
    lt[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
