#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, a[maxn], k, j, t, pre[maxn];
map<int, int> id;
long long ans;
vector<int> pos[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (!id.count(a[i])) id[a[i]] = i;
    t = id[a[i]];
    pos[t].push_back(i);
    if (pos[t].size() >= k) {
      pre[i] = pos[t][pos[t].size() - k];
    }
  }
  t = -1;
  for (int i = 1; i <= n; i++) {
    t = max(t, pre[i]);
    ans += 1LL * (t);
  }
  cout << ans;
}
