#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int cnt[400005];
int tot;
int A[400005];
int main() {
  int n, k, l, r, num = 0;
  long long ans = 0;
  tot = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (mp.count(A[i]) == 0) mp[A[i]] = num++;
  }
  for (int i = 0; i < n; i++) A[i] = mp[A[i]];
  l = r = 0;
  while (l < n) {
    while (r < n) {
      if (tot >= 1) break;
      cnt[A[r]]++;
      tot += (cnt[A[r]] == k);
      r++;
    }
    if (tot) ans += (long long)(n - r + 1);
    if (cnt[A[l]] >= k) tot--;
    cnt[A[l]]--;
    l++;
  }
  cout << ans << endl;
  return 0;
}
