#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int idata = 2e5 + 7;
int i, j, k;
int judge, flag;
long long step[idata];
long long temp;
int n, m, t;
double maxx = 0, minn = inf;
long long cnt, len, sum, ans;
long long high, wigh;
map<long long, int> pre[2];
signed main() {
  while (cin >> n >> k) {
    memset(step, 0, sizeof step);
    for (i = 1; i <= n; i++) {
      cin >> step[i];
      pre[0][step[i]]++;
    }
    for (i = 1; i <= n; i++) {
      pre[0][step[i]]--;
      if (step[i] % k == 0) {
        ans += (long long)pre[1][step[i] / k] * pre[0][step[i] * k];
      }
      pre[1][step[i]]++;
    }
    cout << ans << endl;
  }
  return 0;
}
