#include <bits/stdc++.h>
using namespace std;
map<long long, long long> M;
map<long long, long long> M2;
vector<int> V;
int main() {
  long long n, k;
  cin >> n >> k;
  long long wyn = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    V.push_back(a);
    M2[a]++;
  }
  for (int i = 0; i < V.size(); i++) {
    M[V[i]]++;
    if (V[i] % k) continue;
    if (k == 1 || V[i] == 0) M[V[i]]--;
    long long x;
    x = M[V[i] / k];
    if (k == 1 || V[i] == 0) M[V[i]]++;
    wyn += x * (M2[V[i] * k] - M[V[i] * k]);
  }
  cout << wyn << endl;
}
