#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long int subsequences(long long int a[], long long int n,
                           long long int r) {
  unordered_map<long long int, long long int> left, right;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) right[a[i]]++;
  for (long long int i = 0; i < n; i++) {
    long long int c1 = 0, c2 = 0;
    if (a[i] % r == 0) c1 = left[a[i] / r];
    right[a[i]]--;
    c2 = right[a[i] * r];
    ans += c1 * c2;
    left[a[i]]++;
  }
  return ans;
}
int main() {
  long long int n, r;
  cin >> n >> r;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cout << subsequences(a, n, r);
  return 0;
}
