#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 200100;
map<int, long long> m1;
map<int, long long> m2;
int a[maxn];
int main() {
  m1.clear();
  m2.clear();
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = n; i >= 1; i--) {
    if ((long long)a[i] * k <= 1e9 && (long long)a[i] * k >= -1e9) {
      sum += m2[a[i] * k];
      m2[a[i]] += m1[a[i] * k];
    }
    m1[a[i]]++;
  }
  cout << sum << endl;
}
