#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100005;
long long int sol = 0;
int N, K;
int a[maxn];
map<long long int, int> lijevo, desno;
void rijesi() {
  for (int i = 0; i < N; i++) desno[1LL * a[i]]++;
  for (int i = 0; i < N; i++) {
    desno[1LL * a[i]]--;
    int x = 0;
    if (a[i] % K == 0) x = lijevo[1LL * a[i] / K];
    sol += 1LL * x * desno[1LL * a[i] * K];
    lijevo[1LL * a[i]]++;
  }
  printf("%I64d", sol);
}
void ucitaj() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) scanf("%d", &a[i]);
}
int main(void) {
  ucitaj();
  rijesi();
  return 0;
}
