#include<bits/stdc++.h>
usingnamespacestd;intN;longlongans=0;constintMX=2e5+1;intprevbreedtype[MX];intcows[MX];intbit[MX];voidupdateBIT(inta,intb){while(a<=N){bit[a]+=b;a+=(a&(-a));}}intquery(inta){intr=0;while(a>0){r+=bit[a];a=a-(a&(-a));}returnr;}inlinevoidrunBIT(){for(inti=0;i<N;i++){// last cow of same breedintmybreed=cows[i];intlastcow=prevbreedtype[mybreed];if(lastcow!=-1){// reset to 0 so we can update again with 1 so no overcountingupdateBIT(lastcow+1,-1);}// new breed typeprevbreedtype[mybreed]=i;updateBIT(i+1,1);if(i>0){intp1=max(0,lastcow);ans+=query(i)-query(p1);}}}intmain(){cin>>N;for(inti=0;i<N;i++){cin>>cows[i];prevbreedtype[i]=-1;}runBIT();cout<<ans;}