#include <bits/stdc++.h>
using namespace std;
const int N = 400001;
int n, k, a[N];
unordered_map<int, int> f;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  long long ans = 0;
  int l = 0, r = -1, cnt = 0;
  while (r < n) {
    if (cnt) {
      ans += (n - r);
      f[a[l]]--;
      if (f[a[l]] == k - 1) cnt--;
      l++;
    } else {
      r++;
      f[a[r]]++;
      if (f[a[r]] == k) cnt++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
