#include <bits/stdc++.h>
using namespace std;


#define INF 1000000000
#define MAXN 300010

long long n;
long long a[MAXN];
map<long long, long long> qt;


int main() {
    scanf("%lld", &n);
    long long i, j;
    for (i=1; i<=n; i++) {
        scanf("%lld", &a[i]);
    }


    long long ans = 0;
    for (i=1; i<=n; i++) {
        map<long long, long long>::iterator iter;
        for (iter=qt.begin(); iter!=qt.end(); iter++) {
            ans += (a[i]-iter->first)*(a[i]-iter->first)*iter->second;
        }
        qt[a[i]]++;
    }

    printf("%lld\n", ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF LLONG_MAX
#define MINF LLONG_MIN
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>

int pow(int x, int y, int mod) {
    int temp;
    if (y == 0)
        return 1;

    temp = (pow(x, y / 2, mod)) % mod;

    if (y % 2 == 0)
        return (temp * temp) % mod;
    else
        return (((x * temp) % mod) * temp) % mod;
}

void solve(int tno) {
    
    int n; cin >> n;
    int prev = 0;
    int ans = 0;

    for(int i = 0; i < n; i ++) {

        int a; cin >> a;

        ans += (n - 1) * a * a;
        ans -= 2 * a * prev;
        prev += a;
    }

    cout << ans << endl;
}

int32_t main() {

    FASTIO

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t;
    t = 1;
    for (int i = 1; i <= t; i ++)
        solve(i);
}