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;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e5+20;

#define pii pair<int,int>

int nxt[maxn],lst[maxn];

int val[maxn],lf[maxn],rf[maxn],vis[maxn],L,tag[maxn];
int n;

priority_queue<pii,vector<pii>,greater<pii> >q;

inline void init()
{
	n=read();L=read();
	REP(i,1,n)val[i]=read();
	REP(i,1,n+1)lst[i]=i-1,nxt[i-1]=i,lf[i]=rf[i]=1;
	REP(i,1,n)q.push(mkr(val[i],i));
}

ll ans;

inline void doing()
{
	while(!q.empty())
	{
		static int st[maxn],top; top=0;
		static int Lf[maxn],Rf[maxn];
		int u=q.top().se,VAL=val[u];
		for(int i=u;i<=n && val[i]==val[u];i=nxt[i])
			st[++top]=i,tag[i]=1;
		while(!q.empty() && tag[q.top().se])q.pop();
		ll sumlf=0;
		int j=1,Lst=0;
		REP(i,1,top)if(!vis[st[i]])ans++;
		REP(i,1,top)
		{
			if(!vis[st[i]])Lst=i;
			while(j<=Lst && j<=i-L+1)
				sumlf+=lf[st[j++]];
			ans+=sumlf*rf[st[i]];
		}
		int num=top/L;
		if(num)
		{
			REP(i,1,num)
			{
				Rf[i]=0;
				REP(j,L*i,min(L*i+L-1,top))Rf[i]+=rf[st[j]];
			}
			REP(i,1,num)
			{
				Lf[num-i+1]=0;
				DREP(j,top-L*i+1,max(top-L*i-L+2,1))Lf[num-i+1]+=lf[st[j]];
			}
			nxt[st[num]]=nxt[st[top]];
			lst[nxt[st[top]]]=st[num];
			REP(j,1,num)tag[st[j]]=0,vis[st[j]]=1,val[st[j]]=VAL+1,lf[st[j]]=Lf[j],rf[st[j]]=Rf[j],q.push(mkr(VAL+1,st[j]));
		}else nxt[lst[st[1]]]=n+1;
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}
