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