#include <bits/stdc++.h>
using namespace std;
int n, k, x;
map<int, long long> M1, M2;
long long answer;
int main() {
  scanf("%d%d", &n, &k);
  while (n--) {
    scanf("%d", &x);
    if (x % k == 0) {
      if ((x / k) % k == 0) answer += M2[x / k];
      M2[x] += M1[x / k];
    }
    M1[x] += 1;
  }
  cout << answer << endl;
}
