#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long n, k, a[N], ans = 0;
map<long long, vector<long long> > mp;
vector<long long> dota(N, 0);
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]].push_back(i);
  }
  for (long long i = n - 2; i >= 0; i--) {
    if (mp.find(a[i] * k) == mp.end()) {
      continue;
    }
    dota[i] = (long long)(mp[a[i] * k].size()) -
              (upper_bound(mp[a[i] * k].begin(), mp[a[i] * k].end(), i) -
               mp[a[i] * k].begin());
  }
  for (auto &el : mp) {
    for (long long i = (long long)(el.second.size()) - 2; i >= 0; i--) {
      dota[el.second[i]] += dota[el.second[i + 1]];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (mp.find(a[i] * k) == mp.end()) {
      continue;
    }
    long long ind = upper_bound(mp[a[i] * k].begin(), mp[a[i] * k].end(), i) -
                    mp[a[i] * k].begin();
    if (ind == (long long)(mp[a[i] * k].size())) {
      continue;
    }
    ans += dota[mp[a[i] * k][ind]];
  }
  cout << ans << "\n";
}
