#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long ar[n];
  for (long long i = 0; i < n; i++) {
    cin >> ar[i];
  }
  map<long long, long long> mp1, mp2;
  for (long long i = 0; i < n; i++) {
    mp2[ar[i]]++;
  }
  mp1[ar[0]]++;
  mp2[ar[0]]--;
  long long ans = 0;
  for (long long i = 1; i < n - 1; i++) {
    mp2[ar[i]]--;
    if (ar[i] % k == 0) ans += mp1[ar[i] / k] * mp2[ar[i] * k];
    mp1[ar[i]]++;
  }
  cout << ans << endl;
  return 0;
}
