#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400010;
int n, k, a[MAXN];
map<int, int> mp;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    mp.clear();
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    long long ans = 0;
    for (int i = 0, j = 0; i < n; ++i) {
      while (j < n && mp[a[j]] < k) {
        ++mp[a[j]];
        if (mp[a[j]] == k) break;
        ++j;
      }
      if (j >= n) break;
      ans += n - j, --mp[a[i]];
      if (a[i] == a[j]) ++j;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
