#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 2e18;
int64_t inp() {
  int64_t x;
  cin >> x;
  return x;
}
string inp_str() {
  string x;
  cin >> x;
  return x;
}
int64_t sqr(int64_t n) { return n * n; }
int64_t power(int64_t a, int64_t b, int64_t mod) {
  int64_t res = 1;
  a %= mod;
  for (int64_t i = (0); i <= (log2(b)); ++i) {
    if (b & (1 << i)) res = (res * a) % mod;
    a = (a * a) % mod;
  }
  return res;
}
int64_t gcd(int64_t a, int64_t b) {
  while (b > 0) {
    int64_t tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
bool is_pal(string s) { return equal((s).begin(), (s).end(), s.rbegin()); }
void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
void file_io(char *in, char *out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
void print_bool(bool a) {
  if (a)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int64_t n, k;
vector<int64_t> a;
void Input() {
  n = inp();
  k = inp();
  a.resize(n + 1);
  generate(1 + (a).begin(), (a).end(), inp);
}
void Solve() {
  map<int64_t, int64_t> cnt, cnt_pair;
  int64_t ans = 0;
  for (int64_t i = (1); i <= (n); ++i) {
    if (a[i] == 0 || k == 1)
      ans += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
    else {
      if (a[i] % (k * k) == 0) ans += cnt_pair[a[i] / k];
      if (a[i] % k == 0) {
        int64_t add = cnt[a[i] / k];
        cnt_pair[a[i]] += add;
      }
    }
    cnt[a[i]]++;
  }
  cout << ans;
}
int main() {
  fast_io();
  Input(), Solve();
  return 0;
}
