#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  map<int, int> frec;
  cin >> n >> k;
  int a[n];
  for (int l = 0; l < n; ++l) {
    cin >> a[l];
    frec[a[l]] = 0;
  }
  int i = 0, j = 0;
  long long sol = 0;
  while (i < n && j < n) {
    if (frec[a[j]] < k - 1) {
      frec[a[j]]++;
      j++;
    } else {
      sol += n - j;
      frec[a[i]]--;
      i++;
    }
  }
  cout << sol << endl;
  return 0;
}
