#include <bits/stdc++.h>
using namespace std;
int a[400000 + 10], n, k, p;
long long ans;
map<int, int> mp;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  p = 0;
  ans = 0;
  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
    if (mp[a[i]] == k) {
      do {
        ans += (long long)(n - i);
        mp[a[p++]]--;
      } while (a[p - 1] != a[i]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
