#include <bits/stdc++.h>
using namespace std;
int n, k, val;
vector<int> v;
map<unsigned long long int, unsigned long long int> mp;
void magic_box() {
  unsigned long long int ans = 0;
  unsigned long long int low = 0, high = 0;
  while (high < n) {
    mp[v[high]]++;
    while (mp[v[high]] >= k && low <= high) {
      ans += (n - high);
      mp[v[low]]--;
      low++;
    }
    high++;
  }
  cout << ans << '\n';
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> val;
    v.push_back(val);
  }
  magic_box();
}
