#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<long long, int>> a;
long long k, ans = 0;
int main() {
  cin >> n >> k;
  for (int i = 0, b; i < n; i++) {
    cin >> b;
    a.push_back({b, i});
  }
  sort(a.begin(), a.end(),
       [](pair<long long, int> xx, pair<long long, int> yy) {
         return xx.first < yy.first ||
                (xx.first == yy.first && xx.second < yy.second);
       });
  for (auto item : a) {
    if (item.first % k != 0) continue;
    long long lo = item.first / k, hi = item.first * k, cp = item.second;
    pair<long long, int> v1 = {lo, cp}, v2 = {hi, cp};
    auto lo1 =
        equal_range(a.begin(), a.end(), v1,
                    [](pair<long long, int> xx, pair<long long, int> yy) {
                      return xx.first < yy.first;
                    });
    auto hi1 =
        equal_range(a.begin(), a.end(), v2,
                    [](pair<long long, int> xx, pair<long long, int> yy) {
                      return xx.first < yy.first;
                    });
    if (lo1.second - lo1.first == 0) continue;
    if (hi1.second - hi1.first == 0) continue;
    auto lo2 =
        upper_bound(lo1.first, lo1.second, v1,
                    [](pair<long long, int> xx, pair<long long, int> yy) {
                      return xx.second <= yy.second;
                    });
    auto hi2 =
        lower_bound(hi1.first, hi1.second, v2,
                    [](pair<long long, int> xx, pair<long long, int> yy) {
                      return xx.second <= yy.second;
                    });
    ans += (long long)(lo2 - lo1.first) * (long long)(hi1.second - hi2);
  }
  cout << ans << endl;
  return 0;
}
