#include <bits/stdc++.h>
using namespace std;
const int N=200010,M=5050;
int n,a[N],b[M][M],flag[N];
long long ret=0;
int main() {
freopen("charger.in","r",stdin);
freopen("charger.out","w",stdout);
cin>>n;
if (n>5000)
{
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
cout<<n*(n-1)/2;
return 0;
}
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]][i]++;
}
for (int i=1;i<=n;i++)
{
if (flag[a[i]]) continue;
for (int j=1;j<=n;j++)
{
b[a[i]][j]+=b[a[i]][j-1];
}
flag[a[i]]=1;
}
for (int i=1;i<=n-1;i++)
{
for (int j=i+1;j<=n;j++)
{
if (a[i]!=a[j] && b[a[i]][j-1]==b[a[i]][i] && b[a[j]][j-1]==b[a[j]][i])
{
ret++;
}
}
}
cout<<ret;
}