#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int l = 0, r = -1;
  unordered_map<int, int> uMap;
  int check = 0;
  long long int ans = 0;
  while (1) {
    if (check == 0) {
      r++;
      if (r == n) break;
      uMap[arr[r]]++;
      if (uMap[arr[r]] == k) check++;
    } else {
      ans += (n - r);
      if (uMap[arr[l]] == k) check--;
      uMap[arr[l]]--;
      l++;
      if (l == n) break;
    }
  }
  cout << ans;
  return 0;
}
