#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
long long zuo[maxn];
long long you[maxn];
long long a[maxn];
map<long long, int> mp;
map<long long, int> mp2;
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    if (a[i] % k == 0) {
      if (mp.find(a[i] / k) != mp.end()) {
        zuo[i] = mp[a[i] / k];
      } else {
        zuo[i] = 0;
      }
    } else {
      zuo[i] = 0;
    }
    if (mp.find(a[i]) == mp.end())
      mp[a[i]] = 1;
    else {
      mp[a[i]]++;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (mp2.find(a[i] * k) != mp2.end()) {
      you[i] = mp2[a[i] * k];
    } else {
      you[i] = 0;
    }
    if (mp2.find(a[i]) == mp2.end())
      mp2[a[i]] = 1;
    else {
      mp2[a[i]]++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += zuo[i] * you[i];
  }
  cout << ans << endl;
  return 0;
}
