//copy from https://atcoder.jp/contests/agc037/submissions/7059910
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mem(x,v) memset(x,v,sizeof(x))
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define gc getchar
#define pc putchar
#define fi first
#define se second
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);pc('\n');}
inline void wri(ll x){write(x);pc(' ');}
const int maxn = 2e5+233;
int n,l,a[maxn];
pii b[maxn];
vector<pair<pii,pii> > f,g;
ll calc(vector<pii> &v){
	ll res = 0 ,sum = 0;
	for(unsigned i=0,j=l-1;j<v.size();++i,++j)
		sum+=v[i].fi,res+=sum*v[j].se;
	return res;
}
int main(){
	n = read(),l = read();
	Rep(i,1,n){
		a[i] = read();
		b[i] = make_pair(a[i],i);
	}sort(b+1,b+1+n);
	int pos = 0;
	ll res = n,val = 0;
	for(;;){
//		printf("val = %d\n",val);
		if(f.empty()){
			if(pos > n) break;
			val = b[pos].fi;
		} else ++val;
		while(val == b[pos].fi){f.push_back({{b[pos].se,b[pos].se},{1,1}});pos++;}
		g.clear();sort(f.begin(),f.end());
		for(unsigned i=0,j=i;i<f.size();i=++j){
			while(j+1<f.size()&&f[j+1].fi.fi==f[j].fi.se+1)++j;
			int len=j-i+1,cnt=len/l;
			if(cnt){
				vector<pii> tmp,ff,gg;
				Rep(k,i,j) tmp.push_back(f[k].se);
				res += calc(tmp);
				Rep(k,1,cnt){
					ff.push_back({f[i].fi.fi+k-1,(k==cnt)?f[j].fi.se:f[i].fi.fi+k-1});
					gg.push_back({0,0});
				}
				Rep(k,i,j){
					int tl=k-i+1,tr=j-k+1;
					if(tl>=l) gg[tl/l-1].se += f[k].se.se;
					if(tr>=l) gg[cnt-tr/l].fi += f[k].se.fi;
				}
				res -= calc(gg);
				rep(k,0,cnt) g.push_back({ff[k],gg[k]});
			}
		}f = g;
	}
	writeln(res);
	return 0;
}