#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int a[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> cnt;
  int l, r;
  l = 0;
  r = -1;
  long long ans = 0;
  while (l < n && r < n) {
    if (cnt[a[r]] < k) {
      r++;
      cnt[a[r]]++;
    } else if (cnt[a[r]] == k) {
      ans += n - r;
      cnt[a[l]]--;
      l++;
    }
  }
  cout << ans;
}
