#include <iostream>
#include <vector>

int main() {
    int n, k;
    std::cin >> n >> k;

    std::vector <int> x(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        std::cin >> x[i];
    }

    int xn;
    std::cin >> xn;

    int c = 0, next = x[0];
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (next > * it) {
            continue;
        }

        ++c;

        if (next < * it) {
            next = * (it - 1) + k;
        } else {
            next = * it + k;
        }
    }

    if (next < xn) {
        std::cout << "-1";
    } else {
        std::cout << c;
    }

    return 0;
}


#include<bits/stdc++.h>

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0);

	int n , k;
	cin >> n >> k;

	vi x(n);
	for(auto & it : x) cin >> it;

	int ans = 1;
	int cur = 0;
	int i = 0;
	while(true){
		if(i == n - 1) break;
		if(cur + (x[i + 1] - x[i]) <= k){
			cur += (x[i + 1] - x[i]);
			++i;
		} else {
			++ans;
			if(x[i + 1] - x[i] <= k){
				cur = x[i + 1] - x[i];
			    ++i;
			} else {
				dier(-1);
			}
		}
	}

	cout << ans;

	return 0;
}


#include<bits/stdc++.h>

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0);

	int n , k;
	cin >> n >> k;

	vi x(n);
	for(auto & it : x) cin >> it;

	int ans = 1;
	int cur = 0;
	int i = 0;
	while(true){
		if(i == n - 1) break;
		if(cur + (x[i + 1] - x[i]) <= k){
			cur += (x[i + 1] - x[i]);
			++i;
		} else {
			++ans;
			if(x[i + 1] - x[i] <= k){
				++i;
				cur = x[i + 1] - x[i];
			} else {
				dier(-1);
			}
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define loop(a,b) for(int i = a; i< b; i++)
#define l00P(a,b) for(int j = a; j< b; j++)
#define INF (ll)1e18
#define inf (int)1e9
#define pb push_back
#define lenght() length()
#define all(v) (v).begin(), (v).end()

int main() {
    //cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    int n,k,a[1007],q=0,x;
    cin >> n >> k >> a[0];
    loop(1,n) {
        cin >> a[i];
        if(a[i]-a[i-1] > k) {
            cout << -1;
            return 0;
        }
    }
    x = a[0];
    int i = 0,j;
    while(x < a[n-1]) {
        ++ i;
        x += k;
        for(j = n-1; j >= i; j--) {
            if(a[j] <= x)
                break;
        }
        i = j;
        x = a[j];
        ++ q;
    }
    cout << q;
    return 0;
}
// Проверь программу на всех тестах из условия
// Не забудь проверить диапозон значений (int or ll)
// И сделать тесты на крайних значениях n (-10e9 ; 0; 1; 10e9)
// Посчитай асимптотику (O(n^3)?)


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define loop(a,b) for(int i = a; i< b; i++)
#define l00P(a,b) for(int j = a; j< b; j++)
#define INF (ll)1e18
#define inf (int)1e9
#define pb push_back
#define lenght() length()
#define all(v) (v).begin(), (v).end()

int main() {
    //cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    int n,k,a[1007],q=0,x;
    cin >> n >> k;
    loop(0,n) cin >> a[i];
    x = a[0];
    int i = 0,j;
    while(x < a[n-1]) {
        ++ i;
        if(a[i+1]-a[i] > k) {
            cout << -1;
            return 0;
        }
        x += k;
        for(j = n-1; j >= i; j--) {
            if(a[j] <= x)
                break;
        }
        i = j;
        x = a[j];
        ++ q;
    }
    cout << q;
    return 0;
}
// Проверь программу на всех тестах из условия
// Не забудь проверить диапозон значений (int or ll)
// И сделать тесты на крайних значениях n (-10e9 ; 0; 1; 10e9)
// Посчитай асимптотику (O(n^3)?)


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int mass[1791791];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> mass[i];
    }

    sort(mass, mass + n);

    int now = 0;
    int ans = 1;

    while (now < n - 1) {
        for (int j = now; j < n; ++j) {
            if (mass[j] - mass[now] > k) {
                if (j == now + 1) {
                    cout << -1;
                    return 0;
                }

                now = j - 1;
                ans += 1;
            } else if  (j == n - 1) {
                now = n - 1;
            }
        }
    }

    cout << ans;

}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int mass[1791791];

