#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 100;
long long arr[mxn], k, b[mxn], c[mxn], n, ret;
map<long long, int> mpx, mpy;
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    if (arr[i] % k == 0) b[i] = mpx[arr[i] / k];
    mpx[arr[i]]++;
  }
  for (int i = n; i; --i) {
    c[i] = mpy[arr[i] * k], mpy[arr[i]]++;
    ret += 1LL * b[i] * c[i];
  }
  printf("%lld\n", ret);
}
