#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
using namespace std;

using ll = long long;

#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define Sort(a) sort((a).begin(),(a).end())
#define Rev(a) reverse((a).begin(),(a).end())
#define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a) 


int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	ll temp;
	ll sum = 0;
	ll ans = 0;
	For(i, 0, N) {
		cin >> temp;
		A[i] = temp;
		sum += temp;
		ans += (N - 1) * (temp * temp);
	}
	For(i, 0, N) {
		sum -= A[i];
		ans -= 2 * (A[i] * sum);
	}
	co(ans);
}
#include<bits/stdc++.h>
#define FULL(x,y) memset(x,y,sizeof(x))
#define ll long long
#define SZ(x) (int)x.size()
#define pb push_back
using namespace std;

const int N=300005;
int n;
ll a[N],pre[N],pre2[N];

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
	for(int i=1;i<=n;i++) pre2[i]=pre2[i-1]+a[i]*a[i];
	ll ans=0;
	for(int i=2;i<=n;i++) {
		ans+=(i-1)*a[i]*a[i];
	}
	for(int i=2;i<=n;i++) {
		ans+=pre2[i-1];
	}
	for(int i=2;i<=n;i++) {
		ans-=(2*a[i]*pre[i-1]);
	}
	cout<<ans;
	return 0;
}