#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  long long int k;
  long long int p1 = 1, p2 = 1;
  long long int count = 0;
  cin >> n;
  cin >> k;
  vector<int> vl(n + 1, 0);
  map<int, int> counter;
  for (i = 1; i <= n; i++) {
    cin >> vl[i];
  }
  while (p2 <= n && p1 <= n) {
    counter[vl[p2]]++;
    while (counter[vl[p2]] == k) {
      count += n - p2 + 1;
      counter[vl[p1]]--;
      p1++;
    }
    p2++;
  }
  cout << count << endl;
  return 0;
}
