#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> answer, answer1;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  long long int i;
  long long int sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % k == 0) {
      sum = sum + answer[a[i] / k];
      answer[a[i]] += answer1[a[i] / k];
    }
    answer1[a[i]]++;
  }
  cout << sum << endl;
}
