#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *l = buf, *r = buf;
  return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)
             ? EOF
             : *l++;
}
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = nc();
  }
  x *= f;
}
const int maxn = 2e5 + 50;
const int maxp = maxn * 25;
int n, L, a[maxn];
int p, H[maxp];
struct node {
  int l, r, L, R;
  node(int l = 0, int r = 0, int L = 0, int R = 0) : l(l), r(r), L(L), R(R) {}
  inline bool operator<(const node &other) const { return l < other.l; }
};
vector<node> rec[maxp];
int main() {
  read(n), read(L);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    for (int j = 0; j < 25; ++j) H[++p] = a[i] + j;
  }
  sort(H + 1, H + p + 1), p = unique(H + 1, H + p + 1) - H - 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound(H + 1, H + p + 1, a[i]) - H;
    rec[a[i]].push_back(node(i, i, 1, 1));
  }
  long long an = n;
  for (int i = 1; i <= p; ++i)
    if (rec[i].size()) {
      sort(rec[i].begin(), rec[i].end());
      for (int l = 0, r; l < rec[i].size(); l = r + 1) {
        static node tmp[maxn];
        r = l;
        while (r < rec[i].size() && rec[i][r + 1].l == rec[i][r].r + 1) ++r;
        if (r - l + 1 < L) continue;
        assert(H[i + 1] == H[i] + 1);
        for (int j = r, sum = 0; j >= l + L - 1; --j) {
          sum += rec[i][j].R;
          an += (long long)rec[i][j - L + 1].L * sum;
        }
        int k = (r - l + 1) / L;
        tmp[0].l = rec[i][l].l - 1;
        for (int j = 1; j <= k; ++j) {
          tmp[j].l = tmp[j].r = tmp[j - 1].l + 1;
          tmp[j].L = tmp[j].R = 0;
        }
        tmp[k].r = rec[i][r].r;
        int t = r - L * k + 1;
        for (int j = l; j <= t; ++j) tmp[1].L += rec[i][j].L;
        for (int j = 2, now = t; j <= k; ++j, now += L) {
          for (int h = 1; h <= L; ++h) tmp[j].L += rec[i][now + h].L;
        }
        t = l + L * k - 1;
        for (int j = r; j >= t; --j) tmp[k].R += rec[i][j].R;
        for (int j = k - 1, now = t; j >= 1; --j, now -= L) {
          for (int h = 1; h <= L; ++h) tmp[j].R += rec[i][now - h].R;
        }
        for (int j = k, sum = 0; j >= L; --j) {
          sum += tmp[j].R;
          an -= (long long)tmp[j - L + 1].L * sum;
        }
        while (k) rec[i + 1].push_back(tmp[k--]);
      }
    }
  assert(an > 0);
  printf("%lld\n", an);
  return 0;
}
