#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n, L, a[N], pr[N], nx[N], l[N], r[N];
int vi[N], tl[N], tr[N], p[N];
long long ans;
struct cmp {
  bool operator()(int x, int y) { return a[x] != a[y] ? a[x] < a[y] : x < y; }
};
set<int, cmp> q;
long long calc(int m) {
  long long ret = 0, S = 0;
  for (int i = 1; i <= m; i++) {
    if (i >= L) S += l[p[i - L + 1]];
    ret += 1ll * S * r[p[i]];
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &L);
  ans = n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    pr[i] = i - 1, nx[i] = i == n ? 0 : i + 1;
    l[i] = r[i] = 1;
    q.insert(i);
  }
  while (q.size()) {
    int u = *q.begin(), v, m, t, w = a[u];
    for (m = 0, v = u; v && a[v] == w; v = nx[v]) q.erase(v), p[++m] = v;
    p[0] = pr[p[1]], p[m + 1] = nx[p[m]];
    ans += calc(m);
    t = m / L;
    for (int i = 1; i <= t; i++) tl[i] = tr[i] = 0;
    for (int i = 1; i <= m; i++)
      tr[i / L] += r[p[i]], tl[t - (m - i + 1) / L + 1] += l[p[i]];
    for (int i = 1; i <= t; i++)
      p[i] = v = p[(i - 1) * L + 1], l[v] = tl[i], r[v] = tr[i], a[v] = w + 1,
      q.insert(v);
    p[t + 1] = p[m + 1];
    for (int i = 0; i <= t; i++) pr[p[i + 1]] = p[i], nx[p[i]] = p[i + 1];
    pr[0] = nx[0] = 0;
    ans -= calc(t);
  }
  cout << ans << '\n';
}
