#include <bits/stdc++.h>
using namespace std;
long long mul(long long a, long long b) { return (a * b) % (100000007); }
long long add(long long a, long long b) { return (a + b) % (100000007); }
long long sub(long long a, long long b) {
  return (a - b + (a - b) / (100000007) * (100000007) + (100000007)) %
         (100000007);
}
void upd(long long &a, long long b) {
  a = (a % (100000007) + b % (100000007)) % (100000007);
}
int n, k;
int a[(1000000)];
bool b[(1000000)] = {0};
int l[(1000000)] = {0};
int cnt[40], cnt2[40];
long long f[(1000000)] = {0}, f2[(1000000)] = {0};
map<long long, int> S;
map<long long, int>::iterator it;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] % k == 0 && S.find(a[i] / k) != S.end()) f[i] = S[a[i] / k];
    it = S.find(a[i]);
    if (it == S.end())
      S[a[i]] = 1;
    else
      S[a[i]]++;
  }
  S.clear();
  for (int i = n; i; i--) {
    if (S.find((long long)(a[i]) * k) != S.end())
      f2[i] = S[((long long)(a[i]) * k)];
    it = S.find(a[i]);
    if (it == S.end())
      S[a[i]] = 1;
    else
      S[a[i]]++;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += f[i] * f2[i];
  cout << ans << endl;
  return 0;
}