int get_rightest(int now, int n, int k) {
    int ans = now;
    for (int i = now; i < n; ++i) {
        if (mass[i] - mass[now] <= k) {
            ans = i;
        } else {
            break;
        }
    }
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> mass[i];
    }

    int now = 0;
    int ans = 1;

    while (now != n - 1) {
        int rightest = get_rightest(now, n, k);
        if (rightest == n - 1) {
            cout << ans;
            return 0;
        }
        if (rightest == now) {
            cout << -1;
            return 0;
        }
        now = rightest;
        ans += 1;
    }

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   int n;
   int k;
   int ans=1;
   int e=0;
   int a[1111];
   cin>>n>>k;
   for (int i=0;i<n;i++)
   {
       cin>>a[i];
   }

       //e=a[1]-a[0];
       for(int j=0;j<n-1;j++)
       {
            e+=a[j+1]-a[j];
            //cout<<j<<" "<<e<<" "<<ans<<endl;
            if(a[j+1]-a[j]>k)
            {
                ans=-1;
                break;
            }
            if(e<=k)
            {

            }
            else
            {
                ans++;
                e=0;
                j--;
            }

       }
   cout<<ans;
   return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   int n;
   int k;
   int ans=0;
   int e=1;
   int a[1111];
   cin>>n>>k;
   for (int i=0;i<n;i++)
   {
       cin>>a[i];
   }

       //e=a[1]-a[0];
       for(int j=0;j<n-1;j++)
       {
            e+=a[j+1]-a[j];
            if(a[j+1]-a[j]>k)
            {
                ans=-1;
                break;
            }
            if(e<=k)
            {

            }
            else
            {
                ans++;
                e=0;
                j--;
            }

       }
   cout<<ans;
   return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   int n;
   int k;
   int ans=0;
   int e=0;
   int a[1111];
   cin>>n>>k;
   for (int i=0;i<n;i++)
   {
       cin>>a[i];
   }

       e=a[1]-a[0];
       for(int j=0;j<n-1;j++)
       {
            e+=a[j+1]-a[j];
            if(a[j+1]-a[j]>k)
            {
                ans=-1;
                break;
            }
            if(e<=k)
            {

            }
            else
            {
                ans++;
                e=0;
                j--;
            }

       }
   cout<<ans;
   return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
//#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

void bye() {
	cout << '\n';
	exit(0);
}

