#include <bits/stdc++.h>
using namespace std;
long long int cnt;
map<long long int, int> lft;
map<long long int, int> rght;
void reset();
int main() {
  int n, k, c1, c2, i, j;
  long long int arr[200000 + 7], r1, r2;
  while (scanf("%d %d", &n, &k) == 2) {
    reset();
    for (i = 0; i < n; i++) {
      scanf("%lld", &arr[i]);
      rght[arr[i]]++;
    }
    lft[arr[0]]++;
    rght[arr[0]]--;
    for (i = 1; i < n - 1; i++) {
      rght[arr[i]]--;
      if (arr[i] % k == 0) {
        r1 = arr[i] / k;
        r2 = arr[i] * k;
        c1 = lft[r1];
        c2 = rght[r2];
        cnt += (long long int)((long long int)c1 * (long long int)c2);
      }
      lft[arr[i]]++;
    }
    printf("%lld\n", cnt);
  }
  return 0;
}
void reset() {
  lft.clear();
  rght.clear();
  cnt = 0;
}
