#include <bits/stdc++.h>
using namespace std;
int n, k, a[400005], i, j;
map<int, int> m;
long long c;
int main() {
  for (cin >> n >> k >> a[0]; j < n; cin >> a[++j])
    if (++m[a[j]] >= k) do
        c += n - j, --m[a[i]];
      while (a[i++] - a[j]);
  cout << c;
  return 0;
}
