#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const N=200010;
int n,a[N],d[N];
bool p[N],f;
ll res;
int main(){
freopen("charger.in","r",stdin);
freopen("charger.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
if (p[a[i]]) f=1;
p[a[i]]=1;
}
if (!f){
res=(ll)(n+1)*((ll)n-2)/2;
printf("%lld",res);
return 0;
}
for (int i=1;i<=n;i++){
memset(d,0,sizeof(d));
d[a[i]]++;
for (int j=i+1;j<=n;j++){
d[a[j]]++;
if (d[a[i]]<2 && d[a[j]]<2) res++;
}
}
printf("%lld",res);
return 0;
}