#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
  long long int n, cn, i, p, q, k1, k2, k, s;
  while (cin >> n >> k) {
    long long int a[n + 5];
    k1 = k;
    k2 = k * k;
    map<long long int, long long int> mp, mp1;
    set<long long int> s1;
    set<long long int>::iterator it;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      mp[a[i]]++;
      s1.insert(a[i]);
    }
    s = 0;
    for (i = n; i >= 1; i--) {
      if (k == 1) {
        p = mp1[a[i]];
        q = mp[a[i]] - p - 1;
        s += (p * q);
      } else if (k > 1) {
        if (a[i] % k1 == 0) {
          p = a[i] / k1;
          q = p * k2;
          long long int r = mp[p] - mp1[p];
          if (a[i] == 0) r--;
          s += (r * mp1[q]);
        }
      }
      mp1[a[i]]++;
    }
    cout << s << endl;
  }
  return 0;
}
