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;

typedef long long lint;
typedef pair<int,int> pii;
typedef long double louble;

#define so(x) ((int)((x).size()))
#define fi first
#define se second

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007;

int n,lim,val[_];
pii bas[_];

inline lint finder(vector<pii> &v)
{
	lint ans=0,sum=0;
	for(int i=0,j=lim-1;j<so(v);i++,j++)sum+=v[i].fi,ans+=sum*v[j].se;
	return ans;
}

vector<pair<pii,pii>> f,g;
// <interval_L, interval_R>, <cntBeingL, cntBeingR>

int main()
{
	n=ty(),lim=ty();
	for(int i=1;i<=n;i++)val[i]=ty(),bas[i]=pii(val[i],i);

	sort(bas+1,bas+n+1);

	lint ans=n;
	int now=0,pos=1;
	
	while("pick the smallest values first")
	{
		if(f.empty()){if(pos>n)break;else now=bas[pos].fi;}
		else now++;

		while(pos<=n && bas[pos].fi==now)
			f.emplace_back(pii(bas[pos].se,bas[pos].se),pii(1,1)),pos++;
		sort(f.begin(),f.end());
		g.clear();
		
		for(int l=0,r=0;l<so(f);l=r+1)
		{
			r=l;
			while(r+1<so(f) && f[r].fi.se+1==f[r+1].fi.fi)r++;
			int len=r-l+1,llen=len/lim;
			if(llen<=0)continue;

			vector<pii> temp(len),temp1(llen),temp2(llen,pii(0,0));
			for(int i=0;i<llen;i++)
				temp1[i]=pii(f[l].fi.fi+i*lim,(i==llen-1)?f[r].fi.se:(f[l].fi.fi+i*lim+lim-1));
			for(int i=l,ll=1,rr=len;i<=r;i++,ll++,rr--)
			{
				temp[i-l]=f[i].se;
				if(ll>=lim)temp2[ll/lim-1].se+=f[i].se.se;
				if(rr>=lim)temp2[llen-rr/lim].fi+=f[i].se.fi;
			}
			ans+=finder(temp)-finder(temp2);
			for(int i=0;i<llen;i++)g.emplace_back(temp1[i],temp2[i]);
		}

		f.swap(g);
	}

	printf("%lld\n",ans);

	return 0;
}
