#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 500000;
int d[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> d[i];
  map<int, int> mm;
  long long res = 0, cnt = 0;
  for (int l = 0, r = 0; l < n; ++l) {
    while (r < n && !cnt) {
      ++mm[d[r]];
      if (mm[d[r++]] == k) {
        ++cnt;
      }
    }
    if (cnt) res += n - r + 1;
    if (mm[d[l]] == k) --cnt;
    --mm[d[l]];
  }
  cout << res << endl;
  return 0;
}
