#include <bits/stdc++.h>
using namespace std;
const char IN[] = "_.in";
const char OUT[] = "_.out";
const int maxn = 110000;
int ntest = 0, test;
int n, l, r, a[4 * maxn], k;
long long res;
int main() {
  map<int, int> m;
  cin >> n >> k;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  l = 1;
  r = 1;
  m[a[1]] = 1;
  while (r <= n) {
    if (m[a[r]] < k) {
      if (r <= n) {
        r++;
        m[a[r]]++;
      }
    } else {
      res += n - r + 1;
      m[a[l]]--;
      l++;
    }
  }
  cout << res;
  return 0;
}
