#include <bits/stdc++.h>
using namespace std;
int a[200005];
int a1[200005];
long long visit[200005] = {0}, count2[200005] = {0};
map<int, int> mapi;
vector<pair<int, int> > v;
int main() {
  std::ios::sync_with_stdio(false);
  int n, k, i, hi, ans1 = -1, ans2 = -1, ans3 = -1, j;
  long long count1[200005] = {0};
  long long x, y;
  long long sum = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back(make_pair(a[i], i));
  }
  if (n <= 2)
    cout << 0 << endl;
  else {
    sort(v.begin(), v.end());
    {
      for (i = 0; i < n; i++) {
        x = v[i].first;
        x *= k;
        int lo = 0;
        hi = n - 1;
        while (lo <= hi) {
          int mid = (lo + hi) / 2;
          if (v[mid].first > x) {
            hi = mid - 1;
          } else {
            lo = mid + 1;
            ans1 = mid;
          }
        }
        lo = 0;
        hi = n - 1;
        while (lo <= hi) {
          int mid = (lo + hi) / 2;
          if (v[mid].first < x) {
            lo = mid + 1;
          } else {
            hi = mid - 1;
            ans2 = mid;
          }
        }
        if (v[ans1].second > v[i].second) {
          lo = ans2;
          hi = ans1;
          while (lo <= hi) {
            int mid = (lo + hi) / 2;
            if (v[mid].second <= v[i].second) {
              lo = mid + 1;
            } else {
              hi = mid - 1;
              ans3 = mid;
            }
          }
          if (v[ans1].first == x && v[ans2].first == x) {
            count1[v[i].second] += ans1 - ans3 + 1;
            a1[v[i].second] = ans3;
          } else {
            count1[v[i].second] = 0;
          }
        }
        if (v[i].first % k == 0) {
          y = v[i].first / k;
          int lo = 0;
          hi = n - 1;
          while (lo <= hi) {
            int mid = (lo + hi) / 2;
            if (v[mid].first > y) {
              hi = mid - 1;
            } else {
              lo = mid + 1;
              ans1 = mid;
            }
          }
          lo = 0;
          hi = n - 1;
          while (lo <= hi) {
            int mid = (lo + hi) / 2;
            if (v[mid].first < y) {
              lo = mid + 1;
            } else {
              hi = mid - 1;
              ans2 = mid;
            }
          }
          if (v[ans2].second < v[i].second) {
            lo = ans2;
            hi = ans1;
            while (lo <= hi) {
              int mid = (lo + hi) / 2;
              if (v[mid].second >= v[i].second) {
                hi = mid - 1;
              } else {
                lo = mid + 1;
                ans3 = mid;
              }
            }
            if (v[ans1].first == y && v[ans2].first == y) {
              count2[v[i].second] += ans3 - ans2 + 1;
            } else {
              count2[v[i].second] = 0;
            }
          }
        } else
          count2[v[i].second] = 0;
      }
      for (i = 0; i < n; i++) {
        x = count1[i];
        x *= count2[i];
        sum += x;
      }
      cout << sum << endl;
    }
  }
}
