#include <bits/stdc++.h>   using namespace std;   class BigInt {    public:     string value;     bool sign;     BigInt();     BigInt(string);     BigInt(long long);     BigInt operator+(BigInt &);     BigInt operator-(BigInt &);     bool operator==(BigInt &);     bool operator!=(BigInt &);     bool operator>(BigInt &);     bool operator<(BigInt &);     BigInt operator++(int);     BigInt operator--(int);     friend ostream &operator<<(ostream &, const BigInt &);     friend istream &operator>>(istream &, BigInt &);   };   string toString(long long n) {     stringstream t;     t << n;     return t.str();   }   string add(string a, string b) {     if (a.length() > b.length()) swap(a, b);     a = string(b.length() - a.length(),  0 ) + a;     string res =   ;     int carry = 0;     for (int i = a.length() - 1; i >= 0; i--) {       carry += (a[i] -  0 ) + (b[i] -  0 );       res = char(carry % 10 +  0 ) + res;       carry /= 10;     }     res = (carry != 0 ? string(1, char(carry +  0 )) :   ) + res;     return res;   }   string sub(string a, string b) {     b = string(a.length() - b.length(),  0 ) + b;     string res =   ;     for (int i = a.length() - 1; i >= 0; i--) {       if (a[i] >= b[i])         res = char(a[i] - b[i] +  0 ) + res;       else {         for (int j = i - 1; j >= 0; j--) {           if (a[j] !=  0 ) {             a[j]--;             break;           } else             a[j] =  9 ;         }         res = char(10 + a[i] - b[i] +  0 ) + res;       }     }     return res.find_first_not_of( 0 ) != -1                ? res.substr(res.find_first_not_of( 0 ))                :  0 ;   }   int compare(string a, string b) {     if (a.length() != b.length()) return a.length() > b.length();     for (int i = 0; i < a.length(); i++)       if (a[i] != b[i]) return a[i] > b[i];     return 2;   }   BigInt::BigInt(string s) {     value = s[0] ==  -  ? s.substr(1) : s;     sign = s[0] ==  -  && s.substr(1) !=  0 ;     value = s.find_first_not_of( -0 ) != -1 ? s.substr(s.find_first_not_of( -0 ))                                             :  0 ;   }   BigInt::BigInt(){};   BigInt::BigInt(long long n) : BigInt(toString(n)) {}   BigInt BigInt::operator+(BigInt &secondNumber) {     if (sign == secondNumber.sign)       return BigInt((sign ?  -  :   ) + add(value, secondNumber.value));     else if (compare(value, secondNumber.value) == 1)       return BigInt((sign ?  -  :   ) + sub(value, secondNumber.value));     else       return BigInt((secondNumber.sign ?  -  :   ) +                     sub(secondNumber.value, value));   }   BigInt BigInt::operator-(BigInt &secondNumber) {     BigInt a = *this,            b = BigInt((secondNumber.sign ?    :  - ) + secondNumber.value);     return a + b;   }   bool BigInt::operator==(BigInt &secondNumber) {     return value == secondNumber.value && sign == secondNumber.sign;   }   bool BigInt::operator!=(BigInt &secondNumber) {     return !(*this == secondNumber);   }   bool BigInt::operator>(BigInt &secondNumber) {     BigInt res = *this - secondNumber;     return !res.sign && res.value !=  0 ;   }   bool BigInt::operator<(BigInt &secondNumber) {     return !(*this > secondNumber) && *this != secondNumber;   }   BigInt BigInt::operator++(int dummy) {     BigInt a = *this, b = BigInt( 1 );     *this = a + b;     return a;   }   BigInt BigInt::operator--(int dummy) {     BigInt a = *this, b = BigInt( 1 );     *this = a - b;     return a;   }   ostream &operator<<(ostream &out, const BigInt &c) {     out << (c.sign ?  -  :   ) << c.value;     return out;   }   istream &operator>>(istream &in, BigInt &c) {     string s;     in >> s;     c = BigInt(s);     return in;   }   int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   int main() {     long long n;     scanf( %lld , &n);     map<long long, long long> f;     long long x, cnt = 0;     long long sum = 0;     BigInt ans = 0;     for (int i = 0; i < n; i++) {       scanf( %lld , &x);       long long prev = cnt - f[x] - f[x + 1] - f[x - 1];       long long nwSum =           sum - (f[x] * x) - (f[x + 1] * (x + 1)) - (f[x - 1] * (x - 1));       BigInt add = prev * x - nwSum;       ans = ans + add;       sum += x;       cnt++;       f[x]++;     }     cout << ans;   }