#include <bits/stdc++.h>
using namespace std;
int arr[500010];
int main() {
  map<int, int> fre;
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; ++i) cin >> arr[i];
  int h = 0, t = 0;
  int ov = 0;
  long long sum = 0;
  while (h < N) {
    fre[arr[h]]++;
    if (fre[arr[h]] == K) ov++;
    while (ov > 0) {
      sum += N - h;
      fre[arr[t]]--;
      if (fre[arr[t]] == K - 1) ov--;
      t++;
    }
    h++;
  }
  cout << sum << endl;
}
