#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=200005;
int n,l,p,v,a[N];
ll ans;
vector<pair<int,int> > b,t1,t2,t3;
vector<pair<pair<int,int>,pair<int,int> > > x,y;
ll calc(vector<pair<int,int> > &x){
	ll sum=0,res=0;
	for(unsigned i=l-1,j=0;i<x.size();i++,j++){
		sum+=x[j].first;
		res+=x[i].second*sum;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b.push_back(make_pair(a[i],i));
	}
	sort(b.begin(),b.end());
	while(1){
		if(x.empty()){
			if(p==n){
				break;
			}else{
				v=b[p].first;
			}
		}else{
			v++;
		}
		while(p<n&&b[p].first==v){
			x.push_back(make_pair(make_pair(b[p].second,b[p].second),make_pair(1,1)));
			p++;
		}
		y.clear();
		sort(x.begin(),x.end());
		for(unsigned i=0,j;i<x.size();i=j+1){
			j=i;
			while(j+1<x.size()&&x[j+1].first.first==x[j].first.second+1){
				j++;
			}
			int len=j-i+1,tot=len/l;
			if(tot){
				t1.clear();
				for(unsigned k=i;k<=j;k++){
					t1.push_back(x[k].second);
				}
				ans+=calc(t1);
				t2.clear();
				t3.clear();
				for(int k=1;k<=tot;k++){
					t2.push_back(make_pair(x[i].first.first+k-1,k==tot?x[j].first.second:x[i].first.first+k-1));
					t3.push_back(make_pair(0,0));
				}
				for(unsigned k=i;k<=j;k++){
					int l1=k-i+1,l2=j-k+1;
					if(l1>=l){
						t3[l1/l-1].second+=x[k].second.second;
					}
					if(l2>=l){
						t3[tot-l2/l].first+=x[k].second.first;
					}
				}
				ans-=calc(t3);
				for(int k=0;k<tot;k++){
					y.push_back(make_pair(t2[k],t3[k]));
				}
			}
		}
		x=y;
	}
	printf("%lld\n",ans+n);
	return 0;
}