int main() {
	int n, k, pos, ans = 1, end;
	cin >> n >> k;
	vector <int> d(n);
	for (int &v : d) cin >> v;
	for (int i = 0; i < n - 1; i++) {
		if (d[i + 1] - d[i] > k) {
			cout << -1;
			return 0;
		}
	}
	pos = d[0];
	end = d[n - 1];
	int l = 0;
	while (1) {
		pos += k;
		if (pos >= end) {
			cout << ans;
			return 0;
		}
		while (d[l] <= pos && l < n) {
			l++;
		}
		--l;
		pos = d[l];
		++ans;
	}
	bye();
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
//#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

void bye() {
	cout << '\n';
	exit(0);
}

int main() {
	int n, k, pos, ans = 1, end;
	cin >> n >> k;
	vector <int> d(n);
	for (int &v : d) cin >> v;
	for (int i = 0; i < n - 1; i++) {
		if (d[i + 1] - d[i] > k) {
			cout << -1;
			return 0;
		}
	}
	pos = d[0];
	end = d[n - 1];
	int l = 0;
	while (1) {
		pos += k;
		if (pos >= end) {
			cout << ans;
			return 0;
		}
		while (d[l] < pos) { l++; }
		pos = d[l];
		++ans;
	}
	bye();
}


#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <fstream>
#include <string>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <ctime>
#include <sstream>
#include <list>
#include <functional>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define sq(x) ((x)*(x))
#define bcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
vector<string> pole(3);

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("bridges.in", "r", stdin);
	//freopen("bridges.out", "w", stdout);

	int n, k;
	cin >> n >> k;
	vint p(n);
	for (auto& x : p)
		cin >> x;
	int curL = 0;
	int ans = 1;
	for (int i = 0; i < n - 1; i++)
	{
		if (p[i + 1] - p[i] + curL <= k)
			curL += p[i + 1] - p[i];
		else
		{
			if (curL == 0 || p[i + 1] - p[i] > k)
			{
				cout << -1;
				return 0;
			}
			curL = p[i + 1] - p[i];
			ans++;
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <fstream>
#include <string>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <ctime>
#include <sstream>
#include <list>
#include <functional>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define sq(x) ((x)*(x))
#define bcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
vector<string> pole(3);

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("bridges.in", "r", stdin);
	//freopen("bridges.out", "w", stdout);

	int n, k;
	cin >> n >> k;
	vint p(n);
	for (auto& x : p)
		cin >> x;
	int curL = 0;
	int ans = 1;
	for (int i = 0; i < n - 1; i++)
	{
		if (p[i + 1] - p[i] + curL <= k)
			curL += p[i + 1] - p[i];
		else
		{
			if (curL == 0)
			{
				cout << -1;
				return 0;
			}
			curL = 0;
			ans++;
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    bool dst;
    ll mas[1000],n,k,sch=1,i,j;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>mas[i];
        if (i > 0 && mas[i] - mas[i - 1] > k)
        {
            cout << -1;
            return 0;
        }
    }
    for(i=0;i<n;)
    {
        dst=false;
        for(j=i+1;j<n;j++)
        {
            if(mas[i]+k < mas[j])
            {
                i=j-1;
                sch++;
                dst=true;
                break;
            }
        }
        if (j == n)
        {
            cout << sch;
            return 0;
        }
    }
    cout<<sch;
}


#include <iostream>
using namespace std;
int main(){
  int n,k,A[1000],count=0;
  cin>>n>>k;
  for(int i=0;i<n;i++)
    cin>>A[i];
  int i=0,loc=0,sum;
  while(loc<n-1)
  {
    i++;
    sum=0;
    while(sum<k && i<=n-1)
    {
      sum=A[i]-A[loc];
      i++;
    }
    i--;

    if(sum<=k)
    {
      count++;
      loc=i;
    }
    else
    {
      i--;
      if(i==loc)
      {
          count=-1;
          break;
      }
      else
      {
        count++;
        loc=i;
      }
    }
  }
  cout<<count;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    vector<ll> ansvt;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ansvt.pb(lower.st - lower.nd * realVal[it]);
        ansvt.pb(higher.st - higher.nd * realVal[it]);
        updateBit(it, -realVal[it], -1);
    }
    sort(range(ansvt));
    int pst = 0, pnd = ansvt.size() - 1;
    while (pst <= pnd)
    {
        if (ans >= 0)
        {
            ans += ansvt[pst];
            pst++;
        }
        else
        {
            ans += ansvt[pnd];
            pnd--;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - lower.nd * realVal[it] + higher.st - higher.nd * realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define ld long double
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ld ans = 0;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - lower.nd * realVal[it];
        ans += higher.st - higher.nd * realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout.precision(19);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    vector<ll> ansvt;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ansvt.pb(lower.st - lower.nd * realVal[it]);
        ansvt.pb(higher.st - higher.nd * realVal[it]);
        updateBit(it, -realVal[it], -1);
    }
    sort(range(ansvt));
    int pst = 0, pnd = ansvt.size() - 1;
    while (pst <= pnd)
    {
        ans += ansvt[pst];
        if (pst != pnd)
        {
            ans += ansvt[pnd];
        }
        pst++;
        pnd--;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define ld long double
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 4e5;
int counter[MAX + 5];
ll bit[MAX + 5];
int realVal[MAX];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, int> getSum(int idx)
{
    ll ans = 0;
    int cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ld ans = 0;
    for (auto it : a)
    {
        pair<ll, int> lower = getSum(it - 2);
        pair<ll, int> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - (ll)lower.nd * (ll)realVal[it] + higher.st - (ll)higher.nd * (ll)realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout.precision(20);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define ld long double
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ld ans = 0;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - lower.nd * realVal[it];
        ans += higher.st - higher.nd * realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long double ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT32_MAX-2LL){
                ugh++;
                sum-=INT32_MAX-2LL;
            }
            if(sum<=-(INT32_MAX-2LL)){
                ugh--;
                sum+=-(-(INT32_MAX-2LL));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT32_MAX-2LL){
                ugh++;
                sum-=INT32_MAX-2LL;
            }
            if(sum<=-(INT32_MAX-2LL)){
                ugh--;
                sum+=-(-(INT32_MAX-2LL));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT32_MAX-2LL)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    fur(i,0,n){
        sum+=(pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1));
        sum-=a[i]*(i-(m[a[i]-1]+m[a[i]+1]));
        m[a[i]]++;
    }
    cout<<-sum;

	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    fur(i,0,n){
        sum-=(pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1));
        sum+=a[i]*(i-(m[a[i]-1]+m[a[i]+1]));
        m[a[i]]++;
    }
    cout<<sum;

	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT16_MAX-2LL){
                ugh++;
                sum-=INT16_MAX-2LL;
            }
            if(sum<=-(INT16_MAX-2LL)){
                ugh--;
                sum-=-(-(INT16_MAX-2LL));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT16_MAX-2LL){
                ugh++;
                sum-=INT16_MAX-2LL;
            }
            if(sum<=-(INT16_MAX-2LL)){
                ugh--;
                sum-=-(-(INT16_MAX-2LL));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT16_MAX-2LL)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long double ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

// ll modpow(ll base, ll exp, ll modulus) {
//   base %= modulus;
//   ll result = 1;
//   while (exp > 0) {
//     if (exp & 1) result = (result * base) % modulus;
//     base = (base * base) % modulus;
//     exp >>= 1;
//   }
//   return result;
// }

// ll modinv(ll a, ll m) {
//     ll m0 = m;
//     ll y = 0, x = 1;
//     if (m == 1)
//       return 0;
//     while (a > 1)
//     {
//         ll q = a / m;
//         ll t = m;
//         m = a % m, a = t;
//         t = y;
//         y = x - q * y;
//         x = t;
//     }
//     if (x < 0)
//        x += m0;
//     return x;
// }

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT32_MAX-2LL){
                ugh++;
                sum-=INT32_MAX-2LL;
            }
            if(sum<=-(INT32_MAX-2LL)){
                ugh--;
                sum+=-(-(INT32_MAX-2LL));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT32_MAX-2LL){
                ugh++;
                sum-=INT32_MAX-2LL;
            }
            if(sum<=-(INT32_MAX-2LL)){
                ugh--;
                sum+=-(-(INT32_MAX-2LL));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT32_MAX-2LL)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT32_MAX-2){
                ugh++;
                sum-=INT32_MAX-2;
            }
            if(sum<=-(INT32_MAX-2)){
                ugh--;
                sum-=-(-(INT32_MAX-2));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT32_MAX-2)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    fur(i,0,n){
        sum+=a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1)));
        m[a[i]]++;
    }
    cout<<sum;

	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    while(start>=end){
        if(start==end){
            sum+=ans[start];
        }else{
            sum+=(ans[end]+ans[start]);
            start++;
            end--;
        }
    }
    cout<<sum;

	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT32_MAX-2){
                ugh++;
                sum-=INT32_MAX;
            }
            if(sum<=-(INT32_MAX-2)){
                ugh--;
                sum-=-(-(INT32_MAX-2));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT32_MAX-2)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long double ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

