#include <bits/stdc++.h>
#define db double 
#define maxn 200005 
#define mod 998244353
#define vi vector<double>
#define pb push_back
#define ll long long
#define iter set<th>::iterator
using namespace std;
ll ksm(ll a, ll b) {
	if (!b) return 1;
	ll ns = ksm(a, b >> 1);
	ns = ns * ns % mod;
	if (b & 1) ns = ns * a % mod;
	return ns;
}
inline int add(int a, int b) {
	a += b;
	return (a < mod) ? a : (a - mod);
}
inline int sub(int a, int b) {
	a -= b;
	return (a < 0) ? a + mod : a;
}
inline int mul(int a, int b) {
	return (ll)a * b % mod;
}
// head
struct th{
	int tp, pl, num, l, r;
	th(){
	}
	th(int u, int a, int b) {
		tp = u, pl = a, num = b;
		l = r = 1;
	}
	bool operator < (const th &b)const {
		if (tp == 0) return pl < b.pl;
		else  {
			if (num != b.num) return num < b.num;
			return pl < b.pl;
		}
	}
}; 
int n, l;
ll ans = 0;
set<th> ps, qs;
ll cal(vector<th> u) {
	int n = u.size();
	vi sm(n);
	sm[0] = u[0].r;
	for (int i = 1; i < n; i++)
		sm[i] = sm[i - 1] + u[i].r;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int nx = i + l - 1;
		int ns = sm[n - 1];
		nx--;
		if (nx >= 0) ns -= sm[min(nx, n - 1)];
		ans += 1ll * u[i].l * ns;
	}
	return  ans;
}
void otp(set<th> r) {
	cout << "QQQ" << endl;
	iter q = r.begin();
	while (q != r.end()) {
		cout << (*q).pl << " " << (*q).num << endl;
		q++;
	}
}
int sum[maxn];
int main() {
	cin >> n >> l;
	int inf = 2e9;
	for (int i = 1; i <= n; i++) {
		int a;
		scanf("%d", &a);
		ps.insert(th(0, i, a)), 
		qs.insert(th(1, i, a));
	}
	ans = n;
	while(1) {
		th u1 = *qs.begin();
		if (u1.num >= inf) break;
		iter it = ps.find(th(0, u1.pl, u1.num)), ft = it;
		vector<th> ns;
		while (it != ps.end() && (*it).num == u1.num)
			ns.pb(*it), it++;
		int cnt = ns.size();
		for (int i = 0; i < cnt; i++)
			ps.erase(ns[i]), 
			qs.erase(th(1, ns[i].pl, ns[i].num));
		if (cnt < l) {
		//	ans += cnt;
			ps.insert(th(0, u1.pl, inf)), 
			qs.insert(th(1, u1.pl, inf));
		}
		else {
			vector<th> gr(cnt / l);
			ans += cal(ns);
			int pl = 0;
			for (int i = 0; i < cnt / l; i++) {
				gr[i] = th(1, ns[pl].pl, ns[pl].num + 1);
				gr[i].l = gr[i].r = 0;
				for (int j = pl + l - 1; j < min(pl + 2 * l - 1, cnt); j++)	
					gr[i].r += ns[j].r;
				pl += l;
			}
			pl = cnt - 1;
			for (int i = cnt / l - 1; i >= 0; i--) {
				for (int j = pl - l + 1; j >= max(0, pl - 2 * l + 2); j--)
					gr[i].l += ns[j].l; 
				pl -= l;
			}
			ans -= cal(gr);
			for (int i = 0; i < cnt / l; i++) {
				qs.insert(gr[i]);
				gr[i].tp = 0, ps.insert(gr[i]);
			}
		}
	
	//	otp(ps);
		//otp(qs);
	//	cout << ans << endl;
	////	system("pause");
	}
	cout << ans << endl;
	return 0;
}
