#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[400000], k, l = 0, r = 0, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  map<long long, long long> b;
  b[a[0]] = 1;
  while (l < n) {
    while (r < n && b[a[r]] < k) {
      r++;
      b[a[r]]++;
    }
    ans += n - r;
    b[a[l]]--;
    l++;
  }
  cout << ans << endl;
}
