#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long &i : a) {
    cin >> i;
  }
  bool is = false;
  long long ans = 0;
  for (long long l = 0, r = 0, id = 0; l < n; l++) {
    while (!is && r < n && cnt[a[r]] < k) {
      cnt[a[r]]++;
      if (cnt[a[r]] == k) is = true, id = r;
      r++;
    }
    if (is) ans += (n - r + 1);
    cnt[a[l]]--;
    if (is && cnt[a[id]] < k) is = false;
  }
  cout << ans << '\n';
  return 0;
}
