#include using namespace std; int main(){ using ll=long long; int n,d; cin>>n>>d; vector a(n); map> mp; for (int i=0;i>a[i]; mp[a[i]].push_back(i); } auto f=[&](int x,int r){ if (!mp.count(x)) return 0LL; ll ret=lower_bound(mp[x].begin(),mp[x].end(),r)-mp[x].begin(); return ret; }; ll ans=0; for (int i=0;i