#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400010;
int n, k, v[MAXN], ini = 0, fim = 0, ok = 1;
long long int resp;
map<long long int, int> qtd, K;
set<long long int> aux;
long long int func(int n) {
  long long int r = 0;
  for (int i = n; i > 0; i--) r += i;
  return r;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  if (k == 1) {
    printf("%lld\n", func(n));
    return 0;
  }
  qtd[v[0]]++;
  if (qtd[v[0]] >= k) K[v[0]] = 1, aux.insert(v[0]);
  for (; ini < n && fim < n;) {
    if (ok) {
      while (aux.size() == 0 && fim < n) {
        fim++;
        qtd[v[fim]]++;
        if (qtd[v[fim]] >= k) aux.insert(v[fim]), K[v[fim]] = 1;
      }
      ok = 0;
    } else {
      while (aux.size() != 0 && ini < fim) {
        resp += n - fim;
        qtd[v[ini]]--;
        if (qtd[v[ini]] < k) aux.erase(v[ini]), K[v[ini]] = 0;
        ini++;
      }
      ok = 1;
    }
  }
  printf("%lld\n", resp);
}
