#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
int a[N], cur, cmax, n, k;
long long res;
map<int, int> c;
int main() {
  scanf("%d%d", &n, &k);
  int i;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  cur = 1;
  cmax = 0;
  for (i = 1; i <= n; i++) {
    ++c[a[i]];
    if (c[a[i]] >= c[cmax]) cmax = a[i];
    if (c[cmax] >= k) {
      if (c[cmax] > k) {
        --c[a[cur]];
        ++cur;
      }
      while (cur <= i && a[cur] != cmax) {
        --c[a[cur]];
        ++cur;
      }
      if (cur <= i) {
        res += cur;
      }
    }
  }
  printf("%I64d\n", res);
}
