#include <bits/stdc++.h>
using namespace std;
int n, k;
map<int, int> mapa;
int arr[400100];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  long long res = 0;
  int ini = 0, fin = 0;
  int x, y;
  while (fin < n) {
    mapa[arr[fin]]++;
    x = mapa[arr[fin]];
    if (x >= k) {
      do {
        mapa[arr[ini]]--;
        res += (n - fin);
        if (arr[ini] == arr[fin]) {
          ini++;
          break;
        }
        ini++;
      } while (ini <= fin);
      fin++;
    } else
      fin++;
  }
  cout << res << endl;
  return 0;
}
