#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long int, long long int> m;
  map<long long int, long long int>::iterator it;
  int n, k1, cnt = 0;
  scanf("%d%d", &n, &k1);
  vector<int> v[n];
  int a[n];
  long long int x;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    it = m.find(a[i]);
    if (it == m.end()) {
      m[a[i]] = cnt;
      x = cnt++;
    } else
      x = it->second;
    v[x].push_back(i);
  }
  long long int k = k1, y;
  n--;
  long long int ans = 0;
  for (int i = 1; i < n; i++) {
    x = a[i];
    if (x % k) continue;
    x /= k;
    it = m.find(x);
    if (it == m.end()) continue;
    x = it->second;
    x = lower_bound(v[x].begin(), v[x].end(), i) - v[x].begin();
    y = a[i] * k;
    it = m.find(y);
    if (it == m.end()) continue;
    y = it->second;
    y = v[y].size() - (upper_bound(v[y].begin(), v[y].end(), i) - v[y].begin());
    ans += x * y;
  }
  cout << ans;
  return 0;
}
