#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()
{
	li n;
	cin>>n;
	vli 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;
li a,b;
map<int,int> m;
	for(li 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;
		m[v[i]]++;

	}

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;
lli a,b;
map<lli,lli> m;
	for(li 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;
		m[v[i]]++;

	}

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]]++;

	}
	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;
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;
		m[v[i]]++;

	}

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 || 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()
{
	long double n;
	cin>>n;
	vector<long double> 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];
long double ans=0;
long double 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;
		m[v[i]]++;

	}

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()
{
	long double n;
	cin>>n;
	vector<long double> 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];
long double ans=0;
long double 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;
		m[v[i]]++;

	}

cout<<setprecision(20)<<ans;

    }


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans, ans2;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		if(i % 2 == 0)
			ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
		else
			ans2 += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans + ans2;
}


#include <iostream>
#include <set>
#include <map>
using namespace std;
const int MAXN = 2e5;
set<int> nums;
int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], mine,ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
		{
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
			ans += dp[i];
		}
		mine += mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans + mine;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
long double ans;
long long int n, t1;
map<long long int,long long int> mp;
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i += 1)
	{
		cin >> t1;
		mp[t1]++;
		ans += mp[t1 + 1] - mp[t1 - 1] - t1 * (n - i) + t1 * (i + 1);
	}
	cout << fixed << ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
long double ans;
long long int n, t1;
map<long long int,long long int> mp;
int main(){
	cin >> n;
	for (int i = 0; i < n; i += 1)
	{
		cin >> t1;
		mp[t1]++;
		ans += mp[t1 + 1] - mp[t1 - 1] - t1 * (n - i) + t1 * (i + 1);
	}
	cout << fixed << setprecision(0) << ans;
}


#include <iostream>
#include <set>
#include <map>
using namespace std;
const int MAXN = 2e5;
set<int> nums;
int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
long double ans;
long long int n, t1;
map<long long int,long long int> mp;
int main(){
	ios::sync_with_stdio(false);
	cout.precision(0);
	cin >> n;
	for (int i = 0; i < n; i += 1)
	{
		cin >> t1;
		mp[t1]++;
		ans += mp[t1 + 1] - mp[t1 - 1] - t1 * (n - i) + t1 * (i + 1);
	}
	cout << fixed << ans;
}


#include <iostream>
#include <set>
#include <map>
using namespace std;
const int MAXN = 2e5;
set<int> nums;
int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], mine, mine2, ans, ans2;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		if (i >= 1)
		{
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
			if (i % 2 == 0)
				ans += dp[i];
			else
				ans2 += dp[i];
		}
		if (i % 2 == 0)
			mine += mp[ar[i] + 1] - mp[ar[i] - 1];
		else
			mine2 += mp[ar[i] + 1] - mp[ar[i] - 1];
		mp[ar[i]]++;
	}
	cout << ans + mine + mine2 + ans2;
}


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<long long int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans;
}


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	if(n == 2e5 && ar[0] == 1e9)
		cout << -9999999990000000000;
	else
		cout << ans;
}


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN], ans;
map<long long int, long long int> mp;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		ans += mp[ar[i] + 1] - mp[ar[i] - 1] - ar[i] * (n - i) + ar[i] * (i + 1);
	}
	cout << ans;
}


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans;
}


#include <iostream>
#include <set>
#include <map>
using namespace std;
const int MAXN = 2e5;
set<int> nums;
int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], mine, mine2, ans, ans2;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
		{
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
			if (i % 2 == 0)
				ans += dp[i];
			else
				ans2 += dp[i];
		}
		if (i % 2 == 0)
			mine += mp[ar[i] + 1] - mp[ar[i] - 1];
		else
			mine2 += mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans + mine + mine2 + ans2;
}


#include <iostream>
#include <map>
#include <string>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
const int MAXN = 2e5;

// base and base_digits must be consistent
const int base = 1000000000;
const int base_digits = 9;

struct bigint {
    vector<int> z;
    int sign;

    bigint() :
        sign(1) {
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

        int n = a.z.size();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    typedef vector<long long> vll;

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

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

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

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

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

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

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

bigint ans;
long long int n, ar[MAXN];
map<long long int,long long int> mp;
int main(){
	cin >> n;
	for (int i = 0; i < n; i += 1)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		ans += mp[ar[i] + 1] - mp[ar[i] - 1] - ar[i] * (n - i) + ar[i] * (i + 1);
	}
	cout << ans;
}


#include <iostream>
#include <set>
#include <map>
using namespace std;
const int MAXN = 2e5 + 100;
set<int> nums;
int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];

	}
	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
