#include <bits/stdc++.h>
using namespace std;
long long a[200001];
map<long long, long long> dp[3];
long long n, k, ans;
signed main() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; ++i) {
    if (a[i] % k == 0) {
      ans += dp[1][a[i] / k];
      dp[1][a[i]] += dp[0][a[i] / k];
      ans += dp[2][a[i]];
    }
    dp[0][a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
