#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  return getchar();
  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;
vector<pair<int, int> > num;
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[2];
int main() {
  read(n), read(L);
  for (int i = 1; i <= n; ++i) {
    int x;
    read(x);
    num.push_back(make_pair(x, i));
  }
  sort(num.begin(), num.end());
  long long an = n;
  int cur = 0, now = 0, pt = 0;
  while (true) {
    cur ^= 1;
    rec[cur ^ 1].clear();
    if (rec[cur].size() == 0) {
      if (pt < num.size())
        now = num[pt].first;
      else
        break;
    } else
      ++now;
    while (pt < num.size() && num[pt].first == now)
      rec[cur].push_back(node(num[pt].second, num[pt].second, 1, 1)), ++pt;
    sort(rec[cur].begin(), rec[cur].end());
    for (int l = 0, r; l < rec[cur].size(); l = r + 1) {
      static node tmp[maxn];
      r = l;
      while (r < rec[cur].size() && rec[cur][r + 1].l == rec[cur][r].r + 1) ++r;
      if (r - l + 1 < L) continue;
      for (int j = r, sum = 0; j >= l + L - 1; --j) {
        sum += rec[cur][j].R;
        an += (long long)rec[cur][j - L + 1].L * sum;
      }
      int k = (r - l + 1) / L;
      tmp[0].l = rec[cur][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[cur][r].r;
      for (int j = l; j <= r; ++j) {
        int x = j - l + 1, y = r - j + 1;
        if (x >= L) tmp[x / L].R += rec[cur][j].R;
        if (y >= L) tmp[k - y / L + 1].L += rec[cur][j].L;
      }
      for (int j = k, sum = 0; j >= L; --j) {
        sum += tmp[j].R;
        an -= (long long)tmp[j - L + 1].L * sum;
      }
      for (int j = 1; j <= k; ++j) rec[cur ^ 1].push_back(tmp[j]);
    }
  }
  printf("%lld\n", an);
  return 0;
}
