#include <bits/stdc++.h>
using namespace std;
const int mxn = 4e5 + 100;
int a[mxn], b[mxn], c[mxn], d[mxn];
int main() {
  int n, k, m;
  long long ret = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), c[i - 1] = a[i];
  sort(c, c + n), m = unique(c, c + n) - c;
  for (int i = 1; i <= n; i++) a[i] = lower_bound(c, c + m, a[i]) - c;
  for (int i = 1, j = 1; j <= n; j++) {
    for (++d[++b[a[j]]]; d[k] > 1 || (d[k] == 1 && b[a[i]] != k);
         --d[b[a[i]]], --b[a[i]], ++i)
      ;
    ret += i * (d[k] >= 1);
  }
  printf("%lld\n", ret);
}
