#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <functional>
#define ll long long
#define MAX_INT 100000
using namespace std;

int n;
ll a[310000];
ll ans = 0;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	ll sumA = 0;
	ll sumA2 = 0;
	for (int i = 0; i < n; i++) {
		sumA += a[i];
		sumA2 += a[i] * a[i];
	}
	cout << n * sumA2 - sumA * sumA << endl;
	return 0;
}
#include<iostream>
#include<vector>
#include<cmath>
#include<string>

using namespace std;
using ll = long long;

int main(){
    int n, tmp;
    int a_max=0, b_min=1000;

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> tmp;
        if(a_max < tmp) a_max = tmp;
    }
    for(int i=0; i<n; i++){
        cin >> tmp;
	if(b_min > tmp) b_min = tmp;
    }

    if(b_min-a_max < 0) cout << 0;
    else cout << b_min-a_max+1;// << "," << b_min << "," << a_max;

    return 0;
}