// ll modpow(ll base, ll exp, ll modulus) {
//   base %= modulus;
//   ll result = 1;
//   while (exp > 0) {
//     if (exp & 1) result = (result * base) % modulus;
//     base = (base * base) % modulus;
//     exp >>= 1;
//   }
//   return result;
// }

// ll modinv(ll a, ll m) {
//     ll m0 = m;
//     ll y = 0, x = 1;
//     if (m == 1)
//       return 0;
//     while (a > 1)
//     {
//         ll q = a / m;
//         ll t = m;
//         m = a % m, a = t;
//         t = y;
//         y = x - q * y;
//         x = t;
//     }
//     if (x < 0)
//        x += m0;
//     return x;
// }

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    int start=0;
    int end=ans.size()-1;
    // ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            // if(sum>=INT32_MAX-2LL){
            //     ugh++;
            //     sum-=INT32_MAX-2LL;
            // }
            // if(sum<=-(INT32_MAX-2LL)){
            //     ugh--;
            //     sum+=-(-(INT32_MAX-2LL));
            // }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            // if(sum>=INT32_MAX-2LL){
            //     ugh++;
            //     sum-=INT32_MAX-2LL;
            // }
            // if(sum<=-(INT32_MAX-2LL)){
            //     ugh--;
            //     sum+=-(-(INT32_MAX-2LL));
            // }
            start++;
            end--;
        }
    }
    cout<<fixed<<setprecision(0)<<sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT32_MAX-2){
                ugh++;
                sum-=INT32_MAX-2;
            }
            if(sum<=-(INT32_MAX-2)){
                ugh--;
                sum-=-(-(INT32_MAX-2));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT32_MAX-2){
                ugh++;
                sum-=INT32_MAX-2;
            }
            if(sum<=-(INT32_MAX-2)){
                ugh--;
                sum-=-(-(INT32_MAX-2));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT32_MAX-2)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT16_MAX-2LL){
                ugh++;
                sum-=INT16_MAX-2LL;
            }
            if(sum<=-(INT16_MAX-2LL)){
                ugh--;
                sum+=-(-(INT16_MAX-2LL));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT16_MAX-2LL){
                ugh++;
                sum-=INT16_MAX-2LL;
            }
            if(sum<=-(INT16_MAX-2LL)){
                ugh--;
                sum+=-(-(INT16_MAX-2LL));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT16_MAX-2LL)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            if(sum>=INT16_MAX-2){
                ugh++;
                sum-=INT16_MAX-2;
            }
            if(sum<=-(INT16_MAX-2)){
                ugh--;
                sum-=-(-(INT16_MAX-2));
            }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            if(sum>=INT16_MAX-2){
                ugh++;
                sum-=INT16_MAX-2;
            }
            if(sum<=-(INT16_MAX-2)){
                ugh--;
                sum-=-(-(INT16_MAX-2));
            }
            start++;
            end--;
        }
    }
    cout<<ugh*(INT16_MAX-2)+sum;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

