#include <bits/stdc++.h>
#define N 500000
#define ll long long
using namespace std;
ll n, k;
map <ll, ll> c;
ll a[N+5];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    freopen("dcon.inp","r",stdin);
    freopen("dcon.out","w",stdout);
    cin>>n>>k;
    for (ll i = 1; i<= n;i++)
        cin>>a[i];
    ll i = 1,res = 0;
    for (ll j = 1; j<= n; j++)
    {
        c[a[j]]++;
        while (c[a[j]] == k)
        {
            res += n-j+1;
            c[a[i]]--;
            i++;
        }
    }
    cout<<res;
    return 0;
}
