#include <bits/stdc++.h>
using namespace std;
long long int n, k, arr[200001];
pair<long long int, long long int> p[200001];
set<long long int> s;
bool cmp(pair<long long int, long long int>& a,
         pair<long long int, long long int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
void print() {
  for (int j = 0; j < n; j++)
    cout << "(" << p[j].first << " " << p[j].second << ")   ";
  cout << endl;
  return;
}
void build() {
  cin >> n >> k;
  for (int j = 0; j < n; j++) {
    cin >> p[j].first;
    arr[j] = p[j].first;
    p[j].second = j;
    s.insert(arr[j]);
  }
  sort(p, p + n, cmp);
  return;
}
long long int foo1(int l, int r, long long int finds, int flag) {
  if (l == r) return l;
  if (l + 1 == r) {
    if (flag) {
      if (p[r].first <= finds) return r;
      return l;
    }
    if (p[l].first >= finds) return l;
    return r;
  }
  int mid = (l + r) / 2;
  if (flag) {
    if (p[mid].first > finds) return foo1(l, mid, finds, flag);
    return foo1(mid, r, finds, flag);
  }
  if (p[mid].first >= finds) return foo1(l, mid, finds, flag);
  return foo1(mid + 1, r, finds, flag);
}
long long int foo2(int l, int r, long long int finds) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  if (p[mid].second >= finds) return foo2(l, mid, finds);
  return foo2(mid + 1, r, finds);
}
long long int solve() {
  long long int ans = 0;
  for (int j = 1; j < n - 1; j++) {
    if (arr[j] % k != 0) continue;
    if (s.find(arr[j] / k) == s.end() || s.find(arr[j] * k) == s.end())
      continue;
    pair<long long int, long long int> pair1, pair2;
    pair1.first = foo1(0, n - 1, arr[j] / k, 0);
    pair1.second = foo1(0, n - 1, arr[j] / k, 1);
    pair2.first = foo1(0, n - 1, arr[j] * k, 0);
    pair2.second = foo1(0, n - 1, arr[j] * k, 1);
    int pos1 = foo2(pair1.first, pair1.second, j);
    int pos2 = foo2(pair2.first, pair2.second, j);
    while (pos1 >= pair1.first && p[pos1].second >= j) pos1--;
    while (pos2 <= pair2.second && p[pos2].second <= j) pos2++;
    if (pos1 < pair1.first || pos2 > pair2.second) continue;
    ans += (pos1 - pair1.first + 1) * (pair2.second - pos2 + 1);
  }
  return ans;
}
int main() {
  build();
  cout << solve() << endl;
  return 0;
}
