#include <iostream>
#include <unordered_set>
using namespace std;
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t[505050][2], l[505050];
int main() {
long long n, k, m = 0, a;
cin >> n >> k;
for (long long i = 0; i < n; i++) {
cin >> a;
if (t[m-1][0] != a) {
t[m++][0] = a;
}
t[m-1][1]++;
}
long long s = 0;
long long x = 0, o = 0;
unordered_set<long long> z;
for (long long i = 0; i < m; i++) {
z.insert(t[i][0]);
if (z.size() > k) {
unordered_set<long long> q;
for (long long j = i-1; j >= 0; j--) {
i = j;
q.insert(t[j][0]);
if (q.size() == k) break;
l[o] += t[j][1];
}
o++;
s += x*((x+1)/2);
x = 0;
z.clear();
continue;
}
x += t[i][1];
}
s += x*(x+1)/2;
for (long long i = 0; i < o; i++) s -= l[i]*((l[i]+1)/2);
cout << s << endl;
}