#include <bits/stdc++.h>
using namespace std;
int b, n, k, c, a;
long long p, mas[200005];
map<long long, long long> countt, p1, p2, c2;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> mas[i];
    if (mas[i] % k == 0) {
      if (countt.count(mas[i] / k))
        p1[i] = countt[mas[i] / k];
      else
        p1[i] = 0;
    }
    countt[mas[i]]++;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (mas[i] % k == 0) {
      if (c2.count(mas[i] * k))
        p2[i] = c2[mas[i] * k];
      else
        p2[i] = 0;
    }
    c2[mas[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    if (mas[i] % k == 0) p += (long long)p1[i] * p2[i];
  }
  cout << p;
  return 0;
}
