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<iostream>
#include<cstdio>
#include<queue>
#include<set>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
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];
ll ans;
struct cmp{
	bool operator()(int x,int y)
		{return a[x]!=a[y]?a[x]<a[y]:x<y;}
};
set<int,cmp>q;
ll calc(int m){
	ll ret=0,S=0;
	FOR(i,1,m){
		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(i,1,n) scanf("%d",&a[i]);
	FOR(i,1,n){
		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;
		//FOR(i,1,m) cout<<p[i]<<' ';cout<<'\n';
		// FOR(i,1,m) cout<<a[p[i]]<<' ';cout<<'\n';
		p[0]=pr[p[1]],p[m+1]=nx[p[m]];
		ans+=calc(m);t=m/L;//cout<<"ans="<<ans<<'\n';
		FOR(i,1,t) tl[i]=tr[i]=0;
		FOR(i,1,m) tr[i/L]+=r[p[i]],tl[t-(m-i+1)/L+1]+=l[p[i]];
		FOR(i,1,t) 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(i,1,t) cout<<l[p[i]]<<'-'<<r[p[i]]<<' ';cout<<'\n';
		FOR(i,0,t) pr[p[i+1]]=p[i],nx[p[i]]=p[i+1];
		pr[0]=nx[0]=0;
		if(!t) nx[p[0]]=pr[p[1]]=0;
		ans-=calc(t);//cout<<"ans="<<ans<<'\n';
	}
	cout<<ans<<'\n';
}
