#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
map<int, int> mass;
set<pair<int, int>> sost;
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  int pos = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    arr.push_back(x);
    sost.erase(make_pair(mass[arr[i]], arr[i]));
    mass[x]++;
    sost.insert(make_pair(mass[arr[i]], arr[i]));
    while (sost.rbegin()->first >= k) {
      ans += n - i;
      sost.erase(make_pair(mass[arr[pos]], arr[pos]));
      mass[arr[pos]]--;
      sost.insert(make_pair(mass[arr[pos]], arr[pos]));
      pos++;
    }
  }
  cout << ans;
  return 0;
}
