#include <bits/stdc++.h>
using namespace std;
long long int arr[400005];
map<int, int> m;
int main() {
  long long int ans = 0;
  long long int tc = 0ll;
  long long int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int f, b;
  f = b = 0;
  while (f < n && b < n) {
    m[arr[b]]++;
    while (m[arr[b]] == k) {
      m[arr[f]]--;
      f++;
      ans = ans + n - (long long int)b;
    }
    b++;
  }
  cout << ans;
  return 0;
}
