#include <bits/stdc++.h>
using namespace std;
char ar[105];
int br[105];
int main() {
  int n;
  scanf("%d", &n);
  map<long long, long long> x, y;
  long long k;
  long long ans = 0;
  long long r = 0;
  scanf("%lld", &k);
  int i;
  int a;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a != 0) {
      ans += y[a];
      y[a * k] += x[a];
      x[a * k]++;
    } else
      r++;
  }
  if (r >= 3) {
    ans += r * (r - 1) * (r - 2) / 6;
  }
  cout << ans;
}