ll modpow(ll base, ll exp, ll modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

ll modinv(ll a, ll m) {
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    ll start=0;
    ll end=ans.size()-1;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            start++;
            end--;
        }
    }
    cout<<sum;

	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
struct myhash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef long double ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<string,ll> psl;
typedef vector<psl> vpsl;
typedef vector<int> vi;

#define fur(i,a,b) for(ll (i)=(a);i<(b);++(i))
#define revf(i,a,b) for(ll (i)=(a)-1;(i)>=(b);--(i))
#define mp make_pair
#define mod 1000000007
#define inf 2000000007
#define pb push_back
#define eps 1e-5
#define X first
#define Y second

// ll modpow(ll base, ll exp, ll modulus) {
//   base %= modulus;
//   ll result = 1;
//   while (exp > 0) {
//     if (exp & 1) result = (result * base) % modulus;
//     base = (base * base) % modulus;
//     exp >>= 1;
//   }
//   return result;
// }

// ll modinv(ll a, ll m) {
//     ll m0 = m;
//     ll y = 0, x = 1;
//     if (m == 1)
//       return 0;
//     while (a > 1)
//     {
//         ll q = a / m;
//         ll t = m;
//         m = a % m, a = t;
//         t = y;
//         y = x - q * y;
//         x = t;
//     }
//     if (x < 0)
//        x += m0;
//     return x;
// }

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    vll a(n);
    fur(i,0,n)cin>>a[i];
    unordered_map<ll,ll,myhash> m;
    vll pref(n+1);
    fur(i,1,n+1){
        pref[i]=a[i-1]+pref[i-1];
    }
    ll sum=0;
    vll ans(0);
    fur(i,0,n){
        ans.push_back(a[i]*(i-(m[a[i]-1]+m[a[i]+1]))-((pref[i])-(m[a[i]-1]*(a[i]-1)+m[a[i]+1]*(a[i]+1))));
        m[a[i]]++;
    }
    sort(ans.begin(),ans.end());
    int start=0;
    int end=ans.size()-1;
    // ll ugh=0;
    while(start<=end){
        if(start==end){
            sum+=ans[start];
            // if(sum>=INT32_MAX-2LL){
            //     ugh++;
            //     sum-=INT32_MAX-2LL;
            // }
            // if(sum<=-(INT32_MAX-2LL)){
            //     ugh--;
            //     sum+=-(-(INT32_MAX-2LL));
            // }
            break;
        }else{
            sum+=(ans[end]+ans[start]);
            // if(sum>=INT32_MAX-2LL){
            //     ugh++;
            //     sum-=INT32_MAX-2LL;
            // }
            // if(sum<=-(INT32_MAX-2LL)){
            //     ugh--;
            //     sum+=-(-(INT32_MAX-2LL));
            // }
            start++;
            end--;
        }
    }
    cout<<sum;
	return 0;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pair<long double, int> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long double, int> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long double, int> q = sum(2*v, l, mid, x, mid);
    pair<long double, int> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long double ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pair<long long, int> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, int> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, int> q = sum(2*v, l, mid, x, mid);
    pair<long long, int> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long long ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
