#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
long long n;
long long number_of_pairs(long long k) {
  long long l = 0, r, i, count = 0, M = (n * (n + 1)) / 2;
  long long t;
  map<long long, long long> mp;
  l = 0;
  for (r = 0; r < n; r++) {
    mp[a[r]]++;
    t = mp[a[r]];
    while (mp[a[r]] >= k && l <= r) {
      count += (n - r);
      mp[a[l++]]--;
    }
  }
  return min(count, M);
}
int main() {
  long long k, i, temp, res;
  cin >> n;
  cin >> k;
  for (i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  res = number_of_pairs(k);
  cout << res << endl;
  return 0;
}
