// C - Squared Error
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
	int n; cin>>n;
	vector<ll> A(n); for(ll&a:A) cin>>a;
	ll aa = 0, sa = 0;
	for(ll a:A){
		aa += a*a;
		sa += a;
	}
	cout<< n*aa - sa*sa <<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000001;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

template<class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>

T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll ret = 0;
    map<ll,ll> ma;
    for(int i = 0;i < N;i++) {
        if(i == 0) ma[vec.at(i)]++;
        else {
            for(auto x:ma) {
                ret += x.second * (x.first - vec.at(i)) * (x.first - vec.at(i));
            }
            ma[vec.at(i)]++;
        }
    }
    cout << ret << endl;
}