#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e5+20;

#define pii pair<int,int>

int nxt[maxn],lst[maxn];

int val[maxn],lf[maxn],rf[maxn],vis[maxn],L,tag[maxn];
int n;

priority_queue<pii,vector<pii>,greater<pii> >q;

inline void init()
{
	n=read();L=read();
	REP(i,1,n)val[i]=read();
	REP(i,1,n+1)lst[i]=i-1,nxt[i-1]=i,lf[i]=rf[i]=1;
	REP(i,1,n)q.push(mkr(val[i],i));
}

ll ans;

inline void doing()
{
	while(!q.empty())
	{
		static int st[maxn],top; top=0;
		static int Lf[maxn],Rf[maxn];
		int u=q.top().se,VAL=val[u];
		for(int i=u;i<=n && val[i]==val[u];i=nxt[i])
			st[++top]=i,tag[i]=1;
		while(!q.empty() && tag[q.top().se])q.pop();
		ll sumlf=0;
		int j=1,Lst=0;
		REP(i,1,top)if(!vis[st[i]])ans++;
		REP(i,1,top)
		{
			if(!vis[st[i]])Lst=i;
			while(j<=Lst && j<=i-L+1)
				sumlf+=lf[st[j++]];
			ans+=sumlf*rf[st[i]];
		}
		int num=top/L;
		if(num)
		{
			REP(i,1,num)
			{
				Rf[i]=0;
				REP(j,L*i,min(L*i+L-1,top))Rf[i]+=rf[st[j]];
			}
			REP(i,1,num)
			{
				Lf[num-i+1]=0;
				DREP(j,top-L*i+1,max(top-L*i-L+2,1))Lf[num-i+1]+=lf[st[j]];
			}
			nxt[st[num]]=nxt[st[top]];
			lst[nxt[st[top]]]=st[num];
			REP(j,1,num)tag[st[j]]=0,vis[st[j]]=1,val[st[j]]=VAL+1,lf[st[j]]=Lf[j],rf[st[j]]=Rf[j],q.push(mkr(VAL+1,st[j]));
		}else nxt[lst[st[1]]]=n+1;
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}
