For a sequence S of positive integers and positive integers k and l, S is said to belong to level (k,l) when one of the following conditions is satisfied:

* The length of S is 1, and its only element is k.
* There exist sequences T_1,T_2,...,T_m (m \geq l) belonging to level (k-1,l) such that the concatenation of T_1,T_2,...,T_m in this order coincides with S.



Note that the second condition has no effect when k=1, that is, a sequence belongs to level (1,l) only if the first condition is satisfied.

Given are a sequence of positive integers A_1,A_2,...,A_N and a positive integer L. Find the number of subsequences A_i,A_{i+1},...,A_j (1 \leq i \leq j \leq N) that satisfy the following condition:

* There exists a positive integer K such that the sequence A_i,A_{i+1},...,A_j belongs to level (K,L).

Constraints

* 1 \leq N \leq 2 \times 10^5
* 2 \leq L \leq N
* 1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:


N L
A_1 A_2 ... A_N


Output

Print the number of subsequences A_i,A_{i+1},...,A_j (1 \leq i \leq j \leq N) that satisfy the condition.

Examples

Input

9 3
2 1 1 1 1 1 1 2 3


Output

22


Input

9 2
2 1 1 1 1 1 1 2 3


Output

41


Input

15 3
4 3 2 1 1 1 2 3 2 2 1 1 1 2 2


Output

31
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = n;
  vector<int> l(n), r(n);
  set<pair<int, int>> st;
  set<int> cur;
  for (int i = 0; i < n; ++i) {
    l[i] = r[i] = 1;
    st.emplace(a[i], i);
    cur.insert(i);
  }
  while (!st.empty()) {
    int p = st.begin()->second;
    st.erase(st.begin());
    vector<int> pos(1, p);
    while (true) {
      auto it = cur.lower_bound(pos.back() + 1);
      if (it == cur.end() || a[*it] != a[p]) {
        break;
      }
      st.erase(make_pair(a[p], *it));
      pos.push_back(*it);
    }
    int s = pos.size();
    if (s >= m) {
      for (int p : pos) {
        cur.erase(p);
      }
      long long pref = 0;
      for (int i = m - 1; i < s; ++i) {
        pref += l[pos[i - m + 1]];
        ans += pref * r[pos[i]];
      }
      int new_s = s / m;
      vector<int> new_l(new_s), new_r(new_s);
      for (int i = 0; i < s; ++i) {
        int p = pos[i];
        if (i >= m - 1) {
          new_r[(i - m + 1) / m] += r[p];
        }
        if (i + m <= s) {
          new_l[new_s - 1 - (s - m - i) / m] += l[p];
        }
      }
      for (int i = 0; i < new_s; ++i) {
        int p = pos[i];
        l[p] = new_l[i]; r[p] = new_r[i];
        st.emplace(++a[p], p);
        cur.insert(p);
      }
      if (new_s >= m) {
        pref = 0;
        for (int i = m - 1; i < new_s; ++i) {
          pref += l[pos[i - m + 1]];
          ans -= pref * r[pos[i]];
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
