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>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	char ch=getchar();int f=0;x=0;
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005,inf=1e9+99;
struct node{
	int level,mx;
	vi pre,suf;
	node(int _x=inf){
		level=_x,mx=1;
		if(_x>=0)pre=suf={1};
	}
}stk[N],emp;
int a[N],n,L,top;
ll ans;

node merge(node a[],int n){
	static int sum[N],tot[N];
	rep(i,1,n)sum[i]=sum[i-1]+a[i].mx;
	if(sum[n]<L)return emp;
	tot[n+1]=0;
	per(i,n,1)tot[i]=tot[i+1]+a[i].pre[0];
	for(int l=1,r=1,q=1;r<=n;l++)
		per(i,a[l].mx,1){
			while(l==r)r++,q=1;
			while(r<=n&&i+sum[r-1]-sum[l]+q<L){
				q++;
				if(q<=a[r].mx)continue;
				r++,q=1;
			}
			if(r<=n){
				int A=a[l].suf[i-1]-(i<a[l].mx?a[l].suf[i]:0);
				int B=a[r].pre[q-1]+tot[r+1];
				ans+=(ll)A*B;
			}
		}
	node res(-1);
	res.level=a[1].level+1;
	res.mx=sum[n]/L;
	res.pre.resize(res.mx);
	res.suf.resize(res.mx);
	for(int i=1,cnt=0;i<=n;i++)
		rep(j,1,a[i].mx)
			if(++cnt>=L){
				int tmp=a[i].pre[j-1]-(j<a[i].mx?a[i].pre[j]:0);
				res.pre[cnt/L-1]+=tmp;
			}
	for(int i=n,cnt=0;i>=1;i--)
		rep(j,1,a[i].mx)
			if(++cnt>=L){
				int tmp=a[i].suf[j-1]-(j<a[i].mx?a[i].suf[j]:0);
				res.suf[cnt/L-1]+=tmp;
			}
	per(i,res.mx-1,1){
		res.pre[i-1]+=res.pre[i];
		res.suf[i-1]+=res.suf[i];
	}
	return res;
}

int main(){
	read(n),read(L),ans=n;
	rep(i,1,n)read(a[i]);
	a[n+1]=inf;
	rep(i,1,n){
		stk[++top]=node(a[i]);
		int flag=0;
		while(flag&&stk[top].level<inf||stk[top].level<a[i+1]){
			int cur=top;
			while(cur&&stk[cur].level==stk[top].level)
				cur--;
			stk[cur+1]=merge(stk+cur,top-cur);
			top=cur+1;
			if(stk[top].level==inf)flag=1,top--;
		}
		if(flag)stk[++top].level=inf;
	}
	cout<<ans<<endl;
	return 0;
}