#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdio>
#include <cmath>

using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
	vector<int> z;
	int sign;

	bigint() :
		sign(1) {
	}

	bigint(long long v) {
		*this = v;
	}

	bigint(const string &s) {
		read(s);
	}

	void operator=(const bigint &v) {
		sign = v.sign;
		z = v.z;
	}

	void operator=(long long v) {
		sign = 1;
		if (v < 0)
			sign = -1, v = -v;
		z.clear();
		for (; v > 0; v = v / base)
			z.push_back(v % base);
	}

	bigint operator+(const bigint &v) const {
		if (sign == v.sign) {
			bigint res = v;

			for (int i = 0, carry = 0; i < (int)max(z.size(), v.z.size()) || carry; ++i) {
				if (i == (int)res.z.size())
					res.z.push_back(0);
				res.z[i] += carry + (i < (int)z.size() ? z[i] : 0);
				carry = res.z[i] >= base;
				if (carry)
					res.z[i] -= base;
			}
			return res;
		}
		return *this - (-v);
	}

	bigint operator-(const bigint &v) const {
		if (sign == v.sign) {
			if (abs() >= v.abs()) {
				bigint res = *this;
				for (int i = 0, carry = 0; i < (int)v.z.size() || carry; ++i) {
					res.z[i] -= carry + (i < (int)v.z.size() ? v.z[i] : 0);
					carry = res.z[i] < 0;
					if (carry)
						res.z[i] += base;
				}
				res.trim();
				return res;
			}
			return -(v - *this);
		}
		return *this + (-v);
	}

	void operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int)z.size() || carry; ++i) {
			if (i == (int)z.size())
				z.push_back(0);
			long long cur = z[i] * (long long)v + carry;
			carry = (int)(cur / base);
			z[i] = (int)(cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(int v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
		int norm = base / (b1.z.back() + 1);
		bigint a = a1.abs() * norm;
		bigint b = b1.abs() * norm;
		bigint q, r;
		q.z.resize(a.z.size());

		for (int i = a.z.size() - 1; i >= 0; i--) {
			r *= base;
			r += a.z[i];
			int s1 = b.z.size() < r.z.size() ? r.z[b.z.size()] : 0;
			int s2 = b.z.size() - 1 < r.z.size() ? r.z[b.z.size() - 1] : 0;
			int d = ((long long)s1 * base + s2) / b.z.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.z[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}

	friend bigint sqrt(const bigint &a1) {
		bigint a = a1;
		while (a.z.empty() || a.z.size() % 2 == 1)
			a.z.push_back(0);

		int n = a.z.size();

		int firstDigit = (int)sqrt((double)a.z[n - 1] * base + a.z[n - 2]);
		int norm = base / (firstDigit + 1);
		a *= norm;
		a *= norm;
		while (a.z.empty() || a.z.size() % 2 == 1)
			a.z.push_back(0);

		bigint r = (long long)a.z[n - 1] * base + a.z[n - 2];
		firstDigit = (int)sqrt((double)a.z[n - 1] * base + a.z[n - 2]);
		int q = firstDigit;
		bigint res;

		for (int j = n / 2 - 1; j >= 0; j--) {
			for (; ; --q) {
				bigint r1 = (r - (res * 2 * base + q) * q) * base * base + (j > 0 ? (long long)a.z[2 * j - 1] * base + a.z[2 * j - 2] : 0);
				if (r1 >= 0) {
					r = r1;
					break;
				}
			}
			res *= base;
			res += q;

			if (j > 0) {
				int d1 = res.z.size() + 2 < r.z.size() ? r.z[res.z.size() + 2] : 0;
				int d2 = res.z.size() + 1 < r.z.size() ? r.z[res.z.size() + 1] : 0;
				int d3 = res.z.size() < r.z.size() ? r.z[res.z.size()] : 0;
				q = ((long long)d1 * base * base + (long long)d2 * base + d3) / (firstDigit * 2);
			}
		}

		res.trim();
		return res / norm;
	}

	bigint operator/(const bigint &v) const {
		return divmod(*this, v).first;
	}

	bigint operator%(const bigint &v) const {
		return divmod(*this, v).second;
	}

	void operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int)z.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = z[i] + rem * (long long)base;
			z[i] = (int)(cur / v);
			rem = (int)(cur % v);
		}
		trim();
	}

	bigint operator/(int v) const {
		bigint res = *this;
		res /= v;
		return res;
	}

	int operator%(int v) const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = z.size() - 1; i >= 0; --i)
			m = (z[i] + m * (long long)base) % v;
		return m * sign;
	}

	void operator+=(const bigint &v) {
		*this = *this + v;
	}
	void operator-=(const bigint &v) {
		*this = *this - v;
	}
	void operator*=(const bigint &v) {
		*this = *this * v;
	}
	void operator/=(const bigint &v) {
		*this = *this / v;
	}

	bool operator<(const bigint &v) const {
		if (sign != v.sign)
			return sign < v.sign;
		if (z.size() != v.z.size())
			return z.size() * sign < v.z.size() * v.sign;
		for (int i = z.size() - 1; i >= 0; i--)
			if (z[i] != v.z[i])
				return z[i] * sign < v.z[i] * sign;
		return false;
	}

	bool operator>(const bigint &v) const {
		return v < *this;
	}
	bool operator<=(const bigint &v) const {
		return !(v < *this);
	}
	bool operator>=(const bigint &v) const {
		return !(*this < v);
	}
	bool operator==(const bigint &v) const {
		return !(*this < v) && !(v < *this);
	}
	bool operator!=(const bigint &v) const {
		return *this < v || v < *this;
	}

	void trim() {
		while (!z.empty() && z.back() == 0)
			z.pop_back();
		if (z.empty())
			sign = 1;
	}

	bool isZero() const {
		return z.empty() || (z.size() == 1 && !z[0]);
	}

	bigint operator-() const {
		bigint res = *this;
		res.sign = -sign;
		return res;
	}

	bigint abs() const {
		bigint res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue() const {
		long long res = 0;
		for (int i = z.size() - 1; i >= 0; i--)
			res = res * base + z[i];
		return res * sign;
	}

	friend bigint gcd(const bigint &a, const bigint &b) {
		return b.isZero() ? a : gcd(b, a % b);
	}
	friend bigint lcm(const bigint &a, const bigint &b) {
		return a / gcd(a, b) * b;
	}

	void read(const string &s) {
		sign = 1;
		z.clear();
		int pos = 0;
		while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= base_digits) {
			int x = 0;
			for (int j = max(pos, i - base_digits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			z.push_back(x);
		}
		trim();
	}

	friend istream& operator>>(istream &stream, bigint &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator<<(ostream &stream, const bigint &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.z.empty() ? 0 : v.z.back());
		for (int i = (int)v.z.size() - 2; i >= 0; --i)
			stream << setw(base_digits) << setfill('0') << v.z[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int)p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int)a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.push_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.push_back((int)cur);
		while (!res.empty() && res.back() == 0)
			res.pop_back();
		return res;
	}

	typedef vector<long long> vll;

	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int)a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int)r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int)a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

	bigint operator*(const bigint &v) const {
		vector<int> a6 = convert_base(this->z, base_digits, 6);
		vector<int> b6 = convert_base(v.z, base_digits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.push_back(0);
		while (b.size() < a.size())
			b.push_back(0);
		while (a.size() & (a.size() - 1))
			a.push_back(0), b.push_back(0);
		vll c = karatsubaMultiply(a, b);
		bigint res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int)c.size(); i++) {
			long long cur = c[i] + carry;
			res.z.push_back((int)(cur % 1000000));
			carry = (int)(cur / 1000000);
		}
		res.z = convert_base(res.z, 6, base_digits);
		res.trim();
		return res;
	}
};

int n;
int numbers[200001];
std::map<int, int> seen;
std::vector<long long> sums;
std::vector<long long> sums2;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &numbers[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		int sub = seen[numbers[i] - 1] + seen[numbers[i]] + seen[numbers[i] + 1];
		sums.push_back((long long)(n - 1 - i - sub) * (-numbers[i]));
		seen[numbers[i]]++;
	}
	seen.clear();
	for (int i = 0; i < n; i++) {
		int sub = seen[numbers[i] - 1] + seen[numbers[i]] + seen[numbers[i] + 1];
		sums.push_back((long long)(i - sub) * (numbers[i]));
		seen[numbers[i]]++;
	}

	bigint result = 0;
	for (int i = 0; i < sums.size(); i++) {
		result += sums[i];
	}
	cout << result << endl;

	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define ll  long long int
#define oo 1e9
#define pi 3.14159265359

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 4000000000000000000LL
#define INF 1000000000
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcountll(a)

using namespace std;

map<int, int> m;
int arr[200007];

const int base = 1000000000;
const int base_digits = 9;

struct BigInt {
  vector<int> a;
  int sign;

  BigInt() :
      sign(1) {
  }

  BigInt(long long v) {
    *this = v;
  }

  BigInt(const string &s) {
    read(s);
  }

  void operator=(const BigInt &v) {
    sign = v.sign;
    a = v.a;
  }

  void operator=(long long v) {
    sign = 1;
    if (v < 0)
      sign = -1, v = -v;
    for (; v > 0; v = v / base)
      a.push_back(v % base);
  }

