#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long arr[2 * N];
map<long long, long long> l, r;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  if (n < 3) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) cin >> arr[i], r[arr[i]]++;
  long long res = 0;
  for (int i = 0; i < n; i++) {
    r[arr[i]]--;
    if (arr[i] % k == 0) {
      long long d = arr[i] / k, dd = arr[i] * k;
      res += l[d] * r[dd];
    }
    l[arr[i]]++;
  }
  cout << res;
  return 0;
}
