#include <bits/stdc++.h>
const long long mod = 1000000007;
int Inf = (int)2e9;
using namespace std;
int main() {
  int n;
  scanf("%d", &(n));
  int k;
  scanf("%d", &(k));
  vector<int> a(n);
  for (int(i) = 0; (i) < n; (i)++) scanf("%d", &(a[i]));
  long long ans = 0;
  map<int, int> tmp;
  map<int, int> cnt;
  tmp[a[0]]++;
  cnt[1]++;
  int l = 0, r = 0;
  while (l != n) {
    auto it = cnt.rbegin();
    if (it->first >= k) {
      ans += (long long)(n - r);
      cnt[tmp[a[l]]]--;
      if (cnt[tmp[a[l]]] == 0) cnt.erase(tmp[a[l]]);
      tmp[a[l]]--;
      l++;
      if (r < l) {
        r = l;
        if (r < n) {
          tmp[a[r]]++;
          cnt[tmp[a[r]]]++;
        }
      }
    } else {
      if (r < n) {
        r++;
        if (r < n) {
          tmp[a[r]]++;
          cnt[tmp[a[r]]]++;
        }
      } else {
        break;
      }
    }
    if (cnt.size() != 0) {
      it = cnt.rbegin();
      if (it->second == 0) cnt.erase(it->first);
    }
  }
  cout << ans;
  return 0;
}
