解题思路 : 我们看一下ai的大小 发现是可以暴力的
a[ i ] 和 a[j ]
相同的情况下 那么 : 就是排列组合中的 (n 中选 2) + a[i] (数字本身也要进行一次)
不同的情况 就是 a[i]*a[j]
#include"bits/stdc++.h"
#define ll long long
#define pi pair<int,int>
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<=b;i++)
#define for_(i,a,b) for(int i=a;i<b;i++)
#define _fr(i,a,b) for(int i=a;i>=b;i--)
#define fr_(i,a,b) for(int i=a;i>b;i--)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e6+5;
const ll mod = 998244353;
const double lp=1.000000011;
map<string,int>mp;
ll arr[N];
void solve(){
int n,x;
cin >> n;
_for(i,1,n) cin >> x , arr[x]++;
ll ans = 0;
_for(i,0,1000){
_for(j,i,1000){
ll add ;
if(i == j) add = (arr[i] + arr[i]*(arr[i]-1)/2);
else add = arr[i]*arr[j];
ans += add* abs(i+j-1000);
}
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}