#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define LL long long
#define LD long double
#define pb push_back
#define F first
#define S second


const double PI=3.1415926535897932384626433;
const int KL=1e6;
const LL MOD=1e9+7;


using namespace std;
/*
typedef complex<double> point;
#define x real()
#define y imag()
*/

LL q,x,y,z,n,m,mn=1e9,mx=-1e9,ans,k;
string t;
bool a[2*KL+10];
map <LL,LL> mp;

int main()
{
    scl(n);
    for(LL i=1;i<=n;i++){
        scl(x);
        mp[x]++;
        ans+= (i-mp[x]);
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mp   make_pair
#define pb   push_back
#define eb   emplace_back
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int  long long
#define endl "\n"
int solve(){
	int N,tot=0,sq=0;
	cin >> N;
	vector<int> A(N),suff(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
		sq += A[i]*A[i];
	}
	suff[N-1]=A[N-1];
	for(int i=N-2;i>=0;i--) suff[i]=suff[i+1]+A[i];
	int temp=0;
	for(int i=0;i<N-1;i++) temp+=A[i]*suff[i+1];
	return (N-1)*sq-2*temp;
}

int32_t main(){
	fast;
	int t;
  	//cin >> t;
	t=1;
  	while(t--){
		cout << solve() << endl;
  	}
}
