#include <bits/stdc++.h>
using namespace std;
int n, k, a[400100];
map<int, int> b;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  int l = 0, r = -1;
  while (l < n)
    if (r + 1 < n) {
      if (++b[a[++r]] == k)
        while (b[a[r]] == k) {
          b[a[l]]--;
          l++;
          ans += n - r;
        }
    } else {
      b[a[l]]--;
      l++;
    }
  cout << ans;
}
