#include <bits/stdc++.h>
using namespace std;
int a[400500], d[400500];
map<int, int> ma;
int t = 0;
void solve() {
  int k, n;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (!ma.count(a[i])) ma[a[i]] = t++;
  }
  long long ans = 0;
  int idx = 0, j = 0;
  while (j < n && idx < n) {
    int t = -1;
    while (j < n) {
      d[ma[a[j]]]++;
      if (d[ma[a[j]]] == k) {
        t = ma[a[j]];
        break;
      }
      j++;
    }
    if (t == -1) break;
    while (idx <= j) {
      ans += n - j;
      d[ma[a[idx]]]--;
      idx++;
      if (d[t] < k) break;
    }
    j++;
  }
  cout << ans << endl;
}
int main() { solve(); }
