#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long a[2 * maxn], n, ans, k;
map<long long, long long> cnt1, cnt2;
int main() {
  scanf("%d%d", &n, &k);
  long long i;
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  cnt1[a[1]]++;
  if (a[2] == k * a[1]) cnt2[a[2]]++;
  for (i = 3; i <= n; i++) {
    if (a[i] % k == 0) ans += cnt2[a[i] / k];
    cnt1[a[i - 1]]++;
    if (a[i] % k == 0) cnt2[a[i]] += cnt1[a[i] / k];
  }
  printf("%I64d", ans);
  return 0;
}
