/**
 *    author:  tourist
 *    created: 08.12.2019 08:24:29       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, len;
  cin >> n >> len;
  vector<int> a(n);
  vector<int> L(n);
  vector<int> R(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    L[i] = 1;
    R[i] = 1;
  }
  long long ans = n;
  set<pair<int, int>> s;
  set<int> alive;
  for (int i = 0; i < n; i++) {
    s.emplace(a[i], i);
    alive.insert(i);
  }
  while (!s.empty()) {
    int id = s.begin()->second;
    s.erase(s.begin());
    vector<int> pos(1, id);
    while (true) {
      auto it = alive.lower_bound(pos.back() + 1);
      if (it == alive.end() || a[*it] != a[id]) {
        break;
      }
      s.erase(make_pair(a[*it], *it));
      pos.push_back(*it);
    }
    int sz = (int) pos.size();
    if (sz < len) {
      continue;
    }
    {
      long long sumL = 0;
      for (int i = len - 1; i < sz; i++) {
        sumL += L[pos[i - len + 1]];
        ans += sumL * R[pos[i]];
      }
    }
    for (int x : pos) {
      alive.erase(x);
    }
    int new_sz = sz / len;
    vector<int> newL(new_sz);
    vector<int> newR(new_sz);
    for (int i = 0; i < sz; i++) {
      if (i >= len - 1) {
        newR[(i - (len - 1)) / len] += R[pos[i]];
      }
      if (i <= sz - len) {
        newL[new_sz - 1 - ((sz - len) - i) / len] += L[pos[i]];
      }
    }
    for (int i = 0; i < new_sz; i++) {
      alive.insert(pos[i]);
      L[pos[i]] = newL[i];
      R[pos[i]] = newR[i];
      a[pos[i]] += 1;
      s.emplace(a[pos[i]], pos[i]);
    }
    if (len <= new_sz) {
      long long sumL = 0;
      for (int i = len - 1; i < new_sz; i++) {
        sumL += L[pos[i - len + 1]];
        ans -= sumL * R[pos[i]];
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
