#include <bits/stdc++.h>
using namespace std;
int main() {
  std::iostream::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  std::vector<pair<int, int> > v(n);
  std::vector<int> a(n);
  int i;
  for (i = 0; i < n; i++) {
    int p;
    cin >> p;
    v[i] = make_pair(p, i);
    a[i] = p;
  }
  sort(v.begin(), v.end());
  std::vector<int> b(n, n);
  for (i = 0; i <= n - k; i++) {
    if (v[i].first == v[i + k - 1].first) b[v[i].second] = v[i + k - 1].second;
  }
  for (i = n - 2; i >= 0; i--) b[i] = min(b[i], b[i + 1]);
  long long ans = 0;
  for (i = 0; i < n; i++) {
    ans += (long long)(n - b[i]);
  }
  cout << ans << endl;
  return 0;
}