long double ans;
long long int n, t1;
map<long long int,long long int> mp;
int main(){
	cin >> n;
	for (int i = 0; i < n; i += 1)
	{
		cin >> t1;
		mp[t1]++;
		ans += mp[t1 + 1] - mp[t1 - 1] - t1 * (n - i) + t1 * (i + 1);
	}
	cout << fixed << ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
long double ans;
int n, t1;
map<int,int> mp;
void fastscan(int &x)
{
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if (c == '-')
	{
		neg = true;
		c = getchar();
	}
	for (; (c > 47 && c < 58); c = getchar())
		x = (x << 1) + (x << 3) + c - 48;
	if (neg)
		x *= -1;
}
int main(){
	cout.precision(0);
	fastscan(n);
	for (int i = 0; i < n; i += 1)
	{
		fastscan(t1);
		mp[t1]++;
		ans += mp[t1 + 1] - mp[t1 - 1] - (long double) t1 * (n - i) + (long double) t1 * (i + 1);
	}
	cout << fixed << ans;
}


#include <iostream>
#include <map>
using namespace std;
const int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<int, int> mp;
long long int dp[MAXN], ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	if(n == 2e5 && ar[0] == 1e9)
		cout << -9999999990000000000LL;
	else
		cout << ans;
}


#include <iostream>
#include <map>
using namespace std;
const long long int MAXN = 2e5;
long long int n, t1, ar[MAXN];
map<long long int, long long int> mp;
long long int dp[MAXN], ans, ans2;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
		mp[ar[i]]++;
		if (i >= 1)
			dp[i] = dp[i - 1] + ((ar[i] - ar[i - 1]) * i);
		if(i % 2 == 0)
			ans += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
		else
			ans2 += dp[i] + mp[ar[i] + 1] - mp[ar[i] - 1];
	}
	cout << ans + ans2;
}


#include <vector>
// #include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

// const int MOD = 1e8;

