#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp1, mp2;
long long n, k;
long long a[200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  long long res = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 1; --i) {
    res += mp1[a[i] * k];
    if (a[i] % k == 0) mp1[a[i]] += mp2[a[i] * k];
    if (a[i] % (k * k) == 0) ++mp2[a[i]];
  }
  cout << res;
}
