#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
int n, k, a[N];
map<int, int> cnt;
long long res;
void init() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  cnt[a[1]]++;
  for (int L = 1, R = 1; L <= n && R <= n; L++) {
    while (cnt[a[R]] < k && R <= n) {
      R++;
      cnt[a[R]]++;
    }
    if (cnt[a[R]] >= k) res += (n - R + 1);
    cnt[a[L]]--;
  }
  cout << res << endl;
}
void fread() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  init();
  return 0;
}
