#include <bits/stdc++.h>
using namespace std;
int n, k;
map<long long, vector<long long> > mp;
long long a[400005];
int main() {
  long long ans = 0, last = -1;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    mp[a[i]].push_back(i);
    if (mp[a[i]].size() >= k) last = max(last, mp[a[i]][mp[a[i]].size() - k]);
    ans = ans + last + 1;
  }
  printf("%I64d\n", ans);
  return 0;
}
