#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int n, k, a[400111];
map<int, int> m;
int main() {
  while (scanf("%d%d", &n, &k) == 2) {
    for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]);
    int j = 0;
    long long res = 0;
    int ok = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      if (i) {
        m[a[i - 1]]--;
        if (m[a[i - 1]] == k - 1) --ok;
      }
      while (!ok && j < n) {
        ++j;
        m[a[j]]++;
        if (m[a[j]] >= k) ++ok;
      }
      if (ok) res += n - j + 1;
    }
    cout << res << endl;
  }
  return 0;
}