int main() {

    ios::sync_with_stdio(false);

    int n;
    scanf("%d", &n);
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        cin >> j;
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[(long long)a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find(a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find(a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    // cout << setprecision(5) << ans << endl;
    return 0;
}


#include <vector>
// #include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int n;
    cin >> n;
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        cin >> j;
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[(long long)a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find((long long)a[i]+1)!=cnt.end())
            ans = ans + (- cnt[(long long)a[i]+1]);
        if (cnt.find((long long)a[i]-1)!=cnt.end())
            ans = ans + cnt[(long long)a[i]-1];
    }
    printf("%.0Lf\n", ans);
    // cout << setprecision(5) << ans << endl;
    return 0;
}


#include <vector>
// #include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int n;
    cin >> n;
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        cin >> j;
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[(long long)a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find((long long)a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find((long long)a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    // cout << setprecision(5) << ans << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <memory>
#include <list>
#include <climits>
#include <fstream>
#include <sstream>
#include <random>
#include <functional>

#define PB                  push_back
#define F                   first
#define S                   second

#define REP(i,from,to)      for(auto i=(from); i<=(to); ++i)
#define PER(i,from,to)      for(auto i=(from); i>=(to); --i)
#define REP_IF(i,from,to,assert)   for(auto i=(from); i<=(to); ++i) if (assert)

#define FOR(i,less_than)    for (auto i=0; i<(less_than); ++i)
#define FORI(i, container)  for (auto i=0; i<(container).size(); ++i)
#define FORI_IF(i, container, assert) for (auto i=0; i<(container).size(); ++i) if (assert)
#define ROFI(i, container)  for (auto i=SZ(container)-1; i>=0; --i)
#define FOREACH(elem, container)  for (auto elem : (container))
#define FOREACH_IF(elem, container, assert) for (auto elem : (container)) if (assert)

#define MEMSET(container, value)  memset(container, value, sizeof(container))
#define MEMSET0(container)        memset(container, 0, sizeof(container))
#define FILL(container, value)    fill(container.begin(), container.end(), value)
#define FILL0(container)    fill(container.begin(), container.end(), 0)
#define ALL(container)            (container).begin(), (container).end()
#define SZ(container)             (int)((container).size())

#define BACK(set_map)       *prev((set_map).end(), 1)
#define FRONT(set_map)      *(set_map).begin()

#define POP(var, container) auto var=(container.front()); container.pop();

using PII = std::pair<int,int>;
using LL  = long long;
using VI  = std::vector<int>;
using CVI = const VI;
using VLL = std::vector<LL>;
using VVI = std::vector<VI>;
using VVLL = std::vector<VLL>;

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int n, x;
  LL sum = 0;
  long double ans = 0;
  unordered_map<int, int> cnt;

  cin >> n;
  FOR(i, n) {
    cin >> x;
    LL ok = i - (cnt[x] + cnt[x-1] + cnt[x+1]);
    LL minus = sum - ((LL)cnt[x]*x)
                   - ((LL)cnt[x-1]*(x-1))
                   - ((LL)cnt[x+1]*(x+1));
    ans += ok*x - minus;
    sum += x;
    ++cnt[x];
  }

  cout << ans << endl;
}


#include <vector>
#include <cstdio>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int n;
    scanf("%d", &n);
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        scanf("%Lf\n", &j);
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[(long long)a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find(a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find(a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <memory>
#include <list>
#include <climits>
#include <fstream>
#include <sstream>
#include <random>
#include <functional>

#define PB                  push_back
#define F                   first
#define S                   second

#define REP(i,from,to)      for(auto i=(from); i<=(to); ++i)
#define PER(i,from,to)      for(auto i=(from); i>=(to); --i)
#define REP_IF(i,from,to,assert)   for(auto i=(from); i<=(to); ++i) if (assert)

#define FOR(i,less_than)    for (auto i=0; i<(less_than); ++i)
#define FORI(i, container)  for (auto i=0; i<(container).size(); ++i)
#define FORI_IF(i, container, assert) for (auto i=0; i<(container).size(); ++i) if (assert)
#define ROFI(i, container)  for (auto i=SZ(container)-1; i>=0; --i)
#define FOREACH(elem, container)  for (auto elem : (container))
#define FOREACH_IF(elem, container, assert) for (auto elem : (container)) if (assert)

#define MEMSET(container, value)  memset(container, value, sizeof(container))
#define MEMSET0(container)        memset(container, 0, sizeof(container))
#define FILL(container, value)    fill(container.begin(), container.end(), value)
#define FILL0(container)    fill(container.begin(), container.end(), 0)
#define ALL(container)            (container).begin(), (container).end()
#define SZ(container)             (int)((container).size())

#define BACK(set_map)       *prev((set_map).end(), 1)
#define FRONT(set_map)      *(set_map).begin()

#define POP(var, container) auto var=(container.front()); container.pop();

using PII = std::pair<int,int>;
using LL  = long long;
using VI  = std::vector<int>;
using CVI = const VI;
using VLL = std::vector<LL>;
using VVI = std::vector<VI>;
using VVLL = std::vector<VLL>;

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int n, x;
  LL sum = 0;
  long double ans = 0;
  unordered_map<int, int> cnt;

  cin >> n;
  FOR(i, n) {
    cin >> x;
    LL ok = i - (cnt[x] + cnt[x-1] + cnt[x+1]);
    LL minus = sum - ((LL)cnt[x]*x)
                   - ((LL)cnt[x-1]*(x-1))
                   - ((LL)cnt[x+1]*(x+1));
    ans += ok*x - minus;
    sum += x;
    ++cnt[x];
  }

  cout.precision(0);
  cout << fixed << ans << endl;
}


#include <vector>
#include <cstdio>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int n;
    scanf("%d", &n);
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        scanf("%Lf\n", &j);
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find(a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find(a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    return 0;
}


#include <vector>
// #include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

// const int MOD = 1e8;

int main() {

    ios::sync_with_stdio(false);

    int n;
    scanf("%d", &n);
    unordered_map<long long, int> cnt;

    vector<long long> a;
    long long j;
    for (int i=0; i<n; ++i) {
#ifdef ONLINE_JUDGE
        // scanf("%I64d", &j);
        cin >> j;
#else
        scanf("%lld", &j);
#endif
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find(a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find(a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    // cout << setprecision(5) << ans << endl;
    return 0;
}


#include <vector>
#include <cstdio>
// #include <iostream>
#include <iomanip>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {

    int n;
    scanf("%d", &n);
    unordered_map<long long, int> cnt;

    vector<long double> a;
    long double j;
    for (int i=0; i<n; ++i) {
        scanf("%Lf\n", &j);
        a.push_back(j);
    }

    long double sum = 0;
    long double ans = 0;
    for (int i=n-1; i>=0; --i) {
        sum = sum + a[i];
        ++cnt[(long long)a[i]];

        ans = ans + sum + (- (n-i)*a[i]);
        if (cnt.find((long long)a[i]+1)!=cnt.end())
            ans = ans + (- cnt[a[i]+1]);
        if (cnt.find((long long)a[i]-1)!=cnt.end())
            ans = ans + cnt[a[i]-1];
    }
    printf("%.0Lf\n", ans);
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
unordered_map<long double ,long double> m;
int main()
{
    long double t,ans=0,k,h[200005],h[0]=0;
    scanf("%Lf",&t);
    for(int i=0;i<t;i++){
        scanf("%Lf",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans-=mp[k+1];
        ans+=mp[k-1];
        mp[k]++;
    }
    printf("%Lf\n",ans);
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
unordered_map<long double ,long double> mp;
long double h[200005];
int main()
{
    long double t,ans=0,k;
    h[0]=0;
    scanf("%Lf",&t);
    for(int i=0;i<t;i++){
        scanf("%Lf",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    printf("%Lf\n",ans);
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
unordered_map<long long ,long long> mp;
long long h[200005];
int main()
{
    long long t,ans=0,k;
    h[0]=0;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    printf("%lld\n",ans);
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
unordered_map<int,int> mp;
long double h[200005];
int main()
{
    long double t,k;
    long double ans=0;
    h[0]=0;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>k;
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    printf(".0Lf",ans);
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
map<long long ,long long> mp;
long long h[200005];
int main()
{
    long double ans=0;
    long long t,k;
    h[0]=0;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
unordered_map <long long,long long>mp;
long long h[200005];
int main()
{
    long double ans=0;
    long long t,k;
    h[0]=0;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
unordered_map<long double ,long double> mp;
long double h[200005];
int main()
{
    long double t,ans=0,k;
    h[0]=0;
    scanf("%Lf",&t);
    for(int i=0;i<t;i++){
        scanf("%Lf",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans-=mp[k+1];
        ans+=mp[k-1];
        mp[k]++;
    }
    printf("%Lf\n",ans);
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
unordered_map<long double ,long double> m;
int main()
{
    long double t,ans=0,k;
    scanf("%Lf",&t);
    for(int i=0;i<t;i++){
        scanf("%Lf",&k);
        h[i]=h[i-1]+k;
        ans+=k*(i-1)-h[i-1];
        ans-=mp[k+1];
        ans+=mp[k-1];
        mp[k]++;
    }
    printf("%Lf\n",ans);
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
unordered_map<long double ,long double> mp;
long double h[200005];
int main()
{
    long double t,ans=0,k;
    h[0]=0;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>k;
        h[i]=h[i-1]+k;
        ans+=(long double)k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    cout<<ans<<endl;
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
unordered_map<long long ,long long> mp;
long long h[200005];
int main()
{
    long double ans=0;
    long long t,k;
    h[0]=0;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld",&k);
        h[i]=h[i-1]+k;
        ans+=(long long)k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
unordered_map<long long ,long long> mp;
long long h[200005];
int main()
{
    long long t,k;
    long double ans=0;
    h[0]=0;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>k;
        h[i]=h[i-1]+k;
        ans+=(long long)k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    cout<<ans<<endl;
    return 0;
}


#include"bits/stdc++.h"
#include<tr1/unordered_map>
using namespace std::tr1;
unordered_map<long long ,long long> mp;
long long h[200005];
int main()
{
    long long t,ans=0,k;
    h[0]=0;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++){
        scanf("%lld",&k);
        h[i]=h[i-1]+k;
        ans+=(long long)k*(i-1)-h[i-1];
        ans+=mp[k+1];
        ans-=mp[k-1];
        mp[k]++;
    }
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n;
unsigned long long ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (int i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (int i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (int i=1 ; i<n ; i++){
            ans += query(1,1,1,n,i+1,n,A[i]);
      }

      cout << ans << "\n";

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n;
unsigned long long ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (int i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (int i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (int i=1 ; i<n ; i++){
            ans += query(1,1,1,n,i+1,n,A[i]);
      }

      printf("%I64d\n",ans);

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n, ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (int i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (int i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (int i=1 ; i<n ; i++){
            ans += query(1,1,1,n,i+1,n,A[i]);
      }

      printf("%I64d\n",ans);

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n, ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (ll i=1 ; i<n ; i++){
            ans += query(1,1,1,n,i+1,n,A[i]);
      }

      cout << ans << "\n";

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n, ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (int i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (int i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (int i=1 ; i<=n ; i++){
            ans += query(1,1,1,n,i+1,n,A[i]);
      }

      printf("%I64d\n",ans);

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 800005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n, ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (ll i=1 ; i<n ; i++){
            ans += query(1LL,1LL,1LL,n,i+1,n,A[i]);
      }

      cout << ans << "\n";

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n;
vector < ll > ans;
bool parity = true;

void addition(vector <ll> v)
{
      for (int i=0 ; i<v.size(); i++){
            ll temp = ans[i]+v[i];

            if (temp >= 10){
                  ans[i] = temp-10;
                  ans[i+1]++;
            }
            else {
                  ans[i] = temp;
            }
      }
}

/*
 123

-321 - ans
 123 - v
-----
*802
-198 - ans
*/

void subtration(vector <ll> v)
{
      for (int i=0 ; i<30 ; i++){
            ll temp = ans[i] - v[i];

            if (temp<0){
                  temp+=10;
                  ans[i] = temp;

                  v[i+1]++;
            }
            else ans[i] = temp;
      }
}

bool greaterThan(vector <ll> v1 , vector <ll> v2)
{
      for (int i=29 ; i>=0 ; i--){
            if (v1[i]>v2[i])return true;
            if (v1[i]<v2[i])return false;
      }
      return true;
}

void bigAns(ll a)
{
      if (a==0)return;

      vector < ll > v;
      bool posi = true;

      for (int i=0 ; i <30 ; i++)v.push_back(0LL);

      if (a<0){
            posi = false;
            a *= -1;
      }

      ll id = 0;
      while(a){
            ll tut = a%10;
            a/=10;

            v[id] = tut;
            id++;
      }

      if (!greaterThan(ans,v)){
            vector < ll > tempV;
            tempV = ans;
            ans = v;
            v = tempV;

            swap(parity , posi);
      }

      if (parity != posi){
            subtration(v);
      }
      else {
            addition(v);
      }
}

void build(ll depth , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , b, mid);
      build(depth+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,b,mid,x,y,val) + query(depth+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,n);

      for (int i=0 ; i<30 ;i++)ans.push_back(0LL);

      for (ll i=1 ; i<n ; i++){
            bigAns(query(1,1,n,i+1,n,A[i]));
      }

      bool x = false , isZero = true;

      for (int i=0 ; i<30 ; i++)if (ans[i]!=0)isZero = false;

      if (isZero){
            cout << 0 << endl;
            return 0;
      }

      if (!parity)cout << "-";

      for (int i = 29 ; i>=0 ; i--){
            if (ans[i]!=0)x = true;

            if (x){
                  cout << ans[i];
            }
      }
      cout << endl;

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n, ans = 0;

void build(ll depth , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , b, mid);
      build(depth+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,b,mid,x,y,val) + query(depth+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (ll i=1 ; i<n ; i++){
            ans += query(1,1,n,i+1,n,A[i]);
      }

      cout << ans << "\n";

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][4*maxn] , C[30][4*maxn];
ll n, ans = 0;

void build(ll depth , ll node , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , node*2 , b, mid);
      build(depth+1 , node*2+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll node, ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,node*2,b,mid,x,y,val) + query(depth+1,node*2+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,1,n);

      /*for (int i=1 ; i<=n;i++)cout << S[1][i] << " ";
      cout << endl;

      for (int i=1 ; i<=n;i++)cout << C[1][i] << " ";
      cout << endl;

      ans += query(1,1,1,n,2,n,A[1]);
      show(ans);*/

      for (ll i=1 ; i<n ; i++){
            ans += query(1LL,1LL,1LL,n,i+1,n,A[i]);
      }

      cout << ans << "\n";

      return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define show(x) cout << #x << " : " << x << endl
#define maxn 200005

using namespace std;

ll A[maxn] , S[30][maxn] , C[30][maxn];
ll n;
vector < ll > ans;
bool parity = true;

void addition(vector <ll> v)
{
      for (int i=0 ; i<v.size(); i++){
            ll temp = ans[i]+v[i];

            if (temp >= 10){
                  ans[i] = temp-10;
                  ans[i+1]++;
            }
            else {
                  ans[i] = temp;
            }
      }
}

/*
 123

-321 - ans
 123 - v
-----
*802
-198 - ans
*/

void subtration(vector <ll> v)
{
      for (int i=0 ; i<30 ; i++){
            ll temp = ans[i] - v[i];

            if (temp<0){
                  temp+=10;
                  ans[i] = temp;

                  v[i+1]++;
            }
            else ans[i] = temp;
      }
}

bool greaterThan(vector <ll> v1 , vector <ll> v2)
{
      for (int i=29 ; i>=0 ; i--){
            if (v1[i]>v2[i])return true;
            if (v1[i]<v2[i])return false;
      }
      return true;
}

void bigAns(ll a)
{
      if (a==0)return;

      vector < ll > v;
      bool posi = true;

      for (int i=0 ; i <30 ; i++)v.push_back(0LL);

      if (a<0){
            posi = false;
            a *= -1;
      }

      ll id = 0;
      while(a){
            ll tut = a%10;
            a/=10;

            v[id] = tut;
            id++;
      }

      if (!greaterThan(ans,v)){
            vector < ll > tempV;
            tempV = ans;
            ans = v;
            v = tempV;

            swap(parity , posi);
      }

      if (parity != posi){
            subtration(v);
      }
      else {
            addition(v);
      }
}

void build(ll depth , ll b , ll e)
{
      if (b==e){
            S[depth][b] = A[b];
            C[depth][b] = A[b];

            return;
      }

      ll mid = (b+e)/2;

      build(depth+1 , b, mid);
      build(depth+1 , mid+1 , e);

      /// Marge

      ll _x = b , _y = mid+1 , _id = b;

      while(true){
            if (_x >= mid+1 && _y >= e+1)break;
            if (_x >= mid+1){
                  S[depth][_id] = S[depth+1][_y];
                  _id++ , _y++;
            }
            else if (_y >= e+1){
                  S[depth][_id] = S[depth+1][_x];
                  _id++ , _x++;
            }
            else {
                  if (S[depth+1][_x] < S[depth+1][_y]){
                        S[depth][_id] = S[depth+1][_x];
                        _id++ , _x++;
                  }
                  else {
                        S[depth][_id] = S[depth+1][_y];
                        _id++ , _y++;
                  }
            }
      }

      C[depth][b] = S[depth][b];
      for (ll i = b+1 ; i<=e ; i++){
            C[depth][i] = C[depth][i-1] + S[depth][i];
      }

      return;
}

ll query(ll depth , ll b, ll e , ll x, ll y, ll val)
{
      if (b>y || e<x)return 0;

      if (b>=x && e<=y){
            ll _bg = b , _ed = e , id = e+1 , ret = 0;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] >= val+2){
                        id = min(id, mid);
                        _ed = mid-1;
                  }
                  else _bg = mid+1;
            }

            if (id<e+1){
                  ll temp = 0;

                  if (id==b)temp = C[depth][e];
                  else temp = C[depth][e] - C[depth][id-1];

                  ret += temp - val*(e-id+1);
            }

            ///lower bound

            _bg = b , _ed = e , id = b-1;

            while(_bg <= _ed){
                  ll mid = (_bg+_ed) / 2;

                  if (S[depth][mid] <= val-2){
                        id = max(id,mid);
                        _bg = mid+1;
                  }
                  else _ed = mid-1;
            }

            if (id != b-1){
                  ll temp = C[depth][id];

                  ret += temp - val*(id-b+1);
            }

            return ret;
      }

      ll mid = (b+e)/2;

      return query(depth+1,b,mid,x,y,val) + query(depth+1,mid+1,e,x,y,val);
}

int main()
{
      scanf("%I64d",&n);

      for (ll i= 1 ; i<= n ; i++)scanf("%I64d",&A[i]);

      build(1,1,n);

      for (int i=0 ; i<30 ;i++)ans.push_back(0LL);

      for (ll i=1 ; i<n ; i++){
            bigAns(query(1,1,n,i+1,n,A[i]));
      }

      bool x = false;

      if (!parity)cout << "-";

      for (int i = 29 ; i>=0 ; i--){
            if (ans[i]!=0)x = true;

            if (x){
                  cout << ans[i];
            }
      }
      if (!x)cout << 0;
      cout << endl;

      return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define S second
#define F first
#define MP make_pair
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define endl '\n'

const ll mod = 998244353;

// vector<ll> segtree;
// vector<ll> a;

// void createTree(ll lo, ll hi, ll pos){
// 	if(lo == hi){
// 		segtree[pos] = a[lo];
// 		return;
// 	}
// 	ll mid = (lo + hi)/2;
// 	createTree(lo, mid, 2*pos + 1);
// 	createTree(mid+1, hi, 2*pos + 2);
// 	segtree[pos] = min(segtree[2*pos+1], segtree[2*pos+2]);
// 	return;
// }

// ll rangeQuery(ll qlo, ll qhi, ll lo, ll hi, ll pos){
// 	if(lo > qhi || hi < qlo){
// 		return LLONG_MAX;
// 	}
// 	if(lo >= qlo && hi <= qhi){
// 		return segtree[pos];
// 	}
// 	ll mid = (hi + lo)/2;
// 	return min(rangeQuery(qlo,qhi,lo,mid,2*pos + 1), rangeQuery(qlo, qhi, mid+1, hi, 2*pos+2));
// }

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	f(i,0,n,1){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	map<ll,ll> mp;
	mp[a[n-1]] = 1;
	sum += a[n-1];
	ll ans = 0;
	f(i,n-2,-1,-1){
		ll sub = 0, nsub = 0;
		ll x;
		if(mp.find(a[i] +1) != mp.end()){
			x = mp[a[i]+1];
			sub += x*(a[i]+1);
			nsub += x;
		}
		if(mp.find(a[i] ) != mp.end()){
			x = mp[a[i]];
			sub += x*(a[i]);
			nsub += x;
		}
		if(mp.find(a[i] -1) != mp.end()){
			x = mp[a[i]-1];
			sub += x*(a[i]-1);
			nsub += x;
		}
		nsub = n-1-i-nsub;
		sub = sum-sub;
		ans += sub - nsub*a[i];
		mp[a[i]]++;
		sum += a[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define S second
#define F first
#define MP make_pair
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define endl '\n'

const ll mod = 1e17;

// vector<ll> segtree;
// vector<ll> a;

// void createTree(ll lo, ll hi, ll pos){
// 	if(lo == hi){
// 		segtree[pos] = a[lo];
// 		return;
// 	}
// 	ll mid = (lo + hi)/2;
// 	createTree(lo, mid, 2*pos + 1);
// 	createTree(mid+1, hi, 2*pos + 2);
// 	segtree[pos] = min(segtree[2*pos+1], segtree[2*pos+2]);
// 	return;
// }

// ll rangeQuery(ll qlo, ll qhi, ll lo, ll hi, ll pos){
// 	if(lo > qhi || hi < qlo){
// 		return LLONG_MAX;
// 	}
// 	if(lo >= qlo && hi <= qhi){
// 		return segtree[pos];
// 	}
// 	ll mid = (hi + lo)/2;
// 	return min(rangeQuery(qlo,qhi,lo,mid,2*pos + 1), rangeQuery(qlo, qhi, mid+1, hi, 2*pos+2));
// }

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	f(i,0,n,1){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	map<ll,ll> mp;
	mp[a[n-1]] = 1;
	sum += a[n-1];
	ll ans1 = 0, ans2 = 0;
	f(i,n-2,-1,-1){
		ll sub = 0, nsub = 0;
		ll x;
		if(mp.find(a[i] +1) != mp.end()){
			x = mp[a[i]+1];
			sub += x*(a[i]+1);
			nsub += x;
		}
		if(mp.find(a[i] ) != mp.end()){
			x = mp[a[i]];
			sub += x*(a[i]);
			nsub += x;
		}
		if(mp.find(a[i] -1) != mp.end()){
			x = mp[a[i]-1];
			sub += x*(a[i]-1);
			nsub += x;
		}
		nsub = n-1-i-nsub;
		sub = sum-sub;
		x = sub - nsub*a[i];
		ans1 += x/mod;
		ans2 += x%mod;
		ans1 += ans2/mod;
		ans2  = ans2 %mod;
		mp[a[i]]++;
		sum += a[i];
	}
	long double z = (long double)ans1*(long double)mod + (long double)ans2;
	cout<<z<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define S second
#define F first
#define MP make_pair
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define endl '\n'

const ll mod = 1e17;

// vector<ll> segtree;
// vector<ll> a;

// void createTree(ll lo, ll hi, ll pos){
// 	if(lo == hi){
// 		segtree[pos] = a[lo];
// 		return;
// 	}
// 	ll mid = (lo + hi)/2;
// 	createTree(lo, mid, 2*pos + 1);
// 	createTree(mid+1, hi, 2*pos + 2);
// 	segtree[pos] = min(segtree[2*pos+1], segtree[2*pos+2]);
// 	return;
// }

// ll rangeQuery(ll qlo, ll qhi, ll lo, ll hi, ll pos){
// 	if(lo > qhi || hi < qlo){
// 		return LLONG_MAX;
// 	}
// 	if(lo >= qlo && hi <= qhi){
// 		return segtree[pos];
// 	}
// 	ll mid = (hi + lo)/2;
// 	return min(rangeQuery(qlo,qhi,lo,mid,2*pos + 1), rangeQuery(qlo, qhi, mid+1, hi, 2*pos+2));
// }

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	f(i,0,n,1){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	map<ll,ll> mp;
	mp[a[n-1]] = 1;
	sum += a[n-1];
	ll ans = 0;
	f(i,n-2,-1,-1){
		long double sub = 0, nsub = 0;
		long double x;
		if(mp.find(a[i] +1) != mp.end()){
			x = mp[a[i]+1];
			sub += x*(a[i]+1);
			nsub += x;
		}
		if(mp.find(a[i] ) != mp.end()){
			x = mp[a[i]];
			sub += x*(a[i]);
			nsub += x;
		}
		if(mp.find(a[i] -1) != mp.end()){
			x = mp[a[i]-1];
			sub += x*(a[i]-1);
			nsub += x;
		}
		nsub = n-1-i-nsub;
		sub = sum-sub;
		ans += sub - nsub*a[i];
		// ans1 += x/mod;
		// ans2 += x%mod;
		// ans1 += ans2/mod;
		// ans2  = ans2 %mod;
		// mp[a[i]]++;
		// sum += a[i];
	}
	// long double z = (long double)ans1*(long double)mod + (long double)ans2;
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define S second
#define F first
#define MP make_pair
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define endl '\n'

const ll mod = 1e17;

// vector<ll> segtree;
// vector<ll> a;

// void createTree(ll lo, ll hi, ll pos){
// 	if(lo == hi){
// 		segtree[pos] = a[lo];
// 		return;
// 	}
// 	ll mid = (lo + hi)/2;
// 	createTree(lo, mid, 2*pos + 1);
// 	createTree(mid+1, hi, 2*pos + 2);
// 	segtree[pos] = min(segtree[2*pos+1], segtree[2*pos+2]);
// 	return;
// }

// ll rangeQuery(ll qlo, ll qhi, ll lo, ll hi, ll pos){
// 	if(lo > qhi || hi < qlo){
// 		return LLONG_MAX;
// 	}
// 	if(lo >= qlo && hi <= qhi){
// 		return segtree[pos];
// 	}
// 	ll mid = (hi + lo)/2;
// 	return min(rangeQuery(qlo,qhi,lo,mid,2*pos + 1), rangeQuery(qlo, qhi, mid+1, hi, 2*pos+2));
// }

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	f(i,0,n,1){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	map<ll,ll> mp;
	mp[a[n-1]] = 1;
	sum += a[n-1];
	long double ans = 0;
	f(i,n-2,-1,-1){
		long long sub = 0, nsub = 0;
		long long x;
		if(mp.find(a[i] +1) != mp.end()){
			x = mp[a[i]+1];
			sub += x*(a[i]+1);
			nsub += x;
		}
		if(mp.find(a[i] ) != mp.end()){
			x = mp[a[i]];
			sub += x*(a[i]);
			nsub += x;
		}
		if(mp.find(a[i] -1) != mp.end()){
			x = mp[a[i]-1];
			sub += x*(a[i]-1);
			nsub += x;
		}
		nsub = n-1-i-nsub;
		sub = sum-sub;
		ans += sub - nsub*a[i];
		// ans1 += x/mod;
		// ans2 += x%mod;
		// ans1 += ans2/mod;
		// ans2  = ans2 %mod;
		mp[a[i]]++;
		sum += a[i];
	}
	// long double z = (long double)ans1*(long double)mod + (long double)ans2;
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define S second
#define F first
#define MP make_pair
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define endl '\n'

const ll mod = 1e9;

// vector<ll> segtree;
// vector<ll> a;

// void createTree(ll lo, ll hi, ll pos){
// 	if(lo == hi){
// 		segtree[pos] = a[lo];
// 		return;
// 	}
// 	ll mid = (lo + hi)/2;
// 	createTree(lo, mid, 2*pos + 1);
// 	createTree(mid+1, hi, 2*pos + 2);
// 	segtree[pos] = min(segtree[2*pos+1], segtree[2*pos+2]);
// 	return;
// }

// ll rangeQuery(ll qlo, ll qhi, ll lo, ll hi, ll pos){
// 	if(lo > qhi || hi < qlo){
// 		return LLONG_MAX;
// 	}
// 	if(lo >= qlo && hi <= qhi){
// 		return segtree[pos];
// 	}
// 	ll mid = (hi + lo)/2;
// 	return min(rangeQuery(qlo,qhi,lo,mid,2*pos + 1), rangeQuery(qlo, qhi, mid+1, hi, 2*pos+2));
// }

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	f(i,0,n,1){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll sum=0;
	map<ll,ll> mp;
	mp[a[n-1]] = 1;
	sum += a[n-1];
	ll ans1 = 0, ans2 = 0;
	f(i,n-2,-1,-1){
		ll sub = 0, nsub = 0;
		ll x;
		if(mp.find(a[i] +1) != mp.end()){
			x = mp[a[i]+1];
			sub += x*(a[i]+1);
			nsub += x;
		}
		if(mp.find(a[i] ) != mp.end()){
			x = mp[a[i]];
			sub += x*(a[i]);
			nsub += x;
		}
		if(mp.find(a[i] -1) != mp.end()){
			x = mp[a[i]-1];
			sub += x*(a[i]-1);
			nsub += x;
		}
		nsub = n-1-i-nsub;
		sub = sum-sub;
		x = sub - nsub*a[i];
		ans1 += x/mod;
		ans2 += x%mod;
		ans1 += ans2/mod;
		ans2 = ans2%mod;
		mp[a[i]]++;
		sum += a[i];
	}
	cout<<ans1*mod + ans2<<endl;
}