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>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;

int main(){
	int n, l; 
	scanf("%d %d",&n,&l);
	vector<pair<int, vector<int>>> stk;
	lint dap = 0;
	for(int i=0; i<n; i++){
		int x; scanf("%d",&x);
		while(sz(stk) && stk.back().first < x){
			auto lev = stk.back().first;
			auto vec = stk.back().second;
			vector<int> nvec;
			stk.pop_back();
			if(sz(vec) < l){
				stk.clear();
				break;
			}
			for(int i=sz(vec)-l; i>=0; i-=l) nvec.push_back(vec[i]);
			reverse(all(nvec));
			if(sz(stk) && stk.back().first == lev + 1){
				int foo = stk.back().second.back();
				for(auto &j : nvec) stk.back().second.push_back(foo + j);
			}
			else{
				stk.emplace_back(lev + 1, nvec);
			}
		}
		dap += 1;
		if(sz(stk) && stk.back().first == x){
			int foo = stk.back().second.back();
			stk.back().second.push_back(foo + 1);
		}
		else{
			stk.emplace_back(x, vector<int>{1});
		}
		if(sz(stk.back().second) >= l) dap += stk.back().second[sz(stk.back().second) - l];
		int sum = sz(stk.back().second);
		int clvl = x;
		for(int j=sz(stk)-2; j>=0; j--){
			while(sum && clvl < stk[j].first){
				sum /= l;
				clvl++;
			}
			if(sum == 0) break;
			sum += sz(stk[j].second);
			if(sum >= l) dap += stk[j].second[min(sz(stk[j].second) - 1, sum - l)];
		}
	}
	printf("%lld\n", dap);
}
