#include <bits/stdc++.h>
using namespace std;
long long n, k, a[400100];
long long ans, l = 0;
unordered_map<long long, long long> mep;
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    mep[a[i]]++;
    while (mep[a[i]] >= k) {
      mep[a[l]]--;
      l++;
      ans += n - i;
    }
  }
  cout << ans << endl;
  return 0;
}
