#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>

using std::sort;
using std::vector;
using std::min;

typedef long long ll;
typedef std::pair<int,int> pii;

bool check (int a, int b, int k) {
  assert (a <= b);
  return a >= (b + k - 1) / k;
}

int main() {
  assert(freopen("game.in", "r", stdin));
  assert(freopen("game.out", "w", stdout));

  int n, k;
  scanf("%d%d", &n, &k);
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  vector <pii> b;
  for (int i = 0; i < n; ) {
    int j = i;
    while (i < n && a[i] == a[j]) {
      ++i;
    }
    b.push_back(pii(a[j], i - j));
  }
  ll ans = 0;
  for (int i = 0, j = 1, cnt1 = 0, cnt2 = 0; i < int(b.size()); ) {
    assert (i < j && check(b[i].first, b[j - 1].first, k));
    while (j < int(b.size()) && check(b[i].first, b[j].first, k)) {
      ++cnt1;
      if (b[j].second >= 2) {
        ++cnt2;
      }
      ++j;
    }

    switch (b[i].second) {
      default:
        ans += 1;
      case 2:
        ans += 3 * cnt1;
      case 1:
        ans += 3 * (cnt2 + ll(cnt1) * (cnt1 - 1));
    }

    if (i + 1 == j) {
      ++i, ++j;
      assert (!cnt1 && !cnt2);
    } else {
      ++i;
      --cnt1;
      if (b[i].second >= 2) {
        --cnt2;
      }
    }
  }
  std::cout << ans << std::endl;

  return 0;
}
