#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;

int A[SIZE];

ll solve(vector <P> vec,int L)
{
	int n=vec.size();
	ll ret=0,sum=0;
	for(int i=L-1;i<n;i++)
	{
		sum+=vec[i-L+1].first;
		ret+=sum*vec[i].second;
	}
	return ret;
}
int main()
{
	int n,L;
	scanf("%d %d",&n,&L);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	if(L==1)
	{
		printf("%lld\n",(ll) n*(ll) (n+1)/2);
		return 0;
	}
	vector <P> all;
	for(int i=0;i<n;i++) all.push_back(P(A[i],i));
	sort(all.begin(),all.end());
	int now=-1,pos=0;
	vector <PP> vec;
	ll ret=n;
	while(1)
	{
		if(vec.empty())
		{
			if(pos==all.size()) break;
			now=all[pos].first;
		}
		while(pos<all.size()&&all[pos].first==now)
		{
			int v=all[pos++].second;
			vec.push_back(PP(P(v,v),P(1,1)));
		}
		sort(vec.begin(),vec.end());
		//printf("%d : ",now);
		//for(int i=0;i<vec.size();i++) printf("[%d %d : %d %d] ",vec[i].first.first,vec[i].first.second,vec[i].second.first,vec[i].second.second);puts("");
		vector <PP> nxt;
		for(int i=0;i<vec.size();)
		{
			int f=i++;
			for(;i<vec.size()&&vec[i].first.first==vec[i-1].first.second+1;i++);
			vector <P> now;
			for(int j=f;j<i;j++) now.push_back(vec[j].second);
			if(now.size()>=L)
			{
				ret+=solve(now,L);
				int c=now.size()/L;
				vector <P> v1,v2;
				for(int j=0;j<c;j++)
				{
					int s=vec[f].first.first+j,t=s;
					if(j==c-1) t=vec[i-1].first.second;
					v1.push_back(P(s,t));
					v2.push_back(P(0,0));
				}
				for(int j=f;j<i;j++)
				{
					int l=j-f+1,r=i-j;
					if(l>=L)
					{
						v2[l/L-1].second+=vec[j].second.second;
					}
					if(r>=L)
					{
						v2[c-r/L].first+=vec[j].second.first;
					}
				}
				ret-=solve(v2,L);
				for(int j=0;j<c;j++) nxt.push_back(PP(v1[j],v2[j]));
			}
		}
		vec=nxt;
		now++;
	}
	printf("%lld\n",ret);
	return 0;
}
