#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long int n, k, ans = 0;
long long int arr[500005];
void solve() {
  cin >> n >> k;
  map<long long int, long long int> mpp, tot, till;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
    tot[arr[i]]++;
  }
  for (long long int i = 1; i <= n; i++) {
    till[arr[i]]++;
    if ((arr[i] % (k)) == 0) {
      long long int a = arr[i] / k, b = arr[i] * k;
      ans = ans + (mpp[a]) * (tot[b] - till[b]);
    }
    mpp[arr[i]]++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    solve();
    cout << "\n";
  }
}
