#include <bits/stdc++.h>
using namespace std;
long long n, k, x;
vector<long long> a;
map<long long, vector<long long> > f;
long long cnt;
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
    f[x].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] % k == 0) {
      long long m1 =
          f[a[i] * k].size() > 0
              ? distance(f[a[i] * k].end(),
                         upper_bound(f[a[i] * k].begin(), f[a[i] * k].end(), i))
              : 0;
      long long m2 = f[a[i] / k].size() > 0
                         ? distance(upper_bound(f[a[i] / k].begin(),
                                                f[a[i] / k].end(), i - 1),
                                    f[a[i] / k].begin())
                         : 0;
      cnt += m1 * m2;
    }
  }
  cout << cnt;
  return 0;
}
