#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
const int N = 400100;
int vec[N], n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int(i) = (0); (i) < (n); ++(i)) cin >> vec[i];
  long long ans = 0;
  map<int, int> vx;
  set<pair<int, int> > qt;
  int len = 0;
  for (int i = 0; i < n;) {
    if (qt.empty() || qt.rbegin()->first < k) {
      qt.erase(make_pair(vx[vec[i]], vec[i]));
      vx[vec[i]]++;
      qt.insert(make_pair(vx[vec[i]], vec[i]));
      ++len;
      i++;
    }
    while (!qt.empty() && qt.rbegin()->first >= k) {
      ans += n - i + 1;
      qt.erase(make_pair(vx[vec[i - len]], vec[i - len]));
      vx[vec[i - len]]--;
      qt.insert(make_pair(vx[vec[i - len]], vec[i - len]));
      len--;
    }
  }
  cout << ans << "\n";
  return 0;
}
