#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    que;
int lst[MAXN + 5], nxt[MAXN + 5], N, L;
void link(int x, int y) { lst[y] = x, nxt[x] = y; }
void cut(int x) { nxt[lst[x]] = nxt[x], lst[nxt[x]] = lst[x]; }
bool check(int x, int y) { return nxt[x] == y; }
long long lf[MAXN + 5], rf[MAXN + 5], f1[MAXN + 5], f2[MAXN + 5];
vector<int> v1, v2;
long long solve(int x) {
  long long ret = 0, tmp = 0;
  int lt = v2.size(), lb = lst[v2[0]], rb = nxt[v2[lt - 1]];
  for (int i = 0; i < lt; i++) {
    if (i - L + 1 >= 0) tmp += lf[v2[i - L + 1]];
    if (i - L * L + 1 >= 0) tmp -= lf[v2[i - L * L + 1]];
    ret += tmp * rf[v2[i]], cut(v2[i]);
  }
  for (int i = 0; i < lt; i++)
    f1[v2[i]] = lf[v2[i]], f2[v2[i]] = rf[v2[i]], lf[v2[i]] = rf[v2[i]] = 0;
  int c = lt / L;
  if (c) {
    for (int i = L - 1; i < lt; i++) {
      int t = (i + 1) / L - 1;
      rf[v2[t]] += f2[v2[i]];
    }
    for (int i = lt - L; i >= 0; i--) {
      int t = c - (lt - i) / L;
      lf[v2[t]] += f1[v2[i]];
    }
    for (int i = 1; i < c; i++) link(v2[i - 1], v2[i]);
    link(lb, v2[0]), link(v2[c - 1], rb);
    for (int i = 0; i < c; i++) que.push(make_pair(x + 1, v2[i]));
  }
  v2.clear();
  return ret;
}
int main() {
  scanf("%d%d", &N, &L);
  for (int i = 1; i <= N; i++) {
    int x;
    scanf("%d", &x);
    que.push(make_pair(x, i)), link(i, i + 1);
    lf[i] = rf[i] = 1;
  }
  long long ans = 0;
  link(0, 1);
  while (!que.empty()) {
    int x = que.top().first;
    v1.clear();
    while (!que.empty() && que.top().first == x)
      v1.push_back(que.top().second), que.pop();
    v2.clear();
    v2.push_back(v1[0]);
    for (int i = 1; i < v1.size(); i++) {
      if (!check(v1[i - 1], v1[i])) ans += solve(x);
      v2.push_back(v1[i]);
    }
    ans += solve(x);
  }
  printf("%lld\n", ans + N);
}
