#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
int n, l, x[MAXN];
pair<int, int> y[MAXN];
long long calc(vector<pair<int, int>> &a) {
  long long ans = 0, sum = 0;
  for (unsigned i = l - 1, j = 0; i < a.size(); i++, j++) {
    sum += a[j].first;
    ans += a[i].second * sum;
  }
  return ans;
}
int main() {
  read(n), read(l);
  for (int i = 1; i <= n; i++) {
    read(x[i]);
    y[i] = make_pair(x[i], i);
  }
  sort(y + 1, y + n + 1);
  long long ans = n;
  vector<pair<pair<int, int>, pair<int, int>>> a, b;
  for (int val = 1, pos = 1; val <= n + 64; val++) {
    while (val == y[pos].first)
      a.emplace_back(make_pair(y[pos].second, y[pos].second), make_pair(1, 1)),
          pos++;
    b.clear(), sort(a.begin(), a.end());
    for (unsigned i = 0, j; i < a.size(); i = j + 1) {
      j = i;
      while (j + 1 < a.size() && a[j + 1].first.first == a[j].first.second + 1)
        j++;
      int len = j - i + 1, cnt = len / l;
      if (cnt != 0) {
        vector<pair<int, int>> cur, where, value;
        for (unsigned k = i; k <= j; k++) cur.push_back(a[k].second);
        ans += calc(cur);
        for (int k = 1; k <= cnt; k++) {
          where.emplace_back(
              a[i].first.first + k - 1,
              (k == cnt) ? a[j].first.second : a[i].first.first + k - 1);
          value.emplace_back(0, 0);
        }
        for (unsigned k = i; k <= j; k++) {
          int tl = k - i + 1, tr = j - k + 1;
          if (tl >= l) value[tl / l - 1].second += a[k].second.second;
          if (tr >= l) value[cnt - tr / l].first += a[k].second.first;
        }
        ans -= calc(value);
        for (unsigned k = 0; k < where.size(); k++)
          b.emplace_back(where[k], value[k]);
      }
    }
    a = b;
  }
  writeln(ans);
  return 0;
}
