#include <bits/stdc++.h>
using namespace std;
int arr[400001];
map<int, int> freq;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int start = 0;
  int next = 0;
  long long int ans = 0;
  while (start < n) {
    while (next < n && freq[arr[next]] < k - 1) {
      freq[arr[next]]++;
      next++;
    }
    ans += n - next;
    freq[arr[start]]--;
    start++;
  }
  cout << ans << endl;
}
