#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if ((a.first) == (b.first))
    return a.second > b.second;
  else
    return a.first < b.first;
}
long long power(long long a, long long b) {
  long long p = 1;
  for (long long i = 1; i <= b; i++) p *= a;
  return p;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void bfs(map<long long, vector<long long> > &g, long long src,
         vector<long long> &c) {
  queue<long long> q;
  map<long long, long long> p;
  q.push(src);
  p[src] = src;
  c[src] = 1;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    long long i = 1;
    for (auto v : g[u]) {
      if (c[v] == -1) {
        q.push(v);
        p[v] = u;
        if (i == c[u] || i == c[p[u]]) i++;
        if (i == c[u] || i == c[p[u]]) i++;
        c[v] = i;
        i++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, i, k;
  cin >> n >> k;
  map<long long, long long> m1, m2;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    m1[a[i]]++;
  }
  m2[a[0]]++;
  m1[a[0]]--;
  long long count = 0;
  for (i = 1; i < n; i++) {
    m1[a[i]]--;
    if (a[i] % k == 0) {
      long long c1 = 0, c2 = 0;
      if (m2.find(a[i] / k) != m2.end()) c1 = m2[a[i] / k];
      if (m1.find(a[i] * k) != m1.end()) c2 = m1[a[i] * k];
      count += (c1 * c2);
    }
    m2[a[i]]++;
  }
  cout << count << endl;
}
