#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 2e5 + 10;

int n, L, x[N];
pi y[N];
vector <pair<pi, pi> > a, b;

ll calc(vector<pi> & s) {
  ll ans = 0, sum = 0;
  for (int i = L - 1, j = 0; i < (signed) s.size(); i++, j++) {
    sum += s[j].first;
    ans += s[i].second * sum;
  }
  return ans;
}

int main() {
#ifdef dream_maker
//  freopen("tst.in", "r", stdin);
#else
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
#endif
  n = read(), L = read();
  for (int i = 1; i <= n; i++) {
    x[i] = read();
    y[i] = make_pair(x[i], i);
  }
  sort(y + 1, y + n + 1);
  ll ans = n;
  int val = 0, cur = 1;
  while (1) {
    if (a.empty()) {
      if (cur > n) break;
      else val = y[cur].first;
    } else {
      ++val;
    }
    while (val == y[cur].first) {
      a.emplace_back(pi(y[cur].second, y[cur].second), pi(1, 1));
      cur++;
    }
    b.clear();
    sort(a.begin(), a.end());
    for (int l = 0, r; l < (signed) a.size(); l = r + 1) {
      r = l;
      while (r + 1 < (signed) a.size() && a[r + 1].first.first == a[r].first.second + 1) r++;
      int len = r - l + 1, cnt = len / L;
      if (cnt) {
        vector<pi> now, pos, val;
        for (int k = l; k <= r; k++) now.push_back(a[k].second);
        ans += calc(now);
        for (int k = 0; k < cnt; k++) {
          pos.emplace_back(a[l].first.first + k, (k == cnt - 1) ? a[r].first.second : a[l].first.first + k);
          val.emplace_back(0, 0);
        }
        for (int k = l; k <= r; k++) {
          int tl = k - l + 1, tr = r - k + 1;
          if (tl >= L) val[tl / L - 1].second += a[k].second.second;
          if (tr >= L) val[cnt - tr / L].first += a[k].second.first;
        }
        ans -= calc(val);
        for (int k = 0; k < cnt; k++) b.emplace_back(pos[k], val[k]);
      }
    }
    a = b;
  }
  cout << ans << endl;
  return 0;
}
