#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200005], res;
map<long long, int> MAP_Left, MAP_Right;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 2; i <= n; ++i) MAP_Right[a[i]]++;
  for (int i = 2; i < n; ++i) {
    MAP_Left[a[i - 1]]++;
    MAP_Right[a[i]]--;
    if (a[i] % k) continue;
    long long x1 = a[i] / k;
    long long x3 = a[i] * k;
    res += 1ll * MAP_Left[x1] * MAP_Right[x3];
  }
  cout << res;
}
