#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(555555, -1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long p1 = 0, p2 = 0;
  cnt[a[0]]++;
  long long ans = 0;
  while (p2 < n) {
    if (cnt[a[p2]] < k) {
      p2++;
      cnt[a[p2]]++;
    } else {
      ans += n - p2;
      cnt[a[p1]]--;
      p1++;
    }
  }
  cout << ans << "\n";
}
