#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 2e5 + 5;

#define pii pair<int, int>
#define ll long long

typedef class Segment {
	public:
		int l, r, x, y;

		Segment() {	}
		Segment(int l, int r, int x, int y) : l(l), r(r), x(x), y(y) {	}

		boolean operator < (Segment b) const {
			return l < b.l;
		}
} Segment;

int n, L;
int a[N];
pii b[N];

ll calc(vector<pii>& a) {
	ll ret = 0, sum = 0;
	for (int l = 0, r = L - 1; r < (signed) a.size(); l++, r++) {
		ret += (sum += a[l].first) * a[r].second;
	}
	return ret;
}

ll ans = 0;
int main() {
	scanf("%d%d", &n, &L);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		b[i] = pii(a[i], i);
	}
	ans = n;
	sort(b + 1, b + n + 1);
	int pos = 1, val;
	vector<Segment> vcur, vnxt, vadd;
	while (true) {
		if (!vcur.size()) {
			if (pos > n) {
				break;
			} else {
				val = b[pos].first;
			}
		} else {
			val++;
		}
//		cerr << pos << " " << val << '\n';
		vadd.clear();
		while (pos <= n && b[pos].first == val)
			vadd.emplace_back(b[pos].second, b[pos].second, 1, 1), pos++;
		vnxt.resize(vcur.size() + vadd.size());
		merge(vcur.begin(), vcur.end(), vadd.begin(), vadd.end(), vnxt.begin());
		swap(vcur, vnxt);
		vnxt.clear();
		int num = vcur.size();
		for (int i = 0, j = 0; i < num; i = ++j) {
			while (j < num - 1 && vcur[j].r + 1 == vcur[j + 1].l)
				j++;
			int len = j - i + 1, cnt = len / L;
			if (cnt) {
				vector<pii> tmp;
				for (int k = i; k <= j; k++)
					tmp.emplace_back(vcur[k].x, vcur[k].y);
				ans += calc(tmp);
				tmp.clear();
				tmp.resize(cnt, pii(0, 0));
				for (int k = L - 1; k < len; k++) {
					tmp[cnt - (k - L + 1) / L - 1].first += vcur[j - k].x;
				}
				for (int k = L - 1; k < len; k++) {
					tmp[(k - L + 1) / L].second += vcur[i + k].y;
				}
				ans -= calc(tmp);
				for (int k = 0; k < cnt; k++)
					vnxt.emplace_back(vcur[i].l + k, vcur[i].l + k, tmp[k].first, tmp[k].second);
				vnxt.back().r = vcur[j].r;
			}
		}
		swap(vcur, vnxt);
		vnxt.clear();
	}
	printf("%lld\n", ans);
	return 0;
}
