#include <bits/stdc++.h>
using namespace std;
map<int, int> M;
const int MAXN = 4e5 + 5;
int A[MAXN];
int main() {
  int N, K;
  long long result = 0;
  scanf("%d %d", &N, &K);
  for (int i = 0, j = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    M[A[i]]++;
    while (M[A[i]] >= K) result += N - i, M[A[j++]]--;
  }
  printf("%lld\n", result);
  return 0;
}
