#include <bits/stdc++.h>
using namespace std;
int a[500010], b[500010];
vector<int> p[500010];
int tree[500010 << 2];
void build(int L, int R, int rt) {
  tree[rt] = 0x7FFFFFFF;
  if (L != R) {
    int mid = (L + R) >> 1;
    build(L, mid, rt << 1);
    build(mid + 1, R, rt << 1 | 1);
  }
}
inline void pushUp(int rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); }
void update(int x, int val, int L, int R, int rt) {
  if (L == R)
    tree[rt] = min(tree[rt], val);
  else {
    int mid = (L + R) >> 1;
    if (x <= mid)
      update(x, val, L, mid, rt << 1);
    else
      update(x, val, mid + 1, R, rt << 1 | 1);
    pushUp(rt);
  }
}
int query(int x, int y, int L, int R, int rt) {
  if (x <= L && R <= y) return tree[rt];
  int mid = (L + R) >> 1, ans = 0x7FFFFFFF;
  if (x <= mid) ans = min(ans, query(x, y, L, mid, rt << 1));
  if (y > mid) ans = min(ans, query(x, y, mid + 1, R, rt << 1 | 1));
  return ans;
}
int main() {
  int i, j, n, k;
  int cnt, x;
  long long ans;
  while (~scanf("%d%d", &n, &k)) {
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      b[i] = a[i];
      p[i].clear();
    }
    sort(b, b + n);
    cnt = unique(b, b + n) - b;
    for (i = 0; i < n; i++) {
      a[i] = lower_bound(b, b + cnt, a[i]) - b;
      p[a[i]].push_back(i);
    }
    build(0, n - 1, 1);
    for (i = 0; i < cnt; i++) {
      for (j = 0; j <= (int)p[i].size() - k; j++)
        update(p[i][j], p[i][j + k - 1], 0, n - 1, 1);
    }
    ans = 0;
    for (i = 0; i < n; i++) {
      x = query(i, n - 1, 0, n - 1, 1);
      if (x != 0x7FFFFFFF) ans += n - x;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
