//
//  main.cpp
//  abc194c
//
//  Created by Hsiu-Fen Chou on 2021/4/8.
//

#include <iostream>
using namespace std;
int A[300005];

long long solve(int L, int R) {
    if (L == R) return 0;
    int M = (L + R) / 2;
    long long sum1 = 0, sum2 = 0;
    for (int i = L; i <= M; i++) {
        sum1 += A[i];
    }
    for (int i = M+1; i <= R; i++) {
        sum2 += A[i];
    }
    long long sum = solve(L, M) + sum1 * sum2 + solve(M+1, R);
    return sum;
}

int main() {
    int N;
    cin >> N;
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i] * A[i];
    }
    cout << (N-1) * sum - 2 * solve(0, N-1) << endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(){

    int n;
    cin >> n;

    map<ll, ll> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    ll ans = 0;
    for(auto p : mp){
        for(auto q : mp){
            if(p.first == q.first) continue;
            ans += (p.first - q.first) * (p.first - q.first) * p.second * q.second;
        }
    }

    cout << ans / 2 << "\n";

    return 0;
}
