#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<long long> a;
  for (int i = 0; i < n; ++i) {
    long long v;
    cin >> v;
    a.push_back(v);
  }
  long long m = 0;
  map<long long, int> counts;
  int right = 0;
  for (int left = 0; left < n; ++left) {
    while (right < n) {
      ++counts[a[right]];
      if (counts[a[right]] == k) {
        do {
          m += n - right;
          --counts[a[left]];
        } while (a[left++] != a[right]);
        ++right;
        --left;
        break;
      }
      ++right;
    }
  }
  cout << m << endl;
  return EXIT_SUCCESS;
}
