#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int Nmax = 100005;
int count_one(vector<int> s) {
  int ct = 0;
  int i = 0;
  while (i < s.size()) {
    if (s[i] == 1) ++ct;
    ++i;
  }
  return ct;
}
int count_zero(string s, int index) {
  int i = 0;
  int ct = 0;
  while (s[i] != '1' && i < s.length()) {
    ++ct;
    ++i;
  }
}
int gcd(int a, int b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
bool isPrime(int n) {
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return 0;
  return 1;
}
void binaryRepresentation(int x) {
  for (int i = 31; i >= 0; i--) {
    if (x & (1 << i))
      cout << "1";
    else
      cout << "0";
  }
}
void DFS(vector<vector<int> > &adj, int u, vector<bool> &visit,
         vector<int> &dist, vector<int> &freq) {
  visit[u] = true;
  for (int i = 0; i < adj[u].size(); i++) {
    int x = adj[u][i];
    if (!visit[x]) {
      dist[x] = dist[u] + 1;
      freq[u]++;
      DFS(adj, adj[u][i], visit, dist, freq);
    }
  }
}
bool check(string a, string b) {
  vector<int> first(26, 0);
  vector<int> second(26, 0);
  for (int i = 0; i < a.length(); i++) {
    first[a[i] - 'a']++;
    second[b[i] - 'a']++;
  }
  if (first != second)
    return false;
  else
    return true;
}
long long combination(long long n, long long r) {
  if (r == n || r == 0) {
    return 1;
  }
  return combination(n - 1, r - 1) + combination(n - 1, r);
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second > b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<int> ar(n);
  map<long long, long long> right;
  map<long long, long long> left;
  for (long long i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long ans = 0;
  for (long long i = n - 1; i >= 0; i--) {
    ans += right[ar[i] * k];
    right[ar[i]] += left[ar[i] * k];
    left[ar[i]]++;
  }
  cout << ans << "\n";
  return 0;
}
