#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
map<long long, long long> lf, rt;
long long n, k, ans, a[N];
int main() {
  scanf("%I64d %I64d", &n, &k);
  for (int i = 0; i < int(n); i++) {
    scanf("%I64d", &a[i]);
    rt[a[i]]++;
  }
  for (int i = 0; i < int(n); i++) {
    long long k1 = 0, k2 = 0;
    if (a[i] % k == 0) k1 = lf[a[i] / k];
    rt[a[i]]--;
    k2 = rt[a[i] * k];
    ans += k1 * k2;
    lf[a[i]]++;
  }
  printf("%I64d", ans);
  return 0;
}
