func_code_string: #include <bits/stdc++.h>   using namespace std;   const int Z = (int)2e5 + 111;   const int inf = (int)1e9 + 111;   const long long llinf = (long long)1e18 + 5;   const int MOD = (int)1e9 + 7;   vector<long long> pref[4 * Z];   vector<int> t[4 * Z];   int a[Z];   void build(int v, int vl, int vr) {     if (vl == vr) {       t[v].push_back(a[vl]);       pref[v].push_back(a[vl]);       return;     }     int vm = (vl + vr) / 2;     build(2 * v, vl, vm);     build(2 * v + 1, vm + 1, vr);     merge((t[2 * v]).begin(), (t[2 * v]).end(), (t[2 * v + 1]).begin(),           (t[2 * v + 1]).end(), back_inserter(t[v]));     pref[v].resize((int)t[v].size());     pref[v][0] = t[v][0];     for (int i = 1; i < (int)t[v].size(); ++i) {       pref[v][i] = pref[v][i - 1] + t[v][i];     }   }   pair<long long, long long> query(int v, int vl, int vr, int l, int r, int val1,                                    int val2) {     if (vl > r || vr < l) return make_pair(0, 0);     if (l <= vl && r >= vr) {       long long cnt = upper_bound((t[v]).begin(), (t[v]).end(), val2) -                       lower_bound((t[v]).begin(), (t[v]).end(), val1);       int posL = lower_bound((t[v]).begin(), (t[v]).end(), val1) - t[v].begin();       int posR = upper_bound((t[v]).begin(), (t[v]).end(), val2) - t[v].begin();       posR--;       long long sum;       if (posR == -1)         sum = 0;       else         sum = pref[v][posR] - (posL == 0 ? 0 : pref[v][posL - 1]);       return make_pair(sum, cnt);     }     int vm = (vl + vr) / 2;     pair<long long, long long> ql = query(2 * v, vl, vm, l, r, val1, val2);     pair<long long, long long> qr =         query(2 * v + 1, vm + 1, vr, l, r, val1, val2);     return make_pair(ql.first + qr.first, ql.second + qr.second);   }   int main() {     srand(time(0));     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     build(1, 1, n);     long double ans = 0;     for (int i = 1; i <= n; ++i) {       pair<long long, long long> l;       if (a[i] - 2 >= 1)         l = query(1, 1, n, i + 1, n, 1, a[i] - 2);       else         l = make_pair(0, 0);       pair<long long, long long> r = query(1, 1, n, i + 1, n, a[i] + 2, inf);       ans += l.first + r.first - (l.second + r.second) * a[i];     }     cout << fixed << setprecision(0) << ans;     return 0;   }   