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
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-25 16:54:48
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
#include<set>
#define pii std::pair<int,int>
const int N=200010;
i64 n,pre[N],suf[N],k,a[N],l[N],r[N],ans,s[N],l_[N],r_[N];
std::set<pii> S;
int q[N],m,m_;
int main()
{
	n=read(); k=read();
	fr(i,1,n) a[i]=read();
	fr(i,1,n) if(a[i]!=a[i-1]) S.insert(pii(a[i],i));
	fr(i,2,n){ pre[i]=i-1; suf[i-1]=i; }
	fr(i,1,n) l[i]=r[i]=1;
	while(!S.empty())
	{
		int u=S.begin()->second,v=u,na=a[u]+1; q[m=1]=u; S.erase(S.begin());
		suf[pre[u]]=pre[suf[v]]=0;
		while(a[suf[v]]==a[u]) q[++m]=(v=suf[v]);
		fr(i,1,m){ s[i]=s[i-1]+l[q[i]]; ans+=(l[q[i]]+s[std::max(i-k+1,0ll)])*r[q[i]]; }
//		fr(i,1,m) printf("+ %d %d\n",l[q[i]],r[q[i]]);
//		printf("+%d %d %d\n",int(m),int(na-1),int(ans));
		m_=m/k;
		if(!m_) continue;
		fr(i,1,m) s[i]=s[i-1]+l[q[i]];
		fr(i,1,m_) l_[i]=s[m-(m_-i+1)*k+1];
		fd(i,m_,2) l_[i]-=l_[i-1];
//		fr(i,1,m_) printf("%d%c",s[m-(m_-i+1)*k+1],i==end_i?'\n':' ');
		fr(i,1,m) s[i]=s[i-1]+r[q[i]];
		fr(i,1,m_) r_[i]=s[m]-s[i*k-1];
		fr(i,1,m_-1) r_[i]-=r_[i+1];
//		fr(i,1,m_) printf("- %d %d\n",l_[i],r_[i]);
		fr(i,1,m_){ l[q[i]]=l_[i]; r[q[i]]=r_[i]; a[q[i]]=na; }
		suf[pre[u]]=u; pre[suf[v]]=q[m_]; suf[q[m_]]=suf[v]; m=m_;
		fr(i,1,m){ s[i]=s[i-1]+l[q[i]]; ans-=(l[q[i]]+s[std::max(i-k+1,0ll)])*r[q[i]]; }
		if(a[pre[u]]!=na) S.insert(pii(na,u));
		if(a[suf[v]]==na) S.erase(pii(na,suf[v]));
//		printf("-%d %d %d\n",int(m),int(na-1),int(ans));
	}
	printf("%lld\n",ans);
	return 0;
}