  BigInt operator+(const BigInt &v) const {
    if (sign == v.sign) {
      BigInt res = v;

      for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry;
          ++i) {
        if (i == (int) res.a.size())
          res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
          res.a[i] -= base;
      }
      return res;
    }
    return *this - (-v);
  }

  BigInt operator-(const BigInt &v) const {
    if (sign == v.sign) {
      if (abs() >= v.abs()) {
        BigInt res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
          res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
          carry = res.a[i] < 0;
          if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
      }
      return -(v - *this);
    }
    return *this + (-v);
  }

  void operator*=(int v) {
    if (v < 0)
      sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
      if (i == (int) a.size())
        a.push_back(0);
      long long cur = a[i] * (long long) v + carry;
      carry = (int) (cur / base);
      a[i] = (int) (cur % base);
      //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
  }

  BigInt operator*(int v) const {
    BigInt res = *this;
    res *= v;
    return res;
  }

  friend pair<BigInt, BigInt> divmod(const BigInt &a1, const BigInt &b1) {
    int norm = base / (b1.a.back() + 1);
    BigInt a = a1.abs() * norm;
    BigInt b = b1.abs() * norm;
    BigInt q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
      r *= base;
      r += a.a[i];
      int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
      int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
      int d = ((long long) base * s1 + s2) / b.a.back();
      r -= b * d;
      while (r < 0)
        r += b, --d;
      q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
  }

  BigInt operator/(const BigInt &v) const {
    return divmod(*this, v).first;
  }

  BigInt operator%(const BigInt &v) const {
    return divmod(*this, v).second;
  }

  void operator/=(int v) {
    if (v < 0)
      sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
      long long cur = a[i] + rem * (long long) base;
      a[i] = (int) (cur / v);
      rem = (int) (cur % v);
    }
    trim();
  }

  BigInt operator/(int v) const {
    BigInt res = *this;
    res /= v;
    return res;
  }

  int operator%(int v) const {
    if (v < 0)
      v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
      m = (a[i] + m * (long long) base) % v;
    return m * sign;
  }

  void operator+=(const BigInt &v) {
    *this = *this + v;
  }
  void operator-=(const BigInt &v) {
    *this = *this - v;
  }
  void operator*=(const BigInt &v) {
    *this = *this * v;
  }
  void operator/=(const BigInt &v) {
    *this = *this / v;
  }

  bool operator<(const BigInt &v) const {
    if (sign != v.sign)
      return sign < v.sign;
    if (a.size() != v.a.size())
      return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
      if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
  }

  bool operator>(const BigInt &v) const {
    return v < *this;
  }
  bool operator<=(const BigInt &v) const {
    return !(v < *this);
  }
  bool operator>=(const BigInt &v) const {
    return !(*this < v);
  }
  bool operator==(const BigInt &v) const {
    return !(*this < v) && !(v < *this);
  }
  bool operator!=(const BigInt &v) const {
    return *this < v || v < *this;
  }

  void trim() {
    while (!a.empty() && !a.back())
      a.pop_back();
    if (a.empty())
      sign = 1;
  }

  bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
  }

  BigInt operator-() const {
    BigInt res = *this;
    res.sign = -sign;
    return res;
  }

  BigInt abs() const {
    BigInt res = *this;
    res.sign *= res.sign;
    return res;
  }

  long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
      res = res * base + a[i];
    return res * sign;
  }

  friend BigInt gcd(const BigInt &a, const BigInt &b) {
    return b.isZero() ? a : gcd(b, a % b);
  }
  friend BigInt lcm(const BigInt &a, const BigInt &b) {
    return a / gcd(a, b) * b;
  }

  void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
      if (s[pos] == '-')
        sign = -sign;
      ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
      int x = 0;
      for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
      a.push_back(x);
    }
    trim();
  }

  friend istream& operator>>(istream &stream, BigInt &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
  }

  friend ostream& operator<<(ostream &stream, const BigInt &v) {
    if (v.sign == -1)
      stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
      stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
  }

  static vector<int> convert_base(const vector<int> &a, int old_digits,
      int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
      p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
      cur += a[i] * p[cur_digits];
      cur_digits += old_digits;
      while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
      }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
      res.pop_back();
    return res;
  }

  typedef vector<long long> vll;

  static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          res[i + j] += a[i] * b[j];
      return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
      a2[i] += a1[i];
    for (int i = 0; i < k; i++)
      b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
      r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
      r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
      res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
      res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
      res[i + n] += a2b2[i];
    return res;
  }

  BigInt operator*(const BigInt &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
      a.push_back(0);
    while (b.size() < a.size())
      b.push_back(0);
    while (a.size() & (a.size() - 1))
      a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    BigInt res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
      long long cur = c[i] + carry;
      res.a.push_back((int) (cur % 1000000));
      carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
  }
};
map<LL,LL>mp;
vector<LL>p[200200];
LL sum[200200];
LL get_ans(int x , int i)
{
    LL idx1 = upper_bound(all(p[mp[x]]) , i)-p[mp[x]].begin();
    idx1=p[mp[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<LL>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mp[x])
            mp[x]=++pos;
        p[mp[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    BigInt ans =  0 ;
    for(int i=0; i<n; i++)
    {
       LL s =  0;
       LL t = sum[n]-sum[i];
       LL k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<ans ;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define ll  long long int
#define oo 1e9
#define pi 3.14159265359

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 4000000000000000000LL
#define INF 1000000000
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcountll(a)

using namespace std;

map<int, int> m;
int arr[200007];

const int base = 1000000000;
const int base_digits = 9;

struct BigInt {
  vector<int> a;
  int sign;

  BigInt() :
      sign(1) {
  }

  BigInt(long long v) {
    *this = v;
  }

  BigInt(const string &s) {
    read(s);
  }

  void operator=(const BigInt &v) {
    sign = v.sign;
    a = v.a;
  }

  void operator=(long long v) {
    sign = 1;
    if (v < 0)
      sign = -1, v = -v;
    for (; v > 0; v = v / base)
      a.push_back(v % base);
  }

  BigInt operator+(const BigInt &v) const {
    if (sign == v.sign) {
      BigInt res = v;

      for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry;
          ++i) {
        if (i == (int) res.a.size())
          res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
          res.a[i] -= base;
      }
      return res;
    }
    return *this - (-v);
  }

  BigInt operator-(const BigInt &v) const {
    if (sign == v.sign) {
      if (abs() >= v.abs()) {
        BigInt res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
          res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
          carry = res.a[i] < 0;
          if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
      }
      return -(v - *this);
    }
    return *this + (-v);
  }

  void operator*=(int v) {
    if (v < 0)
      sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
      if (i == (int) a.size())
        a.push_back(0);
      long long cur = a[i] * (long long) v + carry;
      carry = (int) (cur / base);
      a[i] = (int) (cur % base);
      //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
  }

  BigInt operator*(int v) const {
    BigInt res = *this;
    res *= v;
    return res;
  }

  friend pair<BigInt, BigInt> divmod(const BigInt &a1, const BigInt &b1) {
    int norm = base / (b1.a.back() + 1);
    BigInt a = a1.abs() * norm;
    BigInt b = b1.abs() * norm;
    BigInt q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
      r *= base;
      r += a.a[i];
      int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
      int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
      int d = ((long long) base * s1 + s2) / b.a.back();
      r -= b * d;
      while (r < 0)
        r += b, --d;
      q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
  }

  BigInt operator/(const BigInt &v) const {
    return divmod(*this, v).first;
  }

  BigInt operator%(const BigInt &v) const {
    return divmod(*this, v).second;
  }

  void operator/=(int v) {
    if (v < 0)
      sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
      long long cur = a[i] + rem * (long long) base;
      a[i] = (int) (cur / v);
      rem = (int) (cur % v);
    }
    trim();
  }

  BigInt operator/(int v) const {
    BigInt res = *this;
    res /= v;
    return res;
  }

  int operator%(int v) const {
    if (v < 0)
      v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
      m = (a[i] + m * (long long) base) % v;
    return m * sign;
  }

  void operator+=(const BigInt &v) {
    *this = *this + v;
  }
  void operator-=(const BigInt &v) {
    *this = *this - v;
  }
  void operator*=(const BigInt &v) {
    *this = *this * v;
  }
  void operator/=(const BigInt &v) {
    *this = *this / v;
  }

  bool operator<(const BigInt &v) const {
    if (sign != v.sign)
      return sign < v.sign;
    if (a.size() != v.a.size())
      return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
      if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
  }

  bool operator>(const BigInt &v) const {
    return v < *this;
  }
  bool operator<=(const BigInt &v) const {
    return !(v < *this);
  }
  bool operator>=(const BigInt &v) const {
    return !(*this < v);
  }
  bool operator==(const BigInt &v) const {
    return !(*this < v) && !(v < *this);
  }
  bool operator!=(const BigInt &v) const {
    return *this < v || v < *this;
  }

  void trim() {
    while (!a.empty() && !a.back())
      a.pop_back();
    if (a.empty())
      sign = 1;
  }

  bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
  }

  BigInt operator-() const {
    BigInt res = *this;
    res.sign = -sign;
    return res;
  }

  BigInt abs() const {
    BigInt res = *this;
    res.sign *= res.sign;
    return res;
  }

  long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
      res = res * base + a[i];
    return res * sign;
  }

  friend BigInt gcd(const BigInt &a, const BigInt &b) {
    return b.isZero() ? a : gcd(b, a % b);
  }
  friend BigInt lcm(const BigInt &a, const BigInt &b) {
    return a / gcd(a, b) * b;
  }

  void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
      if (s[pos] == '-')
        sign = -sign;
      ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
      int x = 0;
      for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
      a.push_back(x);
    }
    trim();
  }

  friend istream& operator>>(istream &stream, BigInt &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
  }

  friend ostream& operator<<(ostream &stream, const BigInt &v) {
    if (v.sign == -1)
      stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
      stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
  }

  static vector<int> convert_base(const vector<int> &a, int old_digits,
      int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
      p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
      cur += a[i] * p[cur_digits];
      cur_digits += old_digits;
      while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
      }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
      res.pop_back();
    return res;
  }

  typedef vector<long long> vll;

  static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          res[i + j] += a[i] * b[j];
      return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
      a2[i] += a1[i];
    for (int i = 0; i < k; i++)
      b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
      r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
      r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
      res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
      res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
      res[i + n] += a2b2[i];
    return res;
  }

  BigInt operator*(const BigInt &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
      a.push_back(0);
    while (b.size() < a.size())
      b.push_back(0);
    while (a.size() & (a.size() - 1))
      a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    BigInt res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
      long long cur = c[i] + carry;
      res.a.push_back((int) (cur % 1000000));
      carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
  }
};
map<LL,LL>mp;
vector<LL>p[200200];
LL sum[200200];
LL get_ans(int x , int i)
{
    LL idx1 = upper_bound(all(p[mp[x]]) , i)-p[mp[x]].begin();
    idx1=p[mp[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<LL>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mp[x])
            mp[x]=++pos;
        p[mp[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    LL ans =  0 ;
    for(int i=0; i<n; i++)
    {
       LL s =  0;
       LL t = sum[n]-sum[i];
       LL k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<ans ;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define ll  long long int
#define oo 1e9
#define pi 3.14159265359

using namespace std;
typedef pair<ll,ll> lll;
typedef pair<ll,int> lli;
typedef pair<int,int> ii;

#define EL printf("\n")
#define OK printf("OK")
#define pb push_back
#define mp make_pair
#define ep emplace_back
#define X  first
#define Y  second
#define fillchar(a,x) memset(a, x, sizeof(a))
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)

const int base = 1e9;
typedef vector<int> BigInt;

void Set(BigInt &a) {
    while (a.size() > 1 && a.back() == 0) a.pop_back();
}

void Print(BigInt a) {
    Set(a);
    printf("%d", (a.size() == 0) ? 0 : a.back());
    FORD(i,a.size()-2,0) printf("%09d", a[i]); EL;
}

BigInt Integer(string s) {
    BigInt ans;
    if (s[0] == '-') return ans;
    if (s.size() == 0) {ans.pb(0); return ans;}
    while (s.size()%9 != 0) s = '0'+s;
    for (int i=0;i<s.size();i+=9) {
        int v = 0;
        for (int j=i;j<i+9;j++) v = v*10+(s[j]-'0');
        ans.insert(ans.begin(),v);
    }
    Set(ans);
    return ans;
}

BigInt Integer(char c[]) {
    string s = "";
    FOR(i,0,strlen(c)-1) s = s + c[i];
    return Integer(s);
}

BigInt Integer(ll x) {
    string s = "";
    while (x > 0) s = char(x%10+'0') + s, x /= 10;
    return Integer(s);
}

BigInt Integer(int x) {
    return Integer((ll) x);
}

void operator >> (istream &in, BigInt &a) {
    string s;
    getline(cin, s);
    a = Integer(s);
}

void operator << (ostream &out, BigInt a) {
    Print(a);
}

bool operator < (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    if (a.size() != b.size()) return (a.size() < b.size());
    FORD(i,a.size()-1,0)
        if (a[i] != b[i]) return (a[i] < b[i]);
    return false;
}

bool operator > (BigInt a, BigInt b) {
    return (b < a);
}

bool operator == (BigInt a, BigInt b) {
    return (!(a < b) && !(b < a));
}

bool operator <= (BigInt a, BigInt b) {
    return (a < b || a == b);
}

bool operator >= (BigInt a, BigInt b) {
    return (b < a || b == a);
}

bool operator < (BigInt a, int b) {
    return (a < Integer(b));
}

bool operator > (BigInt a, int b) {
    return (a > Integer(b));
}

bool operator == (BigInt a, int b) {
    return (a == Integer(b));
}

bool operator >= (BigInt a, int b) {
    return (a >= Integer(b));
}

bool operator <= (BigInt a, int b) {
    return (a <= Integer(b));
}

BigInt max(BigInt a, BigInt b) {
    if (a > b) return a;
    return b;
}

BigInt min(BigInt a, BigInt b) {
    if (a < b) return a;
    return b;
}

BigInt operator + (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    BigInt ans;
    int carry = 0;
    FOR(i,0,max(a.size(), b.size())-1) {
        if (i < a.size()) carry += a[i];
        if (i < b.size()) carry += b[i];
        ans.pb(carry%base);
        carry /= base;
    }
    if (carry) ans.pb(carry);
    Set(ans);
    return ans;
}

BigInt operator + (BigInt a, int b) {
    return a + Integer(b);
}

BigInt operator ++ (BigInt &a) { // ++a
    a = a + 1;
    return a;
}

void operator += (BigInt &a, BigInt b) {
    a = a + b;
}

void operator += (BigInt &a, int b) {
    a = a + b;
}

BigInt operator - (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    BigInt ans;
    int carry = 0;
    FOR(i,0,a.size()-1) {
        carry += a[i] - (i < b.size() ? b[i] : 0);
        if (carry < 0) ans.pb(carry+base), carry = -1;
        else ans.pb(carry), carry = 0;
    }
    Set(ans);
    return ans;
}

BigInt operator - (BigInt a, int b) {
    return a - Integer(b);
}

void operator -- (BigInt &a) { // --a
    a = a - 1;
}

void operator -= (BigInt &a, BigInt b) {
    a = a + b;
}

void operator -= (BigInt &a, int b) {
    a = a - b;
}

BigInt operator * (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    BigInt ans;
    ans.assign(a.size()+b.size(), 0);
    FOR(i,0,a.size()-1) {
        ll carry = 0ll;
        for (int j=0;j<b.size() || carry > 0;j++) {
            ll s = ans[i+j] + carry + (ll)a[i]*(j<b.size()?(ll)b[j]:0ll);
            ans[i+j] = s%base;
            carry = s/base;
        }
    }
    Set(ans);
    return ans;
}

BigInt operator * (BigInt a, int b) {
    return a * Integer(b);
}

void operator *= (BigInt &a, BigInt b) {
    a = a * b;
}

void operator *= (BigInt &a, int b) {
    a = a * b;
}

BigInt operator / (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    if (b == Integer(0)) return Integer("-1");
    BigInt ans, cur;
    FORD(i,a.size()-1,0) {
        cur.insert(cur.begin(), a[i]);
        int x = 0, L = 0, R = base;
        while (L <= R) {
            int mid = (L+R)>>1;
            if (b*Integer(mid) > cur) {
                x = mid;
                R = mid-1;
            }
            else
                L = mid+1;
        }
        cur = cur - Integer(x-1)*b;
        ans.insert(ans.begin(),x-1);
    }
    Set(ans);
    return ans;
}

BigInt operator / (BigInt a, int b) {
    Set(a);
    BigInt ans;
    ll cur = 0ll;
    FORD(i,a.size()-1,0) {
        cur = (cur*(ll)base + (ll)a[i]);
        ans.insert(ans.begin(),cur/b);
        cur %= b;
    }
    Set(ans);
    return ans;
}

void operator /= (BigInt &a, BigInt b) {
    a = a / b;
}

void operator /= (BigInt &a, int b) {
    a = a / b;
}

BigInt operator % (BigInt a, BigInt b) {
    Set(a);
    Set(b);
    if (b == Integer(0)) return Integer("-1");
    BigInt ans;
    FORD(i,a.size()-1,0) {
        ans.insert(ans.begin(), a[i]);
        int x = 0, L = 0, R = base;
        while (L <= R) {
            int mid = (L+R)>>1;
            if (b*Integer(mid) > ans) {
                x = mid;
                R = mid-1;
            }
            else
                L = mid+1;
        }
        ans = ans - Integer(x-1)*b;
    }
    Set(ans);
    return ans;
}

int operator % (BigInt a, int b) {
    Set(a);
    if (b == 0) return -1;
    int ans = 0;
    FORD(i,a.size()-1,0)
        ans = (ans*(base%b) + a[i]%b)%b;
    return ans;
}

void operator %= (BigInt &a, BigInt b) {
    a = a % b;
}

void operator %= (BigInt &a, int b) {
    a = a % Integer(b);
}

BigInt gcd(BigInt a, BigInt b) {
    Set(a);
    Set(b);
    while (b > Integer(0)) {
        BigInt r = a%b;
        a = b;
        b = r;
    }
    Set(a);
    return a;
}

BigInt lcm(BigInt a, BigInt b) {
    return (a*b/gcd(a,b));
}

BigInt sqrt(BigInt a) {
    BigInt x0 = a, x1 = (a+1)/2;
    while (x1 < x0) {
        x0 = x1;
        x1 = (x1+a/x1)/2;
    }
    return x0;
}

BigInt pow(BigInt a, BigInt b) {
    if (b == Integer(0)) return Integer(1);
    BigInt tmp = pow(a, b/2);
    if (b%2 == 0) return tmp * tmp;
    return tmp * tmp * a;
}

BigInt pow(BigInt a, int b) {
    return pow(a,(Integer(b)));
}

int log(int n, BigInt a) { // log_n(a)
    Set(a);
    int ans = 0;
    while (a > Integer(1)) {
        ans++;
        a /= n;
    }
    return ans;
}
map<ll,ll>mpa;
vector<ll>p[200200];
ll sum[200200];
ll get_ans(int x , int i)
{
    ll idx1 = upper_bound(all(p[mpa[x]]) , i)-p[mpa[x]].begin();
    idx1=p[mpa[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<ll>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mpa[x])
            mpa[x]=++pos;
        p[mpa[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    BigInt ans =  Integer(0) ;
    for(int i=0; i<n; i++)
    {
       ll s =  0;
       ll t = sum[n]-sum[i];
       ll k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<ans ;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
map<LL,LL>mp;
vector<LL>p[200200];
LL sum[200200];
LL get_ans(int x , int i)
{
    LL idx1 = upper_bound(all(p[mp[x]]) , i)-p[mp[x]].begin();
    idx1=p[mp[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<LL>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mp[x])
            mp[x]=++pos;
        p[mp[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    long double ans =  0 ;
    for(int i=0; i<n; i++)
    {
       LL s =  0;
       LL t = sum[n]-sum[i];
       LL k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<ans ;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
map<LL,LL>mp;
vector<LL>p[200200];
LL sum[200200];
LL get_ans(int x , int i)
{
    LL idx1 = upper_bound(all(p[mp[x]]) , i)-p[mp[x]].begin();
    idx1=p[mp[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<LL>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mp[x])
            mp[x]=++pos;
        p[mp[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    LL ans =  0 ;
    for(int i=0; i<n; i++)
    {
       LL s =  0;
       LL t = sum[n]-sum[i];
       LL k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<ans ;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
map<LL,LL>mp;
vector<LL>p[200200];
LL sum[200200];
LL get_ans(int x , int i)
{
    LL idx1 = upper_bound(all(p[mp[x]]) , i)-p[mp[x]].begin();
    idx1=p[mp[x]].size()-idx1;
    return idx1 ;
}
int main()
{
    int n ; cin>>n;
    int pos =  0 ;
    vector<LL>a;
    for(int i=0;i<n;i++)
    {
        int x; scanf("%d" , &x);
        a.pb(x);
        if(!mp[x])
            mp[x]=++pos;
        p[mp[x]].pb(i);
    }
    for(int i=0;i<n;i++)
        sum[i+1]=sum[i]+a[i];
    long double ans =  0 ;
    for(int i=0; i<n; i++)
    {
       LL s =  0;
       LL t = sum[n]-sum[i];
       LL k=get_ans(a[i] , i );
       t-=k*a[i];
       s=get_ans(a[i]+1 , i ); k+=s;
       t-=s*(a[i]+1);
       s=get_ans(a[i]-1 , i ); k+=s;
       t-=s*(a[i]-1);
       ans = ans + t-(n-i-k)*(a[i]);
    }
    cout<<setprecision(30)<<ans ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 5007;
const LD EPS = 1e-7;

unordered_multiset <int> S;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL ans = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		int a;
		cin >> a;
		ans += (2 * i - n - 1LL) * a;
		ans += S.count(a + 1);
		ans -= S.count(a - 1);
		S.insert(a);
	}
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 5007;
const LD EPS = 1e-7;

multiset <int> S;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL ans = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		int a;
		cin >> a;
		ans += (2 * i - n - 1LL) * a;
		ans += S.count(a + 1);
		ans -= S.count(a - 1);
		S.insert(a);
	}
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL s = 0;
	unsigned long long ansp = 0, ansm = 0, a1 = 0, a2 = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		s += (2 * i - n - 1LL) * A[i].first;
		A[i].second = i;
	}
	if (s > 0)
		a1 = s;
	else
		a2 = -s;
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		ansp += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		ansm += lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
	}
	if (ansp + a1 >= ansm + a2)
		cout << ansp + a1 - (ansm + a2);
	else
		cout << '-' << ansm + a2 - (ansp + a1);
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

const LL B = 1000000000000000000;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL a = 0, b = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		b += (2 * i - n - 1LL) * A[i].first;
		if (b >= B)
		{
			b -= B;
			++a;
		}
		if (b <= -B)
		{
			b += B;
			--a;
		}
		A[i].second = i;
	}
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		b += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		b -= lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
		if (b >= B)
		{
			b -= B;
			++a;
		}
		if (b <= -B)
		{
			b += B;
			--a;
		}
	}
	if (a > 0 && b < 0)
	{
		b += B;
		--a;
	}
	if (a < 0 && b > 0)
	{
		b -= B;
		++a;
	}
	if (a == 0)
	{
		cout << b;
		return 0;
	}
	if (b < 0)
		b = -b;
	vector <int> D;
	REP(i, 18)
	{
		D.push_back(b % 10);
		b /= 10;
	}
	cout << a;
	RFOR(i, 18, 0)
		cout << D[i];
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL ans = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		ans += (2 * i - n - 1LL) * A[i].first;
		A[i].second = i;
	}
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		ans += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		ans -= lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
	}
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

const LL B = 1000000000000000000;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL a = 0, b = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		b += (2 * i - n - 1LL) * A[i].first;
		a += b / B;
		b %= B;
		A[i].second = i;
	}
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		b += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		b -= lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
		a += b / B;
		b %= B;
	}
	if (a > 0 && b < 0)
	{
		b += B;
		--a;
	}
	if (a < 0 && b > 0)
	{
		b -= B;
		++a;
	}
	if (a == 0)
	{
		cout << b;
		return 0;
	}
	if (a > 0)
	{
		cout << a << b;
		return 0;
	}
	cout << a << -b;
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	unsigned long long ansp = 0, ansm = 0, dp = 0, dm = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		LL cur = (2 * i - n - 1LL) * A[i].first;
		if (cur > 0)
			ansp += cur;
		else
			ansm += -cur;
		A[i].second = i;
	}
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		dp += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		dm += lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
	}
	if (ansp + dp >= ansm + dm)
		cout << ansp + dp - (ansm + dm);
	else
		cout << '-' << ansm + dp - (ansp + dm);
	//cout << endl; system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_set>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

PII A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	LL s = 0;
	unsigned long long ansp = 0, ansm = 0, a1 = 0, a2 = 0;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> A[i].first;
		s += (2 * i - n - 1LL) * A[i].first;
		A[i].second = i;
	}
	if (s > 0)
		a1 = s;
	else
		a2 = -s;
	sort(A + 1, A + n + 1);
	FOR(i, 1, n + 1)
	{
		PII *p = lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, A[i].second));
		ansp += p - lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, 0));
		ansm += lower_bound(A + 1, A + n + 1, MP(A[i].first + 1, n + 1)) - p;
	}
	if (ansp + a1 > ansm + a2)
		cout << ansp + a1 - (ansm + a2);
	else
		cout << '-' << ansm + a2 - (ansp + a1);
	//cout << endl; system("pause");
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
map<int, int>mp;
int N, A[200004];
int main() {
	int i;
	cin >> N;
	ll sum = 0;
	for (i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
		mp[A[i]]++;
	}
	ll ans = 0, a, b, c; ull ans1, ans2;
	ans1 = ans2 = 0;
	for (i = 0; i < N - 1; i++) {
		sum -= A[i];
		mp[A[i]]--;
		a = sum;
		b = N - 1 - i;
		c = mp[A[i] - 1] + mp[A[i]] + mp[A[i] + 1];
		a -= (ll)mp[A[i] - 1] * (A[i] - 1) + (ll)mp[A[i]] * A[i] + (ll)mp[A[i] + 1] * (A[i] + 1);
		a -= (b - c)*A[i];
		if (a < 0) ans2 -= a;
		else ans1 += a;
	}
	if (ans1 == ans2) cout << 0;
	else if (ans1 > ans2) cout << ans1 - ans2;
	else {
		cout << "-" << ans2 - ans1;
	}
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef long long ll;
map<int, int>mp;
int N, A[200004];
int main() {
	int i;
	cin >> N;
	ll sum = 0;
	for (i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
		mp[A[i]]++;
	}
	ll ans = 0, a, b, c;
	for (i = 0; i < N - 1; i++) {
		sum -= A[i];
		mp[A[i]]--;
		a = sum;
		b = N - 1 - i;
		c = mp[A[i] - 1] + mp[A[i]] + mp[A[i] + 1];
		a -= (ll)mp[A[i] - 1] * (A[i] - 1) + (ll)mp[A[i]] * A[i] + (ll)mp[A[i] + 1] * (A[i] + 1);
		a -= (b - c)*A[i];
		ans += a;
	}
	cout << ans;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct BIGNUM {
	int cnt;
	int wfSign;
	int dig[200];
};
void chengfa(BIGNUM &x, BIGNUM &y, BIGNUM &z) {
	int i, j;
	int s = x.cnt + y.cnt + 1;
	if (s >= 200) {
		s = 199;
	}
	for (i = 0; i <= s; i++) {
		z.dig[i] = 0;
	}
	for (i = 0; i < x.cnt; i++) {
		for (j = 0; j < y.cnt; j++) {
			z.dig[i + j] += x.dig[i] * y.dig[j];
		}
	}
	for (i = 0; i <= s; i++) {
		z.dig[i + 1] += z.dig[i] / 10000;
		z.dig[i] %= 10000;
	}
	i = s;
	while (z.dig[i] == 0) {
		i--;
	}
	z.cnt = i + 1;
	z.wfSign = x.wfSign * y.wfSign;
}
bool isBigger(BIGNUM &x, BIGNUM &y) {
	if (x.cnt > y.cnt) {
		return 1;
	}
	else if (x.cnt < y.cnt) {
		return 0;
	}
	int i;
	for (i = x.cnt - 1; i >= 0; i--) {
		if (x.dig[i] > y.dig[i]) {
			return true;
		}
		else if (x.dig[i] < y.dig[i]) {
			return false;
		}
	}
	return false;
}
void showRes(BIGNUM &rs) {
	if (rs.wfSign == -1) {
		printf("-");
	}
	printf("%d", rs.dig[rs.cnt - 1]);
	int i;
	for (i = rs.cnt - 2; i >= 0; i--) {
		printf("%04d", rs.dig[i]);
	}
	printf("\n");
}
void jiafa(BIGNUM &x, BIGNUM &y) {
	if (x.wfSign == -1 && y.wfSign == -1) {
		x.wfSign = 1;
		y.wfSign = 1;
		jiafa(x, y);
		x.wfSign = -1;
		return;
	}
	if (x.wfSign * y.wfSign == -1) {
		bool f = isBigger(x, y);
		if (f && x.wfSign == -1) {
			x.wfSign = 1;
			y.wfSign = -1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
		else if (!f && y.wfSign == -1) {
			x.wfSign = -1;
			y.wfSign = 1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
	}
	int s = x.cnt < y.cnt ? x.cnt : y.cnt;
	int i;
	for (i = 0; i < s; i++) {
		x.dig[i] = x.dig[i] * x.wfSign + y.dig[i] * y.wfSign;
	}
	while (i < y.cnt) {
		x.dig[i] = y.wfSign * y.dig[i];
		i++;
	}

	s = x.cnt > y.cnt ? x.cnt : y.cnt;
	x.dig[s] = 0;
	for (i = 0; i < s; i++) {
		if (x.dig[i] < 0) {
			x.dig[i] += 10000;
			x.dig[i + 1] --;
		}
		else {
			x.dig[i + 1] += x.dig[i] / 10000;
			x.dig[i] %= 10000;
		}
	}
	i = s;
	while (i > 0 && x.dig[i] == 0) {
		i--;
	}
	x.cnt = i + 1;
	x.wfSign = 1;
}
void init(BIGNUM &x, int val) {
	int i = 0;
	x.dig[0] = 0;
	if (val < 0) {
		x.wfSign = -1;
		val *= -1;
	}
	else {
		x.wfSign = 1;
	}
	while (val) {
		x.dig[i] = val % 10000;
		val /= 10000;
		i++;
	}
	if (i == 0) { i = 1; }
	x.cnt = i;
}
int n, m;
int a[N], b[N], c[N];
int wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	int rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	BIGNUM x, y, z, rs;
	rs.wfSign = 1;
	rs.cnt = 1;
	rs.dig[0] = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		init(x, i - n + i + 1);
		init(y, a[i]);
		chengfa(x, y, z);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
		//ans += (long long)(i - n + i + 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	//printf("-------------------------\n");
	for (i = n - 1; i >= 0; i--) {
		int v = wf(a[i]);
		init(z, v);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
	}
	//printf("%lld\n", ans);
	showRes(rs);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct BIGNUM {
	int cnt;
	int wfSign = 1;
	int dig[200];
};
void chengfa(BIGNUM &x, BIGNUM &y, BIGNUM &z) {
	int i, j;
	int s = x.cnt + y.cnt + 1;
	if (s >= 200) {
		s = 199;
	}
	for (i = 0; i <= s; i++) {
		z.dig[i] = 0;
	}
	for (i = 0; i < x.cnt; i++) {
		for (j = 0; j < y.cnt; j++) {
			z.dig[i + j] += x.dig[i] * y.dig[j];
		}
	}
	for (i = 0; i <= s; i++) {
		z.dig[i + 1] += z.dig[i] / 10000;
		z.dig[i] %= 10000;
	}
	i = s;
	while (z.dig[i] == 0) {
		i--;
	}
	z.cnt = i + 1;
	z.wfSign = x.wfSign * y.wfSign;
}
bool isBigger(BIGNUM &x, BIGNUM &y) {
	if (x.cnt > y.cnt) {
		return 1;
	}
	else if (x.cnt < y.cnt) {
		return 0;
	}
	int i;
	for (i = x.cnt - 1; i >= 0; i--) {
		if (x.dig[i] > y.dig[i]) {
			return true;
		}
		else if (x.dig[i] < y.dig[i]) {
			return false;
		}
	}
	return false;
}
void showRes(BIGNUM &rs) {
	if (rs.wfSign == -1) {
		printf("-");
	}
	printf("%d", rs.dig[rs.cnt - 1]);
	int i;
	for (i = rs.cnt - 2; i >= 0; i--) {
		printf("%04d", rs.dig[i]);
	}
	printf("\n");
}
void jiafa(BIGNUM &x, BIGNUM &y) {
	if (x.wfSign == -1 && y.wfSign == -1) {
		x.wfSign = 1;
		y.wfSign = 1;
		jiafa(x, y);
		x.wfSign = -1;
		return;
	}
	if (x.wfSign * y.wfSign == -1) {
		bool f = isBigger(x, y);
		if (f && x.wfSign == -1) {
			x.wfSign = 1;
			y.wfSign = -1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
		else if (!f && y.wfSign == -1) {
			x.wfSign = -1;
			y.wfSign = 1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
	}
	int s = x.cnt > y.cnt ? x.cnt : y.cnt;
	int i;
	for (i = 0; i < x.cnt; i++) {
		x.dig[i] = x.dig[i] * x.wfSign + y.dig[i] * y.wfSign;
	}
	while (i < y.cnt) {
		x.dig[i] = y.wfSign * y.dig[i];
		i++;
	}
	x.dig[i] = 0;
	for (i = 0; i < s; i++) {
		if (x.dig[i] < 0) {
			x.dig[i] += 10000;
			x.dig[i + 1] --;
		}
		else {
			x.dig[i + 1] += x.dig[i] / 10000;
			x.dig[i] %= 10000;
		}
	}
	i = s;
	while (i > 0 && x.dig[i] == 0) {
		i--;
	}
	x.cnt = i + 1;
	x.wfSign = 1;
}
void init(BIGNUM &x, int val) {
	int i = 0;
	x.dig[0] = 0;
	if (val < 0) {
		x.wfSign = -1;
		val *= -1;
	}
	else {
		x.wfSign = 1;
	}
	while (val) {
		x.dig[i] = val % 10000;
		val /= 10000;
		i++;
	}
	if (i == 0) { i = 1; }
	x.cnt = i;
}
int n, m;
int a[N], b[N], c[N];
int wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	int rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	BIGNUM x, y, z, rs;
	rs.cnt = 1;
	rs.dig[0] = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		init(x, i - n + i + 1);
		init(y, a[i]);
		chengfa(x, y, z);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
		//ans += (long long)(i - n + i + 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	//printf("-------------------------\n");
	for (i = n - 1; i >= 0; i--) {
		int v = wf(a[i]);
		init(z, v);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
	}
	//printf("%lld\n", ans);
	showRes(rs);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct BIGNUM {
	int cnt;
	int wfSign;
	int dig[200];
};
void chengfa(BIGNUM &x, BIGNUM &y, BIGNUM &z) {
	int i, j;
	int s = x.cnt + y.cnt + 1;
	if (s >= 200) {
		s = 199;
	}
	for (i = 0; i <= s; i++) {
		z.dig[i] = 0;
	}
	for (i = 0; i < x.cnt; i++) {
		for (j = 0; j < y.cnt; j++) {
			z.dig[i + j] += x.dig[i] * y.dig[j];
		}
	}
	for (i = 0; i <= s; i++) {
		z.dig[i + 1] += z.dig[i] / 10000;
		z.dig[i] %= 10000;
	}
	i = s;
	while (z.dig[i] == 0) {
		i--;
	}
	z.cnt = i + 1;
	z.wfSign = x.wfSign * y.wfSign;
}
bool isBigger(BIGNUM &x, BIGNUM &y) {
	if (x.cnt > y.cnt) {
		return 1;
	}
	else if (x.cnt < y.cnt) {
		return 0;
	}
	int i;
	for (i = x.cnt - 1; i >= 0; i--) {
		if (x.dig[i] > y.dig[i]) {
			return true;
		}
		else if (x.dig[i] < y.dig[i]) {
			return false;
		}
	}
	return false;
}
void showRes(BIGNUM &rs) {
	if (rs.wfSign == -1) {
		printf("-");
	}
	printf("%d", rs.dig[rs.cnt - 1]);
	int i;
	for (i = rs.cnt - 2; i >= 0; i--) {
		printf("%04d", rs.dig[i]);
	}
	printf("\n");
}
void jiafa(BIGNUM &x, BIGNUM &y) {
	if (x.wfSign == -1 && y.wfSign == -1) {
		x.wfSign = 1;
		y.wfSign = 1;
		jiafa(x, y);
		x.wfSign = -1;
		return;
	}
	if (x.wfSign * y.wfSign == -1) {
		bool f = isBigger(x, y);
		if (f && x.wfSign == -1) {
			x.wfSign = 1;
			y.wfSign = -1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
		else if (!f && y.wfSign == -1) {
			x.wfSign = -1;
			y.wfSign = 1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
	}
	int s = x.cnt > y.cnt ? x.cnt : y.cnt;
	int i;
	for (i = 0; i < x.cnt; i++) {
		x.dig[i] = x.dig[i] * x.wfSign + y.dig[i] * y.wfSign;
	}
	while (i < y.cnt) {
		x.dig[i] = y.wfSign * y.dig[i];
		i++;
	}
	x.dig[i] = 0;
	for (i = 0; i < s; i++) {
		if (x.dig[i] < 0) {
			x.dig[i] += 10000;
			x.dig[i + 1] --;
		}
		else {
			x.dig[i + 1] += x.dig[i] / 10000;
			x.dig[i] %= 10000;
		}
	}
	i = s;
	while (i > 0 && x.dig[i] == 0) {
		i--;
	}
	x.cnt = i + 1;
	x.wfSign = 1;
}
void init(BIGNUM &x, int val) {
	int i = 0;
	x.dig[0] = 0;
	if (val < 0) {
		x.wfSign = -1;
		val *= -1;
	}
	else {
		x.wfSign = 1;
	}
	while (val) {
		x.dig[i] = val % 10000;
		val /= 10000;
		i++;
	}
	if (i == 0) { i = 1; }
	x.cnt = i;
}
int n, m;
int a[N], b[N], c[N];
int wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	int rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	BIGNUM x, y, z, rs;
	rs.wfSign = 1;
	rs.cnt = 1;
	rs.dig[0] = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		init(x, i - n + i + 1);
		init(y, a[i]);
		chengfa(x, y, z);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
		//ans += (long long)(i - n + i + 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	//printf("-------------------------\n");
	for (i = n - 1; i >= 0; i--) {
		int v = wf(a[i]);
		init(z, v);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
	}
	//printf("%lld\n", ans);
	showRes(rs);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct ac {

};
//priority_queue<ac, vector<ac>, ac>que;
//vector<ac> ans;
int n, m;
int a[N], b[N], c[N];
long long wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	long long rt = 0;
	if (x > 0) {
		if (b[x - 1] == b[x] - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == b[x] + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	long long ans = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		ans += (long long)(i - n + i + 1) * (long long)a[i];
		//ans -= (long long)(n - i - 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	for (i = n - 1; i >= 0; i--) {
		ans += wf(a[i]);
	}
	printf("%lld\n", ans);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct BIGNUM {
	int cnt;
	int wfSign;
	int dig[200];
};
void chengfa(BIGNUM &x, BIGNUM &y, BIGNUM &z) {
	int i, j;
	int s = x.cnt + y.cnt + 1;
	if (s >= 200) {
		s = 199;
	}
	for (i = 0; i <= s; i++) {
		z.dig[i] = 0;
	}
	for (i = 0; i < x.cnt; i++) {
		for (j = 0; j < y.cnt; j++) {
			z.dig[i + j] += x.dig[i] * y.dig[j];
		}
	}
	for (i = 0; i <= s; i++) {
		z.dig[i + 1] += z.dig[i] / 10000;
		z.dig[i] %= 10000;
	}
	i = s;
	while (z.dig[i] == 0) {
		i--;
	}
	z.cnt = i + 1;
	z.wfSign = x.wfSign * y.wfSign;
}
bool isBigger(BIGNUM &x, BIGNUM &y) {
	if (x.cnt > y.cnt) {
		return 1;
	}
	else if (x.cnt < y.cnt) {
		return 0;
	}
	int i;
	for (i = x.cnt - 1; i >= 0; i--) {
		if (x.dig[i] > y.dig[i]) {
			return true;
		}
		else if (x.dig[i] < y.dig[i]) {
			return false;
		}
	}
	return false;
}
void showRes(BIGNUM &rs) {
	if (rs.wfSign == -1) {
		printf("-");
	}
	printf("%d", rs.dig[rs.cnt - 1]);
	int i;
	for (i = rs.cnt - 2; i >= 0; i--) {
		printf("%04d", rs.dig[i]);
	}
	printf("\n");
}
void jiafa(BIGNUM &x, BIGNUM &y) {
	if (x.wfSign == -1 && y.wfSign == -1) {
		x.wfSign = 1;
		y.wfSign = 1;
		jiafa(x, y);
		x.wfSign = -1;
		return;
	}
	if (x.wfSign * y.wfSign == -1) {
		bool f = isBigger(x, y);
		if (f && x.wfSign == -1) {
			x.wfSign = 1;
			y.wfSign = -1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
		else if (!f && y.wfSign == -1) {
			x.wfSign = -1;
			y.wfSign = 1;
			jiafa(x, y);
			x.wfSign = -1;
			return;
		}
	}
	int s = x.cnt > y.cnt ? x.cnt : y.cnt;
	int i;
	for (i = 0; i < x.cnt; i++) {
		x.dig[i] = x.dig[i] * x.wfSign + y.dig[i] * y.wfSign;
	}
	while (i < y.cnt) {
		x.dig[i] = y.wfSign * y.dig[i];
		i++;
	}
	x.dig[i] = 0;
	for (i = 0; i < s; i++) {
		if (x.dig[i] < 0) {
			x.dig[i] += 10000;
			x.dig[i + 1] --;
		}
		else {
			x.dig[i + 1] += x.dig[i] / 10000;
			x.dig[i] %= 10000;
		}
	}
	i = s;
	while (i > 0 && x.dig[i] == 0) {
		i--;
	}
	x.cnt = i + 1;
	x.wfSign = 1;
}
void init(BIGNUM &x, int val) {
	int i = 0;
	x.dig[0] = 0;
	if (val < 0) {
		x.wfSign = -1;
		val *= -1;
	}
	else {
		x.wfSign = 1;
	}
	while (val) {
		x.dig[i] = val % 10000;
		val /= 10000;
		i++;
	}
	if (i == 0) { i = 1; }
	x.cnt = i;
}
int n, m;
int a[N], b[N], c[N];
int wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	int rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	BIGNUM x, y, z, rs;
	rs.cnt = 1;
	rs.dig[0] = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		init(x, i - n + i + 1);
		init(y, a[i]);
		chengfa(x, y, z);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
		//ans += (long long)(i - n + i + 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	//printf("-------------------------\n");
	for (i = n - 1; i >= 0; i--) {
		int v = wf(a[i]);
		init(z, v);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
	}
	//printf("%lld\n", ans);
	showRes(rs);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct BIGNUM {
	int cnt;
	int sign = 1;
	int dig[200];
};
void chengfa(BIGNUM &x, BIGNUM &y, BIGNUM &z) {
	int i, j;
	int s = x.cnt + y.cnt + 1;
	if (s >= 200) {
		s = 199;
	}
	for (i = 0; i <= s; i++) {
		z.dig[i] = 0;
	}
	for (i = 0; i < x.cnt; i++) {
		for (j = 0; j < y.cnt; j++) {
			z.dig[i + j] += x.dig[i] * y.dig[j];
		}
	}
	for (i = 0; i <= s; i++) {
		z.dig[i + 1] += z.dig[i] / 10000;
		z.dig[i] %= 10000;
	}
	i = s;
	while (z.dig[i] == 0) {
		i--;
	}
	z.cnt = i + 1;
	z.sign = x.sign * y.sign;
}
bool isBigger(BIGNUM &x, BIGNUM &y) {
	if (x.cnt > y.cnt) {
		return 1;
	}
	else if (x.cnt < y.cnt) {
		return 0;
	}
	int i;
	for (i = x.cnt - 1; i >= 0; i--) {
		if (x.dig[i] > y.dig[i]) {
			return true;
		}
		else if (x.dig[i] < y.dig[i]) {
			return false;
		}
	}
	return false;
}
void showRes(BIGNUM &rs) {
	if (rs.sign == -1) {
		printf("-");
	}
	printf("%d", rs.dig[rs.cnt - 1]);
	int i;
	for (i = rs.cnt - 2; i >= 0; i--) {
		printf("%04d", rs.dig[i]);
	}
	printf("\n");
}
void jiafa(BIGNUM &x, BIGNUM &y) {
	if (x.sign == -1 && y.sign == -1) {
		x.sign = 1;
		y.sign = 1;
		jiafa(x, y);
		x.sign = -1;
		return;
	}
	if (x.sign * y.sign == -1) {
		bool f = isBigger(x, y);
		if (f && x.sign == -1) {
			x.sign = 1;
			y.sign = -1;
			jiafa(x, y);
			x.sign = -1;
			return;
		}
		else if (!f && y.sign == -1) {
			x.sign = -1;
			y.sign = 1;
			jiafa(x, y);
			x.sign = -1;
			return;
		}
	}
	int s = x.cnt > y.cnt ? x.cnt : y.cnt;
	int i;
	for (i = 0; i < x.cnt; i++) {
		x.dig[i] = x.dig[i] * x.sign + y.dig[i] * y.sign;
	}
	while (i < y.cnt) {
		x.dig[i] = y.sign * y.dig[i];
		i++;
	}
	x.dig[i] = 0;
	for (i = 0; i < s; i++) {
		if (x.dig[i] < 0) {
			x.dig[i] += 10000;
			x.dig[i + 1] --;
		}
		else {
			x.dig[i + 1] += x.dig[i] / 10000;
			x.dig[i] %= 10000;
		}
	}
	i = s;
	while (i > 0 && x.dig[i] == 0) {
		i--;
	}
	x.cnt = i + 1;
	x.sign = 1;
}
void init(BIGNUM &x, int val) {
	int i = 0;
	x.dig[0] = 0;
	if (val < 0) {
		x.sign = -1;
		val *= -1;
	}
	else {
		x.sign = 1;
	}
	while (val) {
		x.dig[i] = val % 10000;
		val /= 10000;
		i++;
	}
	if (i == 0) { i = 1; }
	x.cnt = i;
}
int n, m;
int a[N], b[N], c[N];
int wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	int rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	unsigned long long ans = 0;
	BIGNUM x, y, z, rs;
	rs.cnt = 1;
	rs.dig[0] = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		init(x, i - n + i + 1);
		init(y, a[i]);
		chengfa(x, y, z);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
		//ans += (long long)(i - n + i + 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	//printf("-------------------------\n");
	for (i = n - 1; i >= 0; i--) {
		int v = wf(a[i]);
		init(z, v);

		jiafa(rs, z);
		/*
		showRes(rs);
		printf("+\n");
		showRes(z);
		jiafa(rs, z);
		printf("=");
		showRes(rs);
		printf("...............\n");*/
	}
	//printf("%lld\n", ans);
	showRes(rs);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 2340000
//#define MAXN 1125899906842624L
#define MAXN 12345678
#define MOD 1000000009
struct ac {

};
//priority_queue<ac, vector<ac>, ac>que;
//vector<ac> ans;
int n, m;
int a[N], b[N], c[N];
long long wf(int val) {
	int x = 0;
	int y = m - 1;
	int mid;
	while (x < y) {
		mid = (x + y) / 2;
		if (b[mid] == val) {
			x = mid;
			break;
		}
		else if (val > b[mid]) {
			x = mid + 1;
		}
		else {
			y = mid;
		}
	}
	c[x]++;
	long long rt = 0;
	if (x > 0) {
		if (b[x - 1] == val - 1) {
			rt += c[x - 1];
		}
	}
	if (x < n - 1) {
		if (b[x + 1] == val + 1) {
			rt -= c[x + 1];
		}
	}
	return rt;
}
void solve() {
	int i, j;
	unsigned long long ans = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		ans += (long long)(i - n + i + 1) * (long long)a[i];
		//ans -= (long long)(n - i - 1) * (long long)a[i];
	}
	sort(b, b + n);
	m = 1;
	for (j = 1; j < n; j++) {
		if (b[j] != b[j - 1]) {
			b[m++] = b[j];
		}
	}
	for (i = 0; i < m; i++) {
		c[i] = 0;
	}
	for (i = n - 1; i >= 0; i--) {
		ans += wf(a[i]);
	}
	printf("%lld\n", ans);
}
int main() {
	while (scanf("%d", &n) != EOF) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <set>
#include <cassert>
#include <ctime>
#include <unordered_set>
#include <complex>
#include <queue>

#define vd vector<double>
#define pb push_back
#define all(v) v.begin(), v.end()

#define mp make_pair
#define forn(i, l) for (int i = 0; i < l; i++)

using namespace std;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<ld, ld> pd;
typedef long long li;
const int N = 2e5 + 100, M = 1e6 + N / 2;
const ld eps = 0.2, eps2 = 0.0001;
const int INF = (int)1e9 + 7, MOD = INF;
const long long LINF = 1e16;
const double PI = acos(-1.0);
const int mil = 1e9;

struct long_num{
	vector<int> notation;
	bool sig;
	long_num() {
		notation.resize(0);
		sig = 0;
	}
	long_num(long long val) {
		int v1 = abs(val) % mil;
		int v2 = abs(val) / mil;
		notation.resize(1, v1);
		if (v2 > 0) {
			notation.pb(v2);
		}
		sig = val < 0;
	}
	void normalize() {
		while(notation.size() > 1 && notation.back() == 0) {
			notation.pop_back();
		}
		if (notation.size() == 1 && notation[0] == 0) {
			sig = 0;
		}
	}
	void print() {
		if (sig) {
			printf("-");
		}
		int cnt = 0;
		for (int i = notation.size() - 1; i >= 0; i--) {
			printf(cnt? "%09d" : "%d", notation[i]);
			cnt = 1;
		}
	}
	bool zero() {
		normalize();
		if (notation.size() == 1 && notation[0] == 0) {
			return 1;
		}
		return 0;
	}
};

long_num abs(long_num a) {
	a.sig = 0;
	return a;
}

int cmp(long_num a, long_num b) {
	if (a.sig && !b.sig) {
		return 1;
	}
	if (!a.sig && b.sig) {
		return -1;
	}
	int as = a.notation.size(), bs = b.notation.size();
	if (as > bs) {
		return a.sig? 1 : -1;
	}
	if (as < bs) {
		return !a.sig? 1 : -1;
	}
	for (int i = as - 1; i >= 0; i--) {
		if (b.notation[i] < a.notation[i]) {
			return a.sig? 1 : -1;
		}
		if (a.notation[i] < b.notation[i]) {
			return !a.sig? 1 : -1;
		}
	}
	return 0;
}

bool operator <(long_num a, long_num b) {
	if (cmp(a, b) <= 0) {
		return 0;
	} else {
		return 1;
	}
}

long_num operator +(long_num, long_num);

long_num operator -(long_num a, long_num b) {
	if (a.zero()) {
		a.sig = b.sig;
	}
	if (b.zero()) {
		b.sig = a.sig;
	}
	if (a.sig == b.sig) {
		long_num c;
		c.sig = a.sig;
		a = abs(a), b = abs(b);
		if (!(a < b)) {
			int sz = b.notation.size();
			vector<int> &va = a.notation, &vb = b.notation;
			int i;
			for (i = 0; i < sz; i++) {
				va[i] -= vb[i];
				if (va[i] < 0) {
					va[i] += 1e9;
					va[i + 1]--;
				}
			}
			while (i < va.size() && va[i] < 0) {
				va[i + 1]--;
				va[i] += 1e9;
				i++;
			}
			c.notation = va;
			c.normalize();
			return c;
		} else {
			long_num d = b - a;
			c.sig ^= 1;
			c.notation = d.notation;
			return c;
		}
	}
	b.sig ^= 1;
	return a + b;
}

long_num operator +(long_num a, long_num b) {
	if (a.zero()) {
		a.sig = b.sig;
	}
	if (b.zero()) {
		b.sig = a.sig;
	}
	if (a.sig == b.sig) {
		long_num c;
		c.sig = a.sig;
		vector<int> &va = a.notation, &vb = b.notation;
		int as = va.size(), bs = vb.size();
		long long car = 0;
		forn(i, max(as, bs)) {
			if (i < as) {
				car += va[i];
			}
			if (i < bs) {
				car += vb[i];
			}
			c.notation.pb(car % mil);
			car /= mil;
		}
		if (car > 0) {
			c.notation.pb(car);
		}
		return c;
	}
	b.sig ^= 1;
	return a - b;
}

int a[N], n;
map<int, int> m;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &n);
	forn(i, n) {
		scanf("%d", a + i);
	}
	long_num ans(0), sum(a[0]);
	m[a[0]]++;
	for (int i = 1; i < n; i++) {
		ans = ans - sum;
		long_num v(i * 1LL * a[i]);
		ans = ans + v;
		//ans += i * 1LL * a[i] - sum;
		sum = sum + long_num(a[i]);
		long_num cnt1 = long_num(m.count(a[i] + 1)? m[a[i] + 1] : 0);
		long_num cnt2 = long_num(m.count(a[i] - 1)? m[a[i] - 1] : 0);
		cnt1 = cnt1 - cnt2;
		//ans -= cnt2 - cnt1;
		ans = ans + cnt1;
		m[a[i]]++;
	}
	ans.print();
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <set>
#include <cassert>
#include <ctime>
#include <unordered_set>
#include <complex>
#include <queue>

#define vd vector<double>
#define pb push_back
#define all(v) v.begin(), v.end()

#define mp make_pair
#define forn(i, l) for (int i = 0; i < l; i++)

using namespace std;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<ld, ld> pd;
typedef long long li;
const int N = 2e5 + 100, M = 1e6 + N / 2;
const ld eps = 0.2, eps2 = 0.0001;
const int INF = (int)1e9 + 7, MOD = INF;
const long long LINF = 1e16;
const double PI = acos(-1.0);

int a[N], n;
map<int, int> m;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &n);
	forn(i, n) {
		scanf("%d", a + i);
	}
	li ans = 0, sum = a[0];
	m[a[0]]++;
	for (int i = 1; i < n; i++) {
		ans += i * 1LL * a[i] - sum;
		sum += a[i];
		int cnt1 = m.count(a[i] + 1)? m[a[i] + 1] : 0;
		int cnt2 = m.count(a[i] - 1)? m[a[i] - 1] : 0;
		ans -= cnt2 - cnt1;
		m[a[i]]++;
	}
	printf("%I64d", ans);
}


def d(x,y):
    if abs(x-y)>1:
        return(y-x)
    else: return 0

n = int(input())
sum  = 0
s = list(map(int,input().split()))
for i in range(n-1):
    for j in range(i+1,n):
        sum+=d(s[i],s[j])
print(sum)


n = int(input())
a = list(map(int,input().split()))

s = 0
mx = a[0]
dic = dict()
for i in range(n):
    t = {a[i]:0}
    dic.update(t)

for i in range(n):
    s = s - a[i]*(n-i-1) + a[i]*i
    for key in dic:
        if -1<=key-a[i]<=1 and a[i]!=key: s = s + dic[key]*(key - a[i])
    d = dic[a[i]]+1
    t = {a[i]:d}
    dic.update(t)

print(s)


n = int(input())
a = list(map(int,input().split()))

s = 0
mx = a[0]
dic = dict()
for i in range(n):
    t = {a[i]:0}
    dic.update(t)

for i in range(n):
    s = s - a[i]*(n-i-1) + a[i]*i
    kt = 0
    for key in dic:
        if -1<=key-a[i]<=1 and a[i]!=key: s = s + dic[key]*(key - a[i])
        kt+=1
        if kt == 2:break
    d = dic[a[i]]+1
    t = {a[i]:d}
    dic.update(t)

print(s)


#include<iostream>

using namespace std;

int main()
{
    int n, *a;
    cin>>n;
    a = new int[n];
    for(int i = 0; i<n; ++i)
        cin>>a[i];

    int s = 0;

    for(int i = 0; i<n; ++i)
    {
        s = s - a[i]*(n-i-1) + a[i]*i;

        for(int j = i+1; j<n; ++j)
            if(a[j]-a[i]<=1 && a[j]-a[i]>=-1 && a[j]!=a[i]) s = s+a[i]-a[j];
    }
    cout<<s;
}


n = int(input())
a = list(map(int,input().split()))

s = 0

for i in range(n):
    s = s - a[i]*(n-i-1) + a[i]*i

    for j in range(i+1,n):
        if -1<=a[j]-a[i]<=1 and a[j]!=a[i]: s= s + a[i] - a[j]

print(s)


n = int(input())
a = list(map(int,input().split()))

s = 0
mx = a[0]
dic = dict()
for i in range(n):
    dic[a[i]] = 0

for i in range(n):
    s = s - a[i]*(n-i-1) + a[i]*i
    if a[i]-1 in dic:
        s = s + dic[a[i]-1]*(a[i] - 1 - a[i])
    if a[i]+1 in dic:
        s = s + dic[a[i]+1]*(a[i] + 1 - a[i])
    d = dic[a[i]]+1
    t = {a[i]:d}
    dic.update(t)

print(s)


n = int(input())
a = list(map(int,input().strip().split()))
mapp = {}
for i in a:
    mapp[i] = 0
    mapp[i+1] = 0
    mapp[i-1] = 0
s = sum(a)
ans = 0
for i in range(n):
    mapp[a[i]] += 1
    ans += s - a[i]*(n-i)
    s -= a[i]
    ans += mapp[a[i]+1]
    ans -= mapp[a[i]-1]

print(ans)


n = int(input())
nums = list(map(int, input().split()))

cnt = {}

answer = 0
summ = 0

for i, item in enumerate(nums):
	cnt[item] = cnt.get(item, 0) + 1
	summ += item
	answer += (i + 1) * item - summ
	if(item + 1 in cnt):answer += cnt[item + 1]
	if(item - 1 in cnt):answer -= cnt[item - 1]

print(answer)


n = int(input())
l = list(map(int, input().split()))
s = 0
for i in range(n):
    s += l[i] * i - l[i] * (n - i - 1)
d = {}
c = 0
for i in range(n):
    if l[i] not in d:
        d[l[i]] = 1
    else:
        d[l[i]] += 1
    if l[i] + 1 in d:
        c -= d[l[i] + 1]
    if l[i] - 1 in d:
        c += d[l[i] - 1]
print(s - c)


n = int(input())
a = list(map(int, input().split()))
ans = 0
memo = dict((a[i], 0) for i in range(n))
for i in range(n):
    ans += a[i] * (2*i - n + 1)
    memo[a[i]] += 1
    ans -= memo.get(a[i] - 1, 0)
    ans += memo.get(a[i] + 1, 0)
print(ans)


import sys
n = int(input())
a = list(map(int, input().split()))
cnt = dict()
ans = 0

for i in range(n):
        ans += i * a[i]
        ans -= (n - 1 - i) * a[i]
        cnt[a[i]] = 0
for i in range(n):
        if(a[i] - 1 in cnt):
                ans -= cnt[a[i] - 1]
        if(a[i] + 1 in cnt):
                ans += cnt[a[i] + 1]
        cnt[a[i]] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324ggjgf


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324gg


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324ggjg


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324g


maxN = 2 * 10**5
n = int(input())
bad = 0
ghabl = 0
a = list(map(int, input().split()))
for i in range(n):
    if (i):
        bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1])
    bad -= ((n - 1) - i) * (a[i] - a[i - 1])
    Sum += bad
maP = dict()
maP["pedram"] = 1
for i in range(n):
    if a[i] in maP:
        maP[a[i]] += 1
    else:
        maP[a[i]] = 1
    if a[i] - 1 in maP:
        Sum -= maP[a[i] - 1]
    if a[i] + 1 in maP:
        Sum += maP[a[i] + 1]
print(Sum)


n = int(input())
a = list(map(int, input().split()))
bad = 0
for i in range(1, n):
    bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
    bad -= (a[i] - a[i - 1]) * (n - i)
    Sum += bad
maP = dict()
for i in range(n):
    if a[i] in maP: maP[a[i]] += 1
    else: maP[a[i]] = 1
    for j in range(-1, 2, 2):
        if a[i] + j in maP:
            Sum += j * maP[a[i] + j]
print(Sum)
#324ggj


n = int(input())
s = 0; ans = 0
l = input().split(' ')
mp = {}
for i in range(0, n):
    l[i] = int(l[i])
    f = i * l[i]
    f += mp.get(l[i] + 1, 0)
    f -= mp.get(l[i] - 1, 0)
    ans += f - s
    s += l[i]
    temp = mp.get(l[i], 0); mp[l[i]] = temp + 1
print(ans)


n = int(input())
ans = 0
sum = 0
mp = {}
c = []
c = list(map(int,input().split()))
for i in range(0,n):
    tmp = c[i]
    z1 = 0
    z2 = 0
    if tmp - 1 in mp:
        z1 = mp[tmp - 1]
    if tmp + 1 in mp:
        z2 = mp[tmp + 1]
    ans += tmp * i - sum - z1 + z2
    if tmp in mp:
        mp[tmp] += 1
    else:
        mp[tmp] = 1
    sum += tmp
print(ans)


import sys
input=sys.stdin.readline
n=int(input())
a=map(int,input().split())
d={}
ans=sum=num=0
for x in a:
    t=x*num-sum
    if x-1 not in d:
        d[x-1]=0
    if x+1 not in d:
        d[x+1]=0
    if x not in d:
        d[x]=0
    t-=d[x-1]
    t+=d[x+1]
    d[x]+=1
    num+=1
    sum+=x
    ans+=t
print(ans);


n =  int(input())
a = input().split(' ')

for i in range(n):
    a[i] = int(a[i])
ans = 0
sum = 0
m = dict()
for i in range(n):
    m[a[i]] = m.get(a[i],0) + 1;
    sum += a[i];
    ans += (i+1)*a[i] - sum;
    ans -= (m.get(a[i]+1,0)*(- 1));
    ans -= m.get(a[i]-1,0);

print(ans)


n = int(input())

a = [int(x) for x in input().split()]

s = a[n-1]

ans = 0

D = dict()
D[a[n-1]] = 1

for i in range(n-2,-1,-1):
    x = a[i]
    c = 0
    d = 0
    if x-1 in D :
        c = D[x-1]
    if x+1 in D:
        d = D[x+1]
    ans += s - ((n-1-i)*x - c + d)
    s += x
    if x in D:
        D[x] += 1

    else :
        D[x] = 1

print(ans)


n = int(input())

a = list(map(int,input().split()))

s = a[n-1]

ans = 0

D = dict()
D[a[n-1]] = 1

for i in range(n-2,-1,-1):
    x = a[i]
    c = 0
    d = 0
    if x-1 in D :
        c = D[x-1]
    if x+1 in D:
        d = D[x+1]
    ans += s - ((n-1-i)*x - c + d)
    s += x
    if x in D:
        D[x] += 1

    else :
        D[x] = 1

print(ans)


n = int(input())
ls = [int(i) for i in input().split()]
fullsum = sum(ls[i]*(-n+1+(2*i)) for i in range(n))
numdict = dict()
for num in ls:
    if num-1 in numdict:
        fullsum -= numdict[num-1]
    if num+1 in numdict:
        fullsum += numdict[num+1]
    if num in numdict:
        numdict[num] += 1
    else:
        numdict[num] = 1
print(fullsum)


n = int(input())
arr = [int(e) for e in input().split()]
m = {}
pref = 0
ans = 0
for i in arr:
    m[i] = 0
    m[i+1] = 0
    m[i-1] = 0
for i in range(len(arr)):
    ans += i*arr[i] - pref
    ans -= (m[arr[i]-1]-m[arr[i]+1])
    pref += arr[i]
    m[arr[i]] += 1
print(ans)


import sys
N = int(input())
a = []
b = {}
ans = 0
a = input().split()
for i in range(N):
	b[int(a[i])] = 0
	b[int(a[i]) - 1] = 0
	b[int(a[i]) + 1] = 0
for i in range(N):
	ans += int(a[i]) * (i - (N - 1 - i)) - (b[int(a[i]) - 1] - b[int(a[i]) + 1])
	b[int(a[i])] = b[int(a[i])] + 1;
print(ans)


import sys
N = int(input())
a = []
b = {}
ans = 0
a = input().split()
for i in range(N):
	b[a[i]] = 0;
for i in range(N):
	ans += int(a[i]) * (i - (N - 1 - i))
	b[a[i]] = b[a[i]] + 1;
print(ans)


from collections import defaultdict
n=int(input())
a1=list(map(int,input().split()))
p=[0 for _ in range(n+1)]
a=[0 for _ in range(n+1)]
for i in range(1,n+1):
	a[i]=a1[i-1]
for i in range(1,n+1):
	p[i]=p[i-1]+a[i]
ans=0
for i in range(1,n):
	ans=ans+p[n]-2*p[i]
c=0
print(ans)
d = defaultdict(int)
d[a[n]]+=1
for i in range(n-1,0,-1):
	d[a[i]]+=1
	if(d[a[i]+1]>0):
		ans-=d[a[i]+1]
	if(d[a[i]-1]>0):
		ans+=d[a[i]-1]
print(ans)


from collections import defaultdict
n=int(input())
a1=list(map(int,input().split()))
p=[0 for _ in range(n+1)]
a=[0 for _ in range(n+1)]
for i in range(1,n+1):
	a[i]=a1[i-1]
for i in range(1,n+1):
	p[i]=p[i-1]+a[i]
ans=0
for i in range(1,n):
	ans=ans+p[n]-2*p[i]
c=0
# print(ans)
d = defaultdict(int)
d[a[n]]+=1
for i in range(n-1,0,-1):
	d[a[i]]+=1
	if(d[a[i]+1]>0):
		ans-=d[a[i]+1]
	if(d[a[i]-1]>0):
		ans+=d[a[i]-1]
print(ans)


def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())
from collections import defaultdict

n = ii()
a = li()

def calc(a):
    d = defaultdict(int)
    s = 0
    for i in range(n):
        x = a[i]
        s += (i - d[x] - d[x-1] - d[x+1]) * x
        d[x] += 1
    return s

ans = calc(a) - calc(a[::-1])
print(ans)


def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())
from collections import defaultdict

n = ii()
a = li()

def calc(a):
    d = defaultdict(int)
    s = 0
    pre=0
    for i in range(n):
        x = a[i]
        s += (i*x - pre-d[x-1]+d[x+1])
        d[x] += 1
        pre+=x
    return s

ans = calc(a)
print(ans)


cnt = {}
x= int(input())
s = 0
an = 0
a = list(map(int, input().split()))
for i in range(x):
    if a[i] not in cnt.keys():
        cnt[a[i]] = 0
    if a[i] - 1 not in cnt.keys():
        cnt[a[i] - 1] = 0
    if a[i] + 1 not in cnt.keys():
        cnt[a[i] + 1] = 0
    s += a[i]
    cnt[a[i]] += 1
    num = i + 1 - cnt[a[i]] - cnt[a[i] - 1] - cnt[a[i] + 1]
    an += num * a[i] - (s - a[i] * cnt[a[i]] - (a[i] + 1) * cnt[a[i] + 1] - (a[i] - 1) * cnt[a[i] - 1])
print(an)


cnt = {}
n = int(input())
s = 0
an = 0
a = list(map(int, input().split()))
for i in range(n):
    if a[i] not in cnt.keys():
        cnt[a[i]] = 0
    if a[i] - 1 not in cnt.keys():
        cnt[a[i] - 1] = 0
    if a[i] + 1 not in cnt.keys():
        cnt[a[i] + 1] = 0
    s += a[i]
    cnt[a[i]] += 1
    num = i + 1 - cnt[a[i]] - cnt[a[i] - 1] - cnt[a[i] + 1]
    an += num * a[i] - (s - a[i] * cnt[a[i]] - (a[i] + 1) * cnt[a[i] + 1] - (a[i] - 1) * cnt[a[i] - 1])
print(an)


# Useful data structures
from collections import Counter, defaultdict, deque, namedtuple

# Most useful math functions
from math import gcd

# For sys.std*, sys.argv etc...
import sys

def read_ints():
    return [int(token) for token in input().split()]

def read_tokens():
    return input().split()

def main():
    n = read_ints()[0]
    a = read_ints()
    total, running, counts = 0, 0, dict()

    for i, y in enumerate(a):
        total += i * y - running - counts.get(y - 1, 0)
        total += counts.get(y + 1, 0)
        running += y
        counts[y] = counts.get(y, 0) + 1

    print(total)

if __name__ == '__main__':
    main()


def almostDifference(nums):

	# Stores frequencies of previous numbers
	ht = {}
	result = 0
	prefix_sum = 0

	# y is nums[i], x is all elements before it
	for i, n in enumerate(nums):

		# Calculate difference
		ht.setdefault(n, 0)
		result -= prefix_sum	# subtract all previous elements
		result += n*i			# add y i times for i previous elements

		# Modify for "almost difference"
		ht.setdefault(n-1, 0)
		ht.setdefault(n+1, 0)
		result -= ht[n-1]*1		# remove the bonus (+)
		result -= ht[n+1]*-1	# remove the bonus (-)

		ht[n] += 1
		prefix_sum += n

	return result

_ = int(input())
nums = [int(x) for x in input().split()]
print(almostDifference(nums))


def almostDifference(nums):

	ht = {}
	result = 0
	prefix_sum = 0

	# y is nums[i], x is all elements before it
	for i, n in enumerate(nums):
		ht.setdefault(n, 0)
		ht.setdefault(n-1, 0)
		ht.setdefault(n+1, 0)

		result -= prefix_sum	# subtract all the x's
		result += n*(i)			# add y (i+1) times
		result -= ht[n-1]*1		# remove the bonus (+)
		result -= ht[n+1]*-1	# remove the bonus (-)

		ht[n] += 1
		prefix_sum += n

	return result

_ = int(input())
nums = [int(x) for x in input().split()]
print(almostDifference(nums))


import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    x = 0
    ct = collections.defaultdict(int)
    for i in range(n):
        x += a[i]
        ct[a[i]] += 1

        mul = i+1
        sub = x
        for j in range(-1,2):
            if a[i]+j in ct:
                num = ct[a[i]+j]
                mul -= num
                sub -= num*(a[i]+j)

        ans += a[i]*mul
        ans -= sub

    print(ans)

if __name__ == '__main__':
    main()


n = int(input())
v = []
mp = {}
for i in input().split():
	v.append(int(i))
	mp[int(i)] = 0
	mp[int(i)-1] = 0
	mp[int(i)+1] = 0
sum = 0
ele = 0
ans = 0
for i in v[::-1]:
	ans = ans + (sum - ele*i)
	a = ((i+1)*mp[i+1])-(mp[i+1]*i)
	b = ((i-1)*mp[i-1])-(mp[i-1]*i)
	ans = ans - (a+b)
	mp[i] = mp[i]+1
	sum = sum+i
	ele = ele+1
print(ans)


n = int(input())

a = [int(x) for x in input().split()]
count = {}

cum = 0
tot = 0

for i in range(0, n):
	tot = tot + i * a[i] - cum
	if a[i] - 1 in count:
		tot = tot - count[a[i] - 1]
	if a[i] + 1 in count:
		tot = tot + count[a[i] + 1]

	if a[i] in count:
		count[a[i]] = count[a[i]] + 1
	else:
		count[a[i]] = 1

	cum = cum + a[i]

print(tot)


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <functional>
#include <queue>

using namespace std;

#define MOD 1000000007
#define ULL	unsigned long long
#define LL long long
typedef vector<int> vi;
typedef vector<ULL> vu;
#define AVI(n) vector<int>a(n);rvi(a);
#define AVU vector<int>b(n);rvi(b);
#define RNI int n;scanf("%d",&n);
#define RNU ull n;scanf("%llu", &n);
#define WR(a) for(auto b:a)cout << b << ' '; cout << endl;
#define F(n) for (int i = 0; i <n; ++i){

inline void rvi(vi& a) { for ( int i = 0; i <a.size(); ++i) scanf("%d", &a[i]); }
inline void rvu(vu& a) { for ( int i = 0; i <a.size(); ++i) scanf("%llu", &a[i]); }

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);
	for ( int  i = 0; i< n; ++i ){
		 scanf("%lld", &a[i]);
	}

	map<long long, long long> count;

	unsigned long long cum = 0, tot = 0;

	for ( long long i = 0; i <  a.size(); ++i ) {

		tot += a[i] * i - cum;

		if ( count.find(a[i]-1) != count.end() ) {
			tot -= count[a[i]-1];
		}
		if ( count.find(a[i]+1) != count.end() ) {
			tot += count[a[i]+1];
		}
		if ( count.find(a[i]) == count.end() ) count[a[i]] = 1;
		else ++count[a[i]];
		cum += a[i];
	}

	cout << tot << endl;

}


from collections import defaultdict

int(input())
mp, sum, res = defaultdict(int), 0, 0
for i, x in enumerate(map(int, input().split()), start=1):
	mp[x] += 1
	sum += x
	res += x*i - sum - mp[x-1] + mp[x+1]
print(res)


from collections import defaultdict

int(input())
mp, sum, res = defaultdict(int), 0, 0
for i, x in enumerate(map(int, input().split()), start =1):
	mp[x] += 1
	sum += x
	res = x*i - sum - mp[x-1] + mp[x+1]
print(res)


n = int(input())
v = list(map(int, input().split()))
cnt = {}
ans = s = 0
for i in range(0, n):
  ans += i * v[i] - s
  s += v[i]
  if v[i] + 1 in cnt:
    ans += cnt[v[i] + 1]
  if v[i] - 1 in cnt:
    ans -= cnt[v[i] - 1]
  if v[i] in cnt:
    cnt[v[i]] += 1
  else:
    cnt[v[i]] = 1
print(ans)


n = int(input())
v = list(map(int, input().split(' ')))
cnt = {}
ans = s = 0
for i in range(0, n - 1):
  ans += i * v[i] - s
  s += v[i]
  ans = ans - cnt[v[i] - 1] + cnt[v[i] + 1]
  cnt[v[i]] += 1
print(ans)