#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const int inf = 0x3f3f3f3f;
using namespace std;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define endl '\n'
#define IOS \
ios::sync_with_stdio(NULL); \
cin.tie(NULL); \
cout.tie(NULL)
#define qwq cout << "qwq" << endl
#define line cout << "------------------" << endl
const int maxn = 3e5 + 5;
int n;
int a[maxn];
int rea[maxn];
vector<int> t[maxn];
int pre[maxn];
int ans = 0;
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
pre[a[i]] = t[a[i]].size();
t[a[i]].push_back(i);
}
for (int j = 1; j <= n; j++)
{
for (int q = 1; q <= n; q++)
{
if (q == a[j])
continue;
if (t[q].size() <= 1)
continue;
int l = 0, r = t[q].size() - 1;
int res = 0;
while (l <= r)
{
int mid = (l + r) / 2;
if (t[q][mid] > j)
{
r = mid - 1;
res = mid;
}
else
{
l = mid + 1;
}
}
int i = (t[q].size() - 1) - res + 1, k = res;
ans += i * k;
}
}
cout << ans << endl;
return 0;
}