#define int ll

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pii tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pii sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pii q = sum(2*v, l, mid, x, mid);
    pii w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    int ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pair<long double, int> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long double, int> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long double, int> q = sum(2*v, l, mid, x, mid);
    pair<long double, int> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long double ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << fixed << setprecision(0) << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vector< pair<ll, ll> > a;
pair<long long, ll> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, ll> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, ll> q = sum(2*v, l, mid, x, mid);
    pair<long long, ll> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    cout << ll((1ll << 62)-1+(1ll << 62));
    return 0;
    fast;
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long double ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pair<ll, ll> x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << fixed << setprecision(0) << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vector< pair<ll, ll> > a;
pair<long long, ll> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, ll> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, ll> q = sum(2*v, l, mid, x, mid);
    pair<long long, ll> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    fast;
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long double ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pair<ll, ll> x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << fixed << setprecision(0) << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pair<long long, int> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, int> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, int> q = sum(2*v, l, mid, x, mid);
    pair<long long, int> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long long ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pair<ll, ll> x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;
typedef long long ll;

vii a;
pii tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pii sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pii q = sum(2*v, l, mid, x, mid);
    pii w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

int main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    int ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vii a;
pair<long long, ll> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, ll> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, ll> q = sum(2*v, l, mid, x, mid);
    pair<long long, ll> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long long ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pair<ll, ll> x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

#define int ll

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;
typedef long long ll;

vii a;
pii tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pii sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pii q = sum(2*v, l, mid, x, mid);
    pii w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    int ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pii x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define files(x) ((x != "")? (freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)):(0))
#define fast ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pii > vii;

vector< pair<ll, ll> > a;
pair<long long, ll> tr[2000000];

void build(int v, int l, int r)
{
    if(l == r)
    {
        tr[v] = {a[l].ft, 1.0};
        return;
    }
    int mid = (l+r)/2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);
    tr[v] = {tr[2*v].ft+tr[2*v+1].ft, tr[2*v].sd+tr[2*v+1].sd};
}

void push(int v, int l, int r, int x, int c)
{
    if(l == r)
    {
        tr[v].ft = c;
        tr[v].sd = (c != 0);
        return;
    }
    int mid = (l+r)/2;
    if(x <= mid)
        push(2*v, l, mid, x, c);
    else
        push(2*v+1, mid+1, r, x, c);
    tr[v] = {tr[2*v].ft + tr[2*v+1].ft, tr[2*v].sd + tr[2*v+1].sd};
}

pair<long long, ll> sum(int v, int l, int r, int x, int y)
{
    if(l == x && r == y)
        return tr[v];
    int mid = (l+r)/2;
    if(y <= mid)
        return sum(2*v, l, mid, x, y);
    if(mid < x)
        return sum(2*v+1, mid+1, r, x, y);
    pair<long long, ll> q = sum(2*v, l, mid, x, mid);
    pair<long long, ll> w = sum(2*v+1, mid+1, r, mid+1, y);
    return {q.ft+w.ft, q.sd+w.sd};
}

main()
{
    #ifdef ANDRII

        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #else
        files("");
    #endif // ANDRII
    int n;
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].ft;
        a[i].sd = i;
    }
    build(1, 1, n);
    sort(a.begin()+1, a.end());
    queue<pii> add;
    long long ans = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(!add.empty() && a[i].ft-add.front().ft > 1)
        {
            push(1, 1, n, add.front().sd, add.front().ft);
            add.pop();
        }
        while(j <= n && a[j].ft-a[i].ft <= 1)
        {
            push(1, 1, n, a[j].sd, 0);
            add.push(a[j]);
            j++;
        }
        pair<ll, ll> x = sum(1, 1, n, a[i].sd, n);
        ans += x.ft - a[i].ft*x.sd;
        //cerr << a[i].sd << ' ' << ans << '\n';
    }
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
//queue<int> q;
#define lli long long int
#define li long int
#define si stack<int>
#define spi stack<pair<int,int> >
#define sli stack<long int>
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define vpi vector<pair<int,int> >
#define vli vector<long int>
#define pi pair<int,int>
#define pli pair<long int,long int>
#define qi queue<int>
#define qli queue<long int>
#define pb push_back
#define qpi queue<pair<int,int> >
#define pq priority_queue<>
#define vpli vector<pair<long int,long int> >
#define vulli vector<unsigned long long int>
#define vuli vector<unsigned long int>
#define ulli unsigned long long int
#define uli unsigned long int
#define vb vector<bool>

