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<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
inline int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
typedef long long ll;

int n,K;
int a[200010];
int p[200010];
bool cmp(int x,int y){
	if (a[x]^a[y]) return a[x]<a[y];
	return x<y;
}
struct Rec{
	int l,r,L,R;
}A[200010],B[200010]; int Atot,Btot;
ll ans;
int main()
{
	//freopen("data.in","r",stdin);
	//freopen("A.out","w",stdout);

	n=read(),K=read(); ans=n;
	for (int i=1;i<=n;i++) a[i]=read(),p[i]=i;
	sort(p+1,p+n+1,cmp);
	int pos=1,T;  //next considered; cur val
	while (1){
		if (!Atot){
			if (pos>n) break;
			T=a[p[pos]];
		}
		Btot=0;
		for (int i=1;i<=Atot;i++){
			while (pos<=n&&a[p[pos]]==T&&p[pos]<A[i].l)
				B[++Btot]=(Rec){p[pos],p[pos],1,1},pos++;
			B[++Btot]=A[i];
		}
		while (pos<=n&&a[p[pos]]==T)
			B[++Btot]=(Rec){p[pos],p[pos],1,1},pos++;
		Atot=Btot; for (int i=1;i<=Atot;i++) A[i]=B[i];
		for (int i=1,lst=-1,Ltot=0;i<=Atot;i++){
			if (i==1||A[i].l-1!=A[i-1].r) lst=i,Ltot=0;
			if (i-lst+1>=K) Ltot+=A[i-K+1].L;
			ans+=1LL*Ltot*A[i].R;
		}
		Btot=0;
		for (int i=1,j;i<=Atot;i=j+1){
			for (j=i;j+1<=Atot&&A[j].r+1==A[j+1].l;j++);
			if (j-i+1<K) continue;
			int t=(j-i+1)/K;
			for (int s=1,cur=K;s<=t;s++){
				B[++Btot]=(Rec){A[i].l+s-1,A[i].l+s-1,0,0};
				while (cur<=j-i+1&&cur/K==s){
					B[Btot].R+=A[i+cur-1].R;
					B[Btot].L+=A[j-cur+1].L;
					cur++;
				}
			}
			for (int a=Btot-t+1,b=Btot;a<b;swap(B[a++].L,B[b--].L));
			B[Btot].r=A[j].r;
		}
		Atot=Btot; for (int i=1;i<=Atot;i++) A[i]=B[i];
		for (int i=1,lst=-1,Ltot=0;i<=Atot;i++){
			if (i==1||A[i].l-1!=A[i-1].r) lst=i,Ltot=0;
			if (i-lst+1>=K) Ltot+=A[i-K+1].L;
			ans-=1LL*Ltot*A[i].R;
		}
		T++;
	}
	printf("%lld\n",ans);
	return 0;
}