#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=200000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}

#define pii pair<int,int>
#define mp make_pair 
int m,n,l;
int a[NN]={};
int v[NN][2]={};
int xt[NN]={};
int pre[NN]={};
set<pii> all;
int tp[NN][2]={};
int sum[NN]={};
int id[NN]={};
int res[NN][2]={};
LL calc(int v[NN][2],int len){
	for(int i=1;i<=len;++i){
		sum[i]=sum[i-1]+v[i][1];
	}
	LL ans=0;
	for(int i=1;i+l-1<=len;++i){
		ans+=(LL)v[i][0]*(sum[len]-sum[i+l-2]);
	}
	return ans;
}
int main(){
	//open();
	n=read();
	l=read();
	LL ans=n;
	for(int i=1;i<=n;++i){
		a[i]=read();
		all.insert(mp(a[i],i));
		v[i][0]=v[i][1]=1;
		xt[i]=i+1;
		pre[i]=i-1;
	}
	while(!all.empty()){
		pii now=*all.begin();
		int val=now.first;
		int pos=now.second;
		int cnt=0;
		while(a[pos]==val){
			tp[++cnt][0]=v[pos][0];
			tp[cnt][1]=v[pos][1];
			id[cnt]=pos;
			all.erase(mp(val,pos));
			pos=xt[pos];
		}
		if(cnt>=l){
			ans+=calc(tp,cnt);
			int bcnt=cnt/l;
			for(int i=1;i<=bcnt;++i){
				res[i][0]=res[i][1]=0;
			}
			for(int i=l;i<=cnt;++i){
				res[i/l][1]+=tp[i][1];
			}
			for(int i=cnt-l+1;i>=1;--i){
				res[bcnt+1-(cnt+1-i)/l][0]+=tp[i][0];
			}
			ans-=calc(res,bcnt);
			for(int i=1;i<=bcnt;++i){
				int pos=id[i];
				all.insert(mp(val+1,pos));
				a[pos]=val+1;
				v[pos][0]=res[i][0];
				v[pos][1]=res[i][1];
			}
			xt[id[bcnt]]=xt[id[cnt]];
			pre[xt[id[bcnt]]]=id[bcnt];
		}
	}
	printf("%lld\n",ans);
	close();
	return 0;
}