vector<int> factorize(int n) {
    vector<int> res;
    for (int i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

lli multiple(lli a, lli b, lli c)  //for multiplying bigger nmbers mod C like 10^18 and 10^18 (out of ulli range)
{
  if (b==0)   return 0;
  lli ret = multiple(a,b >> 1,c);
  ret = (ret + ret) % c;
  if (b & 1) ret = (ret + a)%c;
  return ret;
}

/*
vb isPrime;
void sieve(int N) {
        isPrime.resize(N+1);
        for(int i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(int j = 2; j*i <= N ;j++)
                     isPrime[j*i] = false;
            }
        }
    }
*/
li GCD(int A, int B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
/*
int d, x, y;
void extendedEuclid(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
*/

//lli que,n,m,a=0,b,mi=0,c=0,t=0,i=0,j,l,k,r,d,t1,t2;
 //priority_queue <pair<li,li> > q1; maxpriority element
 //priority_queue<pair<li,li>, vector<pair<li,li> >, greater<pair<li,li> > > q2; minpriority elements
li Log2(li x)
{
    li ans = 0 ;
    while (x>>=1) ans++;
    return ans ;
}

lli mini(lli a,lli b)
{
if(a<=b)
return a;
else return b;
}

lli maxe(lli a,lli b)
{
if(a>=b)
return a;
else return b;
}
 //ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int main()
{
	lli n;
	cin>>n;
	vlli v(n+1),arr(n+2);
	for(li i=1;i<=n;i++)
		cin>>v[i];
	for(li i=n;i>=1;i--)
		arr[i]+=v[i]+arr[i+1];
lli ans=0,ans2=0;
lli a,b;
vlli vr,vrn;
map<lli,lli> m;
	for(lli i=1;i<=n;i++)
	{
		ans+=(arr[i+1]-((n-i)*v[i]));
		a=m[v[i]-1];
		b=m[v[i]+1];
		ans-=a;
		ans+=b;
		if(ans>=1000000000000000)
			vr.pb(ans),ans=0;
		else if(ans<=-1000000000000000)
			vrn.pb(ans),ans=0;
		m[v[i]]++;

	}
	if(ans>0)
	vr.pb(ans);
	else vrn.pb(ans);
	ulli a11=0,a2=0;
for(auto j:vr)
	a11+=j;
for(auto j:vrn)
	a2+=abs(j);

	lli aa,bb;
aa=a11;
bb=a2;
cout<<aa-bb;

    }


#include<bits/stdc++.h>
using namespace std;
//queue<int> q;
#define lli long long int
#define li long int
#define si stack<int>
#define spi stack<pair<int,int> >
#define sli stack<long int>
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define vpi vector<pair<int,int> >
#define vli vector<long int>
#define pi pair<int,int>
#define pli pair<long int,long int>
#define qi queue<int>
#define qli queue<long int>
#define pb push_back
#define qpi queue<pair<int,int> >
#define pq priority_queue<>
#define vpli vector<pair<long int,long int> >
#define vulli vector<unsigned long long int>
#define vuli vector<unsigned long int>
#define ulli unsigned long long int
#define uli unsigned long int
#define vb vector<bool>

vector<int> factorize(int n) {
    vector<int> res;
    for (int i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

lli multiple(lli a, lli b, lli c)  //for multiplying bigger nmbers mod C like 10^18 and 10^18 (out of ulli range)
{
  if (b==0)   return 0;
  lli ret = multiple(a,b >> 1,c);
  ret = (ret + ret) % c;
  if (b & 1) ret = (ret + a)%c;
  return ret;
}

/*
vb isPrime;
void sieve(int N) {
        isPrime.resize(N+1);
        for(int i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(int j = 2; j*i <= N ;j++)
                     isPrime[j*i] = false;
            }
        }
    }
*/
li GCD(int A, int B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
/*
int d, x, y;
void extendedEuclid(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
*/

//lli que,n,m,a=0,b,mi=0,c=0,t=0,i=0,j,l,k,r,d,t1,t2;
 //priority_queue <pair<li,li> > q1; maxpriority element
 //priority_queue<pair<li,li>, vector<pair<li,li> >, greater<pair<li,li> > > q2; minpriority elements
li Log2(li x)
{
    li ans = 0 ;
    while (x>>=1) ans++;
    return ans ;
}

lli mini(lli a,lli b)
{
if(a<=b)
return a;
else return b;
}

lli maxe(lli a,lli b)
{
if(a>=b)
return a;
else return b;
}
 //ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int main()
{
	lli n;
	cin>>n;
	vlli v(n+1),arr(n+2);
	for(li i=1;i<=n;i++)
		cin>>v[i];
	for(li i=n;i>=1;i--)
		arr[i]+=v[i]+arr[i+1];
lli ans=0,ans2=0;
lli a,b;
map<lli,lli> m;
	for(lli i=1;i<=n;i++)
	{
		ans+=(arr[i+1]-((n-i)*v[i]));
		a=m[v[i]-1];
		b=m[v[i]+1];
		ans-=a;
		ans+=b;
		if(ans>1000000000000000)
			ans2=ans,ans=0;
		m[v[i]]++;

	}
	ans+=ans2;
cout<<ans;

    }


#include<bits/stdc++.h>
using namespace std;
//queue<int> q;
#define lli long long int
#define li long int
#define si stack<int>
#define spi stack<pair<int,int> >
#define sli stack<long int>
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define vpi vector<pair<int,int> >
#define vli vector<long int>
#define pi pair<int,int>
#define pli pair<long int,long int>
#define qi queue<int>
#define qli queue<long int>
#define pb push_back
#define qpi queue<pair<int,int> >
#define pq priority_queue<>
#define vpli vector<pair<long int,long int> >
#define vulli vector<unsigned long long int>
#define vuli vector<unsigned long int>
#define ulli unsigned long long int
#define uli unsigned long int
#define vb vector<bool>

vector<int> factorize(int n) {
    vector<int> res;
    for (int i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

lli multiple(lli a, lli b, lli c)  //for multiplying bigger nmbers mod C like 10^18 and 10^18 (out of ulli range)
{
  if (b==0)   return 0;
  lli ret = multiple(a,b >> 1,c);
  ret = (ret + ret) % c;
  if (b & 1) ret = (ret + a)%c;
  return ret;
}

/*
vb isPrime;
void sieve(int N) {
        isPrime.resize(N+1);
        for(int i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(int j = 2; j*i <= N ;j++)
                     isPrime[j*i] = false;
            }
        }
    }
*/
li GCD(int A, int B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
/*
int d, x, y;
void extendedEuclid(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
*/

//lli que,n,m,a=0,b,mi=0,c=0,t=0,i=0,j,l,k,r,d,t1,t2;
 //priority_queue <pair<li,li> > q1; maxpriority element
 //priority_queue<pair<li,li>, vector<pair<li,li> >, greater<pair<li,li> > > q2; minpriority elements
li Log2(li x)
{
    li ans = 0 ;
    while (x>>=1) ans++;
    return ans ;
}

lli mini(lli a,lli b)
{
if(a<=b)
return a;
else return b;
}

lli maxe(lli a,lli b)
{
if(a>=b)
return a;
else return b;
}
 //ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int main()
{
	lli n;
	cin>>n;
	vlli v(n+1),arr(n+2);
	for(li i=1;i<=n;i++)
		cin>>v[i];
	for(li i=n;i>=1;i--)
		arr[i]+=v[i]+arr[i+1];
lli ans=0,ans2=0;
lli a,b;
map<lli,lli> m;
	for(lli i=1;i<=n;i++)
	{
		ans+=(arr[i+1]-((n-i)*v[i]));
		a=m[v[i]-1];
		b=m[v[i]+1];
		ans-=a;
		ans+=b;
		if(ans>1000000000000000)
			ans2=ans,ans=0;
		m[v[i]]++;

	}
cout<<ans+ans2;

    }