#include <bits/stdc++.h>
using namespace std;
void fast_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const long long MOD = 1000000007;
const int maxn = 1e+5;
long long n, k, a[400005], ans;
map<long long, long long> m;
int main(int argc, const char* argv[]) {
  cin >> n >> k;
  long long l = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    while (m[a[i]] >= k) {
      ans += (n - i);
      m[a[l]]--;
      l++;
    }
  }
  cout << ans << "\n";
  return 0;
}
