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<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (200010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
#define int long long
#define fi first
#define se second
#define mkp make_pair
int n,m,now,a[N]; pair<int,int> pos[N];
LL ans; vector<pair<pair<int,int>,pair<int,int> > >t,tmp;
vector<pair<int,int> > wk,pp;
int calc(vector<pair<int,int> > &a){
	LL sum=0,ans=0;
	for(int i=0,j=m-1;j<a.size();i++,j++)
	sum+=a[i].fi,ans+=sum*a[j].se;
	return ans;
}
signed main(){
	read(n),read(m),ans=n;
	for(int i=1;i<=n;i++)read(a[i]),pos[i]=mkp(a[i],i);
	sort(pos+1,pos+n+1);
	for(int p=1,val=0;p<=n||!t.empty();){
		if(t.empty())val=pos[p].fi;else val++;
		for(;pos[p].fi==val;p++)t.emplace_back(mkp(pos[p].se,pos[p].se),mkp(1,1));
		tmp.clear(),sort(t.begin(),t.end());
		for(int i=0,j=0;i<t.size();i=j+1){
			for(j=i;j+1<t.size()&&t[j+1].fi.fi==t[j].fi.se+1;j++);
			int len=j-i+1,cnt=len/m;
			if(cnt){
				wk.clear();
				for(int k=i;k<=j;k++)wk.push_back(t[k].se);
				ans+=calc(wk),wk.clear(),wk.resize(cnt),pp.clear();
				for(int k=1;k<=cnt;k++)
				pp.emplace_back(t[i].fi.fi+k-1,(k==cnt)?t[j].fi.se:t[i].fi.fi+k-1);
				for(int k=i;k<=j;k++){
					int l=k-i+1,r=j-k+1;
					if(l>=m)wk[l/m-1].se+=t[k].se.se;
					if(r>=m)wk[cnt-r/m].fi+=t[k].se.fi;
				}
				ans-=calc(wk);
				for(int k=0;k<pp.size();k++)tmp.emplace_back(pp[k],wk[k]);
			}
		}
		t=tmp;
	}
	cout<<ans;
}