#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
unordered_map<long long, long long> dpLeft, dpRight;
long long arr[200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < (n); ++i) {
    cin >> arr[i];
    ++dpRight[arr[i]];
  }
  long long ans = 0LL;
  for (long long i = 0; i < (n); ++i) {
    --dpRight[arr[i]];
    if (arr[i] % k == 0) ans += (dpLeft[arr[i] / k] * dpRight[arr[i] * k]);
    ++dpLeft[arr[i]];
  }
  cout << ans << '\n';
  return 0;
}
