//#define _CRT_DISABLE_PERFCRIT_LOCKS

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define forn(m,n) for (int i=m; i<n; i++)
#define form(k,m) for (int j=k; j<m; j++)
//#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main() { //opt
    int n, m, *a, l;
    cin >> n >> m;
    a = new int[n];
    static int c[10001], d[10001];
    forn(0,n) {
        cin >> a[i];
        c[a[i]]++;
    }
    forn(1,10001) if (c[i]) d[0]++;
    forn(1,n) {
        d[i] = d[i-1];
        c[a[i]]--;
        if (c[a[i]] == 0) d[i]--;
    }
    form(0,m) {
        cin >> l;
        cout << d[--l] << "\n";
    }
    return 0;
}


//#define _CRT_DISABLE_PERFCRIT_LOCKS

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define forn(m,n) for (int i=m; i<n; i++)
#define form(k,m) for (int j=k; j<m; j++)
//#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main() { //opt
    int n, m, *a, l;
    cin >> n >> m;
    a = new int[n];
    int c[100001] = {0}, d[100001] = {0};
    forn(0,n) {
        cin >> a[i];
        c[a[i]]++;
    }
    forn(1,100001) if (c[i]) d[0]++;
    forn(1,n) {
        d[i] = d[i-1];
        c[a[i-1]]--;
        if (c[a[i]] == 0) d[i]--;
    }
    form(0,m) {
        cin >> l;
        cout << d[--l] << "\n";
    }
    return 0;
}


//#define _CRT_DISABLE_PERFCRIT_LOCKS

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define forn(m,n) for (int i=m; i<n; i++)
#define form(k,m) for (int j=k; j<m; j++)
//#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main() { //opt
    int n, m, *a, l;
    cin >> n >> m;
    a = new int[n];
    int c[100001] = {0}, d[100001] = {0};
    forn(0,n) {
        cin >> a[i];
        c[a[i]]++;
    }
    forn(1,100001) if (c[i]) d[0]++;
    forn(1,n) {
        d[i] = d[i-1];
        c[a[i]]--;
        if (c[a[i]] == 0) d[i]--;
    }
    form(0,m) {
        cin >> l;
        cout << d[--l] << "\n";
    }
    return 0;
}


#define _CRT_DISABLE_PERFCRIT_LOCKS

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define forn(m,n) for (int i=m; i<n; i++)
#define form(k,m) for (int j=k; j<m; j++)
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main() { opt
    int n, m, *a, l;
    cin >> n >> m;
    a = new int[n];
    static int c[10001], d[10001];
    forn(0,n) {
        cin >> a[i];
        c[a[i]]++;
    }
    forn(1,10001) if (c[i]) d[0]++;
    forn(1,n) {
        d[i] = d[i-1];
        c[a[i]]--;
        if (c[a[i]] == 0) d[i]--;
    }
    form(0,m) {
        cin >> l;
        cout << d[--l] << "\n";
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#define MAX 100001
int g[MAX],diff[MAX],mp[MAX];
int main(){
    memset(mp,0,sizeof(mp));
    int n,m,k,x;
    scanf("%d%d",&n,&m);
    for(k=0;k<n;k++)scanf("%d",g+k);
    diff[n-1] = 1;
    for(k=n-2;k>=0;k--){
        diff[k] = diff[k+1]+((mp[g[k]])?0:1);
        mp[g[k]]++;
    }
    //for(k=0;k<n;k++)printf("%d ",diff[k]);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100001
int g[MAX],diff[MAX],mp[MAX];
int main(){
    memset(diff,0,sizeof(diff));
    memset(mp,0,sizeof(mp));
    int n,m,k,x;
    scanf("%d%d",&n,&m);
    for(k=0;k<n;k++)scanf("%d",g+k);
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--){
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    }
   // for(k=0;k<n;k++)printf("%d ",diff[k]);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100001
#include<iostream>
using namespace std;
int g[MAX],diff[MAX],mp[MAX];
int main(){
    cin.sync_with_stdio(false);
  //  cout.sync_with_stdio(false);
    int n,m,k,x;
   // scanf("%d%d",&n,&m);
    cin>>n>>m;
    for(k=0;k<n;k++){//scanf("%d",g+k),mp[g[k]]=0;
        cin>>g[k];mp[g[k]]=0;
    }
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
//        cout<<diff[x-1]<<endl;
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100001
int g[MAX],diff[MAX],mp[MAX];
int main(){
    int n,m,k,x;
    scanf("%d%d",&n,&m);
    for(k=0;k<n;k++)scanf("%d",g+k),mp[g[k]]=0;
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100001
#include<iostream>
using namespace std;
int g[MAX],diff[MAX],mp[MAX];
int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n,m,k,x;
   // scanf("%d%d",&n,&m);
    cin>>n>>m;
    for(k=0;k<n;k++){//scanf("%d",g+k),mp[g[k]]=0;
        cin>>g[k];mp[g[k]]=0;
    }
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
//        printf("%d\n",diff[x-1]);
        cout<<diff[x-1]<<endl;
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100001
#include<iostream>
using namespace std;
int g[MAX],diff[MAX],mp[MAX];
int main(){
 //   cin.sync_with_stdio(false);
  //  cout.sync_with_stdio(false);
    int n,m,k,x;
   // scanf("%d%d",&n,&m);
    cin>>n>>m;
    for(k=0;k<n;k++){//scanf("%d",g+k),mp[g[k]]=0;
        cin>>g[k];mp[g[k]]=0;
    }
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
//        printf("%d\n",diff[x-1]);
        cout<<diff[x-1]<<endl;
    }
return 0;}


#include<stdio.h>
#include<string.h>
#define MAX 100002
int g[MAX],diff[MAX],mp[MAX];
int main(){
    int n,m,k,x;
    memset(mp,0,sizeof(mp));
    scanf("%d%d",&n,&m);
    for(k=0;k<n;k++)scanf("%d",g+k);
    for(k=n-1;k>=0;k--){
        diff[k]=diff[k+1];
        if(!(mp[g[k]]++))diff[k]++;
    }
//        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
    }
return 0;
}


#include<stdio.h>
#include<string.h>
#define MAX 100002
int g[MAX],diff[MAX],mp[MAX];
int main(){
    int n,m,k,x;
    memset(mp,0,sizeof(mp));
    scanf("%d%d",&n,&m);
    for(k=0;k<n;k++)scanf("%d",g+k);
    for(k=n-1;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
        scanf("%d",&x);
        printf("%d\n",diff[x-1]);
    }
return 0;
}


#include<stdio.h>
#include<string.h>
#define MAX 10000
#define gc getchar
#include<iostream>
using namespace std;
void read(int &x){
    x=0; int register c = gc();
    for(;c>57||c<48;c=gc());
    for(;c>=48 && c<=57;c=gc()){x=(x<<3)+(x<<1)+c-48;}
}
int g[MAX],diff[MAX],mp[MAX];
int main(){
    int n,m,k,x;
   // scanf("%d%d",&n,&m);
    read(n);read(m);
    for(k=0;k<n;k++){//scanf("%d",g+k),mp[g[k]]=0;
//        cin>>g[k];
        read(g[k]);
        mp[g[k]]=0;
    }
    diff[n-1] = 1;mp[g[n-1]]++;
    for(k=n-2;k>=0;k--)
        diff[k] = diff[k+1]+((mp[g[k]]++)?0:1);
    for(k=0;k<m;k++){
//        scanf("%d",&x);
        read(x);
        printf("%d\n",diff[x-1]);
//        cout<<diff[x-1]<<endl;
    }
return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int a[10005];
bool t[10005];
int ans[10005];
int main()
{
    int n,q,ask;
    while(scanf("%d%d",&n,&q)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            t[a[i]]=true;
        }
        int sum=0;
        for(int i=n-1;i>=0;i--)
        {
            if(t[a[i]])
            {
                sum++;
                t[a[i]]=false;
            }
            ans[i]=sum;
        }
        while(q--)
        {
            scanf("%d",&ask);
            printf("%d\n",ans[ask-1]);
        }
    }
    return 0;
}
/*2018-05-08 18:22:53.816*/


#include<stdio.h>
#include<set>
#include<string.h>
using namespace std;
int main ()
{
    int a[10005],dp[10005],q,n,ai,i;
    set<int>cunt;
    memset(dp,0,sizeof(dp));
    scanf("%d%d",&n,&q);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=n;i>0;i--)
    {
        if(cunt.count(a[i])==0)
        {
            dp[i]=dp[i+1]+1;
            cunt.insert(a[i]);
        }
        else dp[i]=dp[i+1];
    }
    while(q--)
    {
        scanf("%d",&ai);
        printf("%d\n",dp[ai]);
    }
    return 0;
}
/*2017-08-11 11:38:10.075*/


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[100005],c[100005]={0};
bool b[100005]={0};
int main(void)
{
    int q,i,n,m,k,j,num,ans,t;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    ans=0;
    for(i=n;i>=1;i--)
    {
        if(b[a[i]]==0)
        ans++;
        b[a[i]]=1;
        c[i]=ans;
    }
    while(q--)
    {
        ans=0;
        t=0;
        scanf("%d",&num);
        //memset(b,0,sizeof(b));
        printf("%d\n",c[num]);
    }
    return 0;
}/*2016-08-06 20:37:12.97*/


#include<stdio.h>
#include<math.h>
int main()
{
double a;
while(scanf("%lf",&a)!=EOF)
printf("%.2lf\n",fabs(a));
return 0;
}/*2018-03-24 14:14:52.261*/


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<cstdio>
int main()
{
    int n,m,i,j;
    int a[100006];
    int ans[100006];
    bool t[100006];
    scanf("%d %d",&n,&m);
    int sum=0;
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        t[a[i]]=true;
    }
    for(j=n-1; j>=0; j--)
    {
        if(t[a[j]])
        {
            sum++;
            t[a[j]]=false;
        }
        ans[j]=sum;
    }
    int k;
    while(m--)
    {
        scanf("%d",&k);
        printf("%d\n",ans[k-1]);
    }
    return 0;
}
/*2017-03-29 15:57:50.105*/


#include<stdio.h>
const int maxn = 1e5+5;
int a[maxn];
int ans[maxn];
bool vis[maxn];
int main()
{
    int n, q, k;
    scanf("%d%d",&n,&q);
    for(int i = 1; i <= n; i++)
        scanf("%d",a+i);
    int dif = 0;
    for(int i = n; i > 0; i--)
    {
        if(!vis[a[i]])
        {
            vis[a[i]] = 1;
            dif++;
        }
        ans[i] = dif;
    }
    while(q--)
    {
        scanf("%d",&k);
        printf("%d\n",ans[k]);
    }
    return 0;
}
/*2018-07-27 13:35:26.385*/


#include<stdio.h>

int a[100002];
int b[100002];
int data[100002],di=0;

int quir(int obj)
{
    int bResult=1;
    if(di==0)
    {
        data[di++]=obj;
        return 0;
    }
    for(int i=0;i<di;i++)
    {
        if(data[i]==obj)
        {
            bResult = 0;
            break;
        }
    }
    if(bResult)data[di++]=obj;
    return bResult;
}

int deal(int n)
{
    int i=n-1;
    b[i]=1;quir(a[i]);
    for(--i;i>=0;i--)
    {
        if(quir(a[i]))
            b[i]=b[i+1]+1;
        else b[i]=b[i+1];
    }
}

int main()
{
    int q,n,i,t;
    scanf("%d%d",&n,&q);
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    deal(n);
    for(i=0;i<q;i++)
    {
        scanf("%d",&t);
        printf("%d\n",b[t-1]);
    }
    return 0;
}
/*2017-02-18 20:27:02.148*/


#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>

using namespace std;

#define FOU(i,x,y) for(int i=x;i<=y;i++)
#define FOD(i,x,y) for(int i=x;i>=y;i--)
#define MEM(a,val) memset(a,val,sizeof(a))
#define PI acos(-1.0)

const double EXP = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll MINF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const int N = 1e5+5;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    std::ios::sync_with_stdio(false);
    int n,q;
    int cnt[N];
    int a[N];
    int sum[N],x;
    while(~scanf("%d%d",&n,&q))
    {
        MEM(cnt,0);
        MEM(sum,0);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sum[n+1]=0;
        for(int i=n;i>=1;i--)
        {
            cnt[a[i]]++;
            if(cnt[a[i]]==1)
            {
                sum[i]=sum[i+1]+1;
            }
            else
            {
                sum[i]=sum[i+1];
            }
        }
        while(q--)
        {
            scanf("%d",&x);
            printf("%d\n",sum[x]);
        }
    }
    return 0;
}
/*2018-01-31 16:34:21.566*/


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6;
int a[maxn],num[maxn];
set<int> st;
int main()
{
    int n,q,v;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&num[i]);
    }
    for(int i=n;i>=1;i--){
        st.insert(num[i]);
        a[i]=st.size();
    }
    while(q--){
        scanf("%d",&v);
        printf("%d\n",a[v]);
    }

    return 0;
}
/*2018-02-22 19:09:13.203*/


#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int a[100005];
bool t[100005];
int ans[100005];
int main()
{
    int n,q;
    while(scanf("%d%d",&n,&q)==2&&n&&q)
    {
        int ask,sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            t[a[i]]=true;
        }
        for(int i=n-1;i>=0;i--)
        {
            if(t[a[i]])
            {
                sum++;
                t[a[i]]=false;
            }
            ans[i]=sum;
        }
        while(q--)
        {
            scanf("%d",&ask);
            printf("%d\n",ans[ask-1]);
        }
    }
    return 0;
}
/*2018-05-08 18:31:03.003*/


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
map <ull,ull> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	ull ans=0;
	ull x;
	for(ull i=0;i<n;i++)
	{
		scanf("%llu",&x);
		m[x]++;
		ans=ans+m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	printf("%llu",ans);
}


#include<bits/stdc++.h>
#define lb long double
using namespace std;
map <double,double> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	lb ans=0;
	double x;
	for(lb i=0;i<n;i++)
	{
		scanf("%lf",&x);
		m[x]++;
		ans=ans+m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define lb long double
using namespace std;
map <lb,lb> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	lb ans=0,x;
	for(lb i=0;i<n;i++)
	{
		cin>>x;
		m[x]++;
		ans+=m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define lb long double
using namespace std;
map <double,double> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	lb ans=0;
	double x;
	for(lb i=0;i<n;i++)
	{
		scanf("%lf",&x);
		m[x]++;
		ans=ans+m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	printf("%.0Lf",ans);
}


#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
map <ull,ull> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	ull ans=0;
	ull x;
	for(ull i=0;i<n;i++)
	{
		cin>>x;
		m[x]++;
		ans=ans+m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define lb long double
using namespace std;
map <lb,lb> m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	scanf("%d",&n);
	lb ans=0,x;
	for(lb i=0;i<n;i++)
	{
		cin>>x;
		m[x]++;
		ans+=m[x+1]-m[x-1]+x*(i+1-n+i);
	}
	printf("%.0lf",ans);
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long int  n,s,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<1)
		s=0;
		else
			s=a[j]-a[i];
		s+=s;
	}
}
cout<<s;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int ans, sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
 ans=0;
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

		ans=ans+a[i];
	}
    sum=sum+(ii-1)*a[ii]-ans-m;
   }
   cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int  n,s,t,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<=1){
			s=0;}
		else
			{s=a[j]-a[i];
		}
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int  n,s,t,a[200000];
	long long int sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<=1){
			s=0;}
		else
			{s=a[j]-a[i];
		}
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{

    cin >>a[1];

sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
	    cin>>a[j]
		t=a[j]-a[i];
		s=abs(t);
		s=((t*(s-1))/((s-1)-0.1));
		sum=sum+s;

	}
}
	cout<<sum;
return 0;

}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
    a[0]=a[1];
	for(int i=ii;i>0;i--){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
	for(int i=ii;i>0;i--){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  n,s,s1,sum,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		s=t*t;
		s1=((t*(s-1))/((s-1)-0.1));
		sum=sum+s1;
	}
}
	cout<<sum;
return 0;

}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "almost differance", "almost differance\almost differance.vcxproj", "{05AE346E-BADC-4FFA-BCE0-5FBFBC9F1AE7}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{05AE346E-BADC-4FFA-BCE0-5FBFBC9F1AE7}.Debug|Win32.ActiveCfg = Debug|Win32
		{05AE346E-BADC-4FFA-BCE0-5FBFBC9F1AE7}.Debug|Win32.Build.0 = Debug|Win32
		{05AE346E-BADC-4FFA-BCE0-5FBFBC9F1AE7}.Release|Win32.ActiveCfg = Release|Win32
		{05AE346E-BADC-4FFA-BCE0-5FBFBC9F1AE7}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
	for(int i=ii-1;i>0;i--){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int  n,s,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	s=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t>1)
			s+=a[j]-a[i];
	}
}
cout<<s;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
	sum=0;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
   if(z<=2){

	for(int i=1;i<z;i++){
		t=a[z]-a[i];
		t=((t*(abs(t)-1))/((abs(t)-1)-0.1));
		sum=sum+t;
	}

   }
}

	cout<<sum;
return 0;

}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
    int i=1;
	while(i<ii){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}
	i++;
	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
if(ii>1){
    m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
}
}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=(n-1)*a[n]+sum-(n-1)*a[1]
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
    int i=1;
	while(i<ii){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}
	i++;
	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int ans, sum,t,a[200000];
	 int n,l,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
 ans=0;
m=0;
l=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	l=l+1;
	}

		ans=ans+a[i];
	}
    sum=sum+ans-m+l;
   }
   cout<<sum;
return 0;
}


By fireworkes, contest: Educational Codeforces Round 34 (Rated for Div. 2), problem: (D) Almost Difference, Wrong answer on test 1, #
 #include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
	sum=0;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
   if(z>=2){

	for(int i=1;i<z;i++){

		t=a[z]-a[i];
		if(abs(t)==1){
		    t=0;
		}
		sum=sum+t;
	}

   }
}

	cout<<sum;
return 0;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long int  n,s,t,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<=1){
			s=0;}
		else
			{s=a[j]-a[i];
		}
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
	sum=0;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
   if(z>=2){

	for(int i=1;i<z;i++){
		t=a[z]-a[i];
		t=((t*(abs(t)-1))/((abs(t)-1)-0.1));
		sum=sum+t;
	}

   }
}

	cout<<sum;
return 0;

}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		t=((t*(abs(t)-1))/((abs(t)-1)-0.1));
		sum=sum+t;
	}
}
	cout<<sum;
return 0;

}


#include <bits/stdc++.h>
 long long a [210000];
 long  double ans;
using namespace std;

int n;
int main(){
    //scanf("%d",&n);
    map<long long, long long> mp;
    for(int i = 1; i <= n; i ++)
    ans = 0;
    for(int i = 1; i <= n; i ++){
        ans += (2*i-1-n) * a[i] + mp[a[i] + 1] - mp[a[i] - 1];
        mp[a[i]] ++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int  n,s,t,a[200000],sum;
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t>1)
		s=a[j]-a[i];
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m-1;
	}
	else if((a[ii]-a[i])==-1){
	m=m+1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=sum-(n-1)*a[1]
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=(n-1)*a[n]+sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  n,s,sum,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		s=((t*(abs(t)-1))/((abs(t)-1)-0.1));
		sum=sum+s;
	}
}
	cout<<sum;
return 0;

}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
	sum=0;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
   if(z<=2){

	for(int i=1;i<z;i++){

		t=a[z]-a[i];
		if(abs(t)==1){
		    t=0;
		}
		sum=sum+t;
	}

   }
}

	cout<<sum;
return 0;

}


#include <bits/stdc++.h>
#define LL long long
#define ld long  double
using namespace std;

int n;
LL a[210000];

int main(){
    scanf("%d",&n);
    map<LL, LL> mp;
    for(int i = 1; i <= n; i ++) scanf("%lld",&a[i]);
    ld ans = 0;
    for(int i = 1; i <= n; i ++){
        ans += (2*i-1-n) * a[i] + mp[a[i] + 1] - mp[a[i] - 1];
        mp[a[i]] ++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  n,s,s1,sum,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		s=abs(t);
		s1=((t*(s-1))/((s-1)-0.1));
		sum=sum+s1;
	}
}
	cout<<sum;
return 0;

}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  n,s,sum,t,a[200000];
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
sum=0;

for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		s=abs(t);
		s=((t*(s-1))/((s-1)-0.1));
		sum=sum+s;

	}
}
	cout<<sum;
return 0;

}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200000];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m-1;
	}
	else if((a[ii]-a[i])==-1){
	m=m+1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
    int i=1
	while(i<ii){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}
	i++
	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int ans, sum,t,a[200000];
	 int n,l,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
 ans=0;
m=0;
l=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	l=l+1;
	}

		ans=ans+a[i];
	}
    sum=sum+(ii-1)*a[ii]-ans-m+l;
   }
   cout<<sum;
return 0;


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	signed long  int  n,s,t,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<=1){
			s=0;}
		else
			{s=a[j]-a[i];
		}
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	signed long long  int  n,s,t,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		if (abs(a[i]-a[j])<=1)
			s=0;
		else
			s=a[j]-a[i];

		sum=+s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m-1;
	}
	else if((a[ii]-a[i])==-1){
	m=m+1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int ans, sum,t,a[200000];
	 int n,l,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
 ans=0;
m=0;
l=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	l=l+1;
	}

		ans=ans+a[i];
	}
    sum=(ii-1)*a[ii]-sum+ans-m+l;
   }
   cout<<sum;
return 0;


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;
	sum=0;
    for (int ii = 1; ii <=n ; ii++) {
    cin >>a[ii];
    m=0;
    a[0]=a[1];
	for(int i=ii-1;i>0;i--){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;

}
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  sum,t,a[200000];
	long int n;
	cin>>n;
	sum=0;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
   if(z>=2){

	for(int i=1;i<z;i++){
		t=a[z]-a[i];
		if(t==1||t==-1){
		    t=0;
		}
		sum=sum+t;
	}

   }
}

	cout<<sum;
return 0;

}


#include<iostream>
using namespace std;
int main()
{
	long long int ans, sum,a[200000];
	 int n,l,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
 ans=0;
m=0;
l=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	l=l+1;
	}

		ans=ans+a[i];
	}
    sum=sum+(ii-1)*a[ii]-ans-m+l;
   }
   cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	signed long long int  n,s,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){

		if (abs(a[i]-a[j])>1)
			s=a[j]-a[i];
		sum+=s;
	}
}
cout<<sum;
return 0;
}


#include <bits/stdc++.h>
 long long a [210000];
 long  double ans;
using namespace std;

int n;
int main(){
    scanf("%d",&n);
    map<long long, long long> mp;
    for(int i = 1; i <= n; i ++) scanf("%lld",&a[i]);
    ans = 0;
    for(int i = 1; i <= n; i ++){
        ans += (2*i-1-n) * a[i] + mp[a[i] + 1] - mp[a[i] - 1];
        mp[a[i]] ++;
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	signed long  int  n,s,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){

		if (abs(a[i]-a[j])<=1)
			s=0;
		else
			s=a[j]-a[i];
		sum+=s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int  n,s,sum,t,a[200000];
	cin>>n;
	sum=0;
   int z = 1;
        for(int k=2;k<=n;k++ ){
    cin >>a[k];
    t=a[k]-a[1];
		s=abs(t);
		s=((t*(s-1))/((s-1)-0.1));
		sum=sum+s;
}

for(int i=2;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=a[j]-a[i];
		s=abs(t);
		s=((t*(s-1))/((s-1)-0.1));
		sum=sum+s;

	}
}
	cout<<sum;
return 0;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int  n,s,t,a[200000];

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	s=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<=1)
			s=0;
		else
			s=s+a[j]-a[i];

	}
}
cout<<s;
return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ld long  double
using namespace std;

int n;
LL a[210000];

int main(){
    scanf("%d",&n);
    map<LL, LL> mp;
    for(int i = 0; i < n; i ++) scanf("%lld",&a[i]);
    ld ans = 0, sum = 0;
    for(int i = 0; i < n; i ++){
        ans += i * a[i] - sum + mp[a[i] + 1] - mp[a[i] - 1];
        mp[a[i]] ++;
        sum += a[i];
    }
    cout << fixed << setprecision(0) << ans << endl;
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	signed long long int  n,s,a[200000],sum;
	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){

		if (abs(a[i]-a[j])<=1)
			s=0;
		else
			s=a[j]-a[i];
		sum+=s;
	}
}
cout<<sum;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int  sum,a[200001];
	 int n,m;
	cin>>n;

    for (int z = 1; z <=n ; z++) {
    cin >>a[z];

}
sum=0;
for(int ii=2;ii<=n;ii++){
m=0;
	for(int i=1;i<ii;i++){
	if((a[ii]-a[i])==1){
	 m=m+1;
	}
	else if((a[ii]-a[i])==-1){
	m=m-1;
	}

	}
    sum=sum+(2*ii-1-n)*a[ii]-m;
   }
   sum=sum-(n-1)*a[1];
   cout<<sum;
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long int  n,s,t,a[200000],sum;

	cin>>n;
    for (int z = 1; z <=n ; z++) {
    cin >>a[z];
}
	sum=0;
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t=abs(a[i]-a[j]);
		if (t<1)
		s=0;
		else
			s=a[j]-a[i];
		sum=sum+s;
	}
}
cout<<sum;
return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n;
unsigned ll ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return get(1000000000) - get(x + 1); }
ll cntg(ll x) { return teg(1000000000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += ((unsigned ll)x * cnts(x) - sums(x)) + ((unsigned ll)x * cntg(x) - sumg(x));
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, sum, cur;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  f.max_load_factor(0.25);f.reserve(512);
  z.max_load_factor(0.25);z.reserve(512);
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n;
ld ans;
struct chash {
  unsigned operator()(int x) const {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
  }
};
gp_hash_table<ll, ll, chash> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return get(1000000000) - get(x + 1); }
ll cntg(ll x) { return teg(1000000000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
struct chash {
  const int RANDOM =
      (long long)(make_unique<char>().get()) ^
      chrono::high_resolution_clock::now().time_since_epoch().count();
  static unsigned long long hash_f(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
  int operator()(int x) const { return hash_f(x) ^ RANDOM; }
};
struct fen {
  ll g[40]={};
  gp_hash_table<int, ll, chash> f;
  ll teg(int v) {
    ll r = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) r += g[v];
    return r;
  }
  ll get(int v) {
    if (!v) return 0;
    ll r = 0, u = pc(v) - 1;
    while (u--) r += f[v], v -= (v & -v);
    return r + teg(__lg(v));
  }
  void dpu(int v, int x) {
    for (; v <= 30; v |= (v + 1)) g[v] += x;
  }
  void upd(int v, int x) {
    while (pc(v) > 1) f[v] += x, v += (v & -v);
    dpu(__lg(v), x);
  }
};
ll n, sum, cur;
ld ans;
fen f, s;
ll sumg(ll x) { return sum - f.get(x + 1); }
ll cntg(ll x) { return cur - s.get(x + 1); }
ll sums(ll x) { return f.get(x - 2); }
ll cnts(ll x) { return s.get(x - 2); }
void add(ll x) {
  f.upd(x, x);
  s.upd(x, 1);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n, sum, cur;
ld ans;
const ll TIME = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll SEED = (ll)(new ll);
const ll RANDOM = TIME ^ SEED;
const ll MOD = (int)1e9+7;
const ll MUL = (int)1e6+3;

struct chash{
    ll operator()(ll x) const { return std::hash<ll>{}((x ^ RANDOM) % MOD * MUL); }
};

gp_hash_table<int, ll, chash> f;
gp_hash_table<int, int, chash> z;
ll get(int x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(int x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
int teg(int x) {
  int y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(int x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n, sum, cur;
ld ans;
struct chash {
  unsigned operator()(int x) const {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
  }
};
gp_hash_table<int, ll, chash> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, a[800005], f[800005], z[800005];
vector<ll> b;
ld ans;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x, ll y) {
  for (; x <= 800000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 800000; x += (x & -x)) z[x]++;
}
ll comp(ll x) { return lower_bound(all(b), x) - b.begin() + 1; }
ll sumg(ll x) { return get(500000) - get(x + 1); }
ll cntg(ll x) { return teg(500000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x, ll y) {
  upd(x, a[y]);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) cin >> a[i], b.pb(a[i] - 1), b.pb(a[i]), b.pb(a[i] + 1);
  sort(all(b));
  b.erase(unique(all(b)), b.end());
  forn(n) {
    ll x = comp(a[i]);
    ans += (a[i] * cnts(x) - sums(x)) + (a[i] * cntg(x) - sumg(x));
    add(x, i);
  }
  cout << ans;
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return get(1000000000) - get(x + 1); }
ll cntg(ll x) { return teg(1000000000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, sum, cur;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  f.max_load_factor(0.7);f.reserve(512);
  z.max_load_factor(0.7);z.reserve(512);
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
struct chash {
  const int RANDOM =
      (long long)(make_unique<char>().get()) ^
      chrono::high_resolution_clock::now().time_since_epoch().count();
  static unsigned long long hash_f(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
  int operator()(int x) const { return hash_f(x) ^ RANDOM; }
};
struct fen {
  ll g[40]={};
  map<int, ll, chash> f;
  ll teg(int v) {
    ll r = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) r += g[v];
    return r;
  }
  ll get(int v) {
    if (!v) return 0;
    ll r = 0, u = pc(v) - 1;
    while (u--) r += f[v], v -= (v & -v);
    return r + teg(__lg(v));
  }
  void dpu(int v, int x) {
    for (; v <= 30; v |= (v + 1)) g[v] += x;
  }
  void upd(int v, int x) {
    while (pc(v) > 1) f[v] += x, v += (v & -v);
    dpu(__lg(v), x);
  }
};
ll n, sum, cur;
ld ans;
fen f, s;
ll sumg(ll x) { return sum - f.get(x + 1); }
ll cntg(ll x) { return cur - s.get(x + 1); }
ll sums(ll x) { return f.get(x - 2); }
ll cnts(ll x) { return s.get(x - 2); }
void add(ll x) {
  f.upd(x, x);
  s.upd(x, 1);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
struct chash {
  const int RANDOM =
      (long long)(make_unique<char>().get()) ^
      chrono::high_resolution_clock::now().time_since_epoch().count();
  static unsigned long long hash_f(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
  int operator()(int x) const { return hash_f(x) ^ RANDOM; }
};
struct fen {
  ll g[40]={};
  cc_hash_table<int, ll, chash> f;
  ll teg(int v) {
    ll r = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) r += g[v];
    return r;
  }
  ll get(int v) {
    if (!v) return 0;
    ll r = 0, u = pc(v) - 1;
    while (u--) r += f[v], v -= (v & -v);
    return r + teg(__lg(v));
  }
  void dpu(int v, int x) {
    for (; v <= 30; v |= (v + 1)) g[v] += x;
  }
  void upd(int v, int x) {
    while (pc(v) > 1) f[v] += x, v += (v & -v);
    dpu(__lg(v), x);
  }
};
ll n, sum, cur;
ld ans;
fen f, s;
ll sumg(ll x) { return sum - f.get(x + 1); }
ll cntg(ll x) { return cur - s.get(x + 1); }
ll sums(ll x) { return f.get(x - 2); }
ll cnts(ll x) { return s.get(x - 2); }
void add(ll x) {
  f.upd(x, x);
  s.upd(x, 1);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, sum, cur;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  f.max_load_factor(0.5);f.reserve(512);
  z.max_load_factor(0.5);z.reserve(512);
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n, sum, cur;
ld ans;
struct chash {
  unsigned operator()(int x) const {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
  }
};
gp_hash_table<int, ll, chash> f;
gp_hash_table<int, int, chash> z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
int teg(ll x) {
  int y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
struct chash {
  const int RANDOM =
      (long long)(make_unique<char>().get()) ^
      chrono::high_resolution_clock::now().time_since_epoch().count();
  static unsigned long long hash_f(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
  int operator()(int x) const { return hash_f(x) ^ RANDOM; }
};
struct fen {
  ll g[40]={};
  unordered_map<int, ll, chash> f;
  ll teg(int v) {
    ll r = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) r += g[v];
    return r;
  }
  ll get(int v) {
    if (!v) return 0;
    ll r = 0, u = pc(v) - 1;
    while (u--) r += f[v], v -= (v & -v);
    return r + teg(__lg(v));
  }
  void dpu(int v, int x) {
    for (; v <= 30; v |= (v + 1)) g[v] += x;
  }
  void upd(int v, int x) {
    while (pc(v) > 1) f[v] += x, v += (v & -v);
    dpu(__lg(v), x);
  }
};
ll n, sum, cur;
ld ans;
fen f, s;
ll sumg(ll x) { return sum - f.get(x + 1); }
ll cntg(ll x) { return cur - s.get(x + 1); }
ll sums(ll x) { return f.get(x - 2); }
ll cnts(ll x) { return s.get(x - 2); }
void add(ll x) {
  f.upd(x, x);
  s.upd(x, 1);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n, sum, cur;
ld ans;
struct chash {
  unsigned operator()(int x) const {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
  }
};
cc_hash_table<int, ll, chash> f;
cc_hash_table<int, int, chash> z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
int teg(ll x) {
  int y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, sum, cur;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  f.max_load_factor(0.5);f.reserve(2048);
  z.max_load_factor(0.5);z.reserve(2048);
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n;
ld ans;
struct chash {
  unsigned operator()(int x) const {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
  }
};
gp_hash_table<int, ll, chash> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return get(1000000000) - get(x + 1); }
ll cntg(ll x) { return teg(1000000000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, sum, cur;
ld ans;
unordered_map<ll, ll> f, z;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
struct chash {
  const int RANDOM =
      (long long)(make_unique<char>().get()) ^
      chrono::high_resolution_clock::now().time_since_epoch().count();
  static unsigned long long hash_f(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
  int operator()(int x) const { return hash_f(x) ^ RANDOM; }
};
struct fen {
  ll g[40]={};
  map<int, ll> f;
  ll teg(int v) {
    ll r = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) r += g[v];
    return r;
  }
  ll get(int v) {
    if (!v) return 0;
    ll r = 0, u = pc(v) - 1;
    while (u--) r += f[v], v -= (v & -v);
    return r + teg(__lg(v));
  }
  void dpu(int v, int x) {
    for (; v <= 30; v |= (v + 1)) g[v] += x;
  }
  void upd(int v, int x) {
    while (pc(v) > 1) f[v] += x, v += (v & -v);
    dpu(__lg(v), x);
  }
};
ll n, sum, cur;
ld ans;
fen f, s;
ll sumg(ll x) { return sum - f.get(x + 1); }
ll cntg(ll x) { return cur - s.get(x + 1); }
ll sums(ll x) { return f.get(x - 2); }
ll cnts(ll x) { return s.get(x - 2); }
void add(ll x) {
  f.upd(x, x);
  s.upd(x, 1);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
ll n, sum, cur;
ld ans;
const ll TIME = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll SEED = (ll)(new ll);
const ll RANDOM = TIME ^ SEED;
const ll MOD = (int)1e9+7;
const ll MUL = (int)1e6+3;

struct chash{
    ll operator()(ll x) const { return std::hash<ll>{}((x ^ RANDOM) % MOD * MUL); }
};

cc_hash_table<int, ll, chash> f;
cc_hash_table<int, int, chash> z;
ll get(int x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(int x) {
  ll y = x;
  for (; x <= 1000000000; x += (x & -x)) f[x] += y;
}
int teg(int x) {
  int y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 1000000000; x += (x & -x)) z[x]++;
}
ll sumg(ll x) { return sum - get(x + 1); }
ll cntg(ll x) { return cur - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(int x) {
  upd(x);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) {
    ll x;
    cin >> x;
    ans += (x * cnts(x) - sums(x)) + (x * cntg(x) - sumg(x));
    sum += x;
    cur++;
    add(x);
  }
  cout << ans << "\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define mp(x, y) make_pair(x, y)
#define F first
#define S second
using namespace std;
ll n, a[800005], f[800005], z[800005];
vector<ll> b;
ld ans;
ll get(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += f[x];
  return y;
}
void upd(ll x, ll y) {
  for (; x <= 800000; x += (x & -x)) f[x] += y;
}
ll teg(ll x) {
  ll y = 0;
  for (; x > 0; x -= (x & -x)) y += z[x];
  return y;
}
void dpu(ll x) {
  for (; x <= 800000; x += (x & -x)) z[x]++;
}
ll comp(ll x) { return lower_bound(all(b), x) - b.begin() + 1; }
ll sumg(ll x) { return get(800000) - get(x + 1); }
ll cntg(ll x) { return teg(800000) - teg(x + 1); }
ll sums(ll x) { return get(x - 2); }
ll cnts(ll x) { return teg(x - 2); }
void add(ll x, ll y) {
  upd(x, a[y]);
  dpu(x);
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n;
  forn(n) cin >> a[i], b.pb(a[i] - 1), b.pb(a[i]), b.pb(a[i] + 1);
  sort(all(b));
  b.erase(unique(all(b)), b.end());
  forn(n) {
    ll x = comp(a[i]);
    ans += (a[i] * cnts(x) - sums(x)) + (a[i] * cntg(x) - sumg(x));
    add(x, i);
  }
  cout << ans;
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[200010];
int n;
ll a[200010], b[200010], sum[200010], ans = 0;
void add(int pos) {
	while(pos <= n) {
		tree[pos]++;
		pos += pos&(-pos);
	}
}
ll ssum(int pos) {
	ll res = 0;
	while(pos) {
		res += tree[pos];
		pos -= pos&(-pos);
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		sum[i] = sum[i-1] + a[i];
		b[i] = a[i];
	}
	sort(b+1, b+1+n);
	b[n+1] = 1e12;
	int p = lower_bound(b+1, b+n+1, a[1])-b;
	add(p);
	for(int i = 2; i <= n; i++) {
		ans += a[i]*(i-1)-sum[i-1];
		p = lower_bound(b+1, b+n+1, a[i]-1)-b;
		if(b[p] == a[i]-1)
		ans -= ssum(p)-ssum(p-1);
		p = lower_bound(b+1, b+n+1, a[i]+1)-b;
		if(b[p] == a[i]+1)
		ans += ssum(p)-ssum(p-1);
		p = lower_bound(b+1, b+n+1, a[i])-b;
		add(p);
	}
	printf("%lld\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll tree[200010];
int n;
ll a[200010], b[200010], sum[200010], ans = 0, c[200010];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		sum[i] = sum[i-1] + a[i];
		b[i] = a[i];
	}
	sort(b+1, b+1+n);
	b[n+1] = 1e12;
	int p = lower_bound(b+1, b+n+1, a[1])-b;
	c[p]++;
	for(int i = 2; i <= n; i++) {
		p = lower_bound(b+1, b+n+1, a[i]-1)-b;
		if(b[p] == a[i]-1)
		ans -= c[p];
		p = lower_bound(b+1, b+n+1, a[i]+1)-b;
		if(b[p] == a[i]+1)
		ans += c[p];
		p = lower_bound(b+1, b+n+1, a[i])-b;
		ans += a[i]*(i-1);
		ans -= sum[i-1];
		c[p]++;
	}
	printf("%lld\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[200010];
int n;
ll a[200010], b[200010], sum[200010], ans = 0;
void add(int pos) {
	while(pos <= n) {
		tree[pos]++;
		pos += pos&(-pos);
	}
}
ll ssum(int pos) {
	ll res = 0;
	while(pos) {
		res += tree[pos];
		pos -= pos&(-pos);
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		sum[i] = sum[i-1] + a[i];
		b[i] = a[i];
	}
	sort(b+1, b+1+n);
	int p = lower_bound(b+1, b+n+1, a[1])-b;
	add(p);
	for(int i = 2; i <= n; i++) {
		ans += a[i]*(i-1)-sum[i-1];
		p = lower_bound(b+1, b+n+1, a[i]-1)-b;
		if(b[p] == a[i]-1)
		ans -= ssum(p)-ssum(p-1);
		p = lower_bound(b+1, b+n+1, a[i]+1)-b;
		if(b[p] == a[i]+1)
		ans += ssum(p)-ssum(p-1);
		p = lower_bound(b+1, b+n+1, a[i])-b;
		add(p);
	}
	printf("%lld\n", ans);
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<list>
#include<queue>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<math.h>
#include<set>
#include<stack>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<iterator>
#include<unordered_map>
using namespace std;
#define ll long long
#define ld long double
#define llu unsigned long long
#define inf 99194853094755497
#define pf printf
#define sf scanf
#define sf1(x) scanf("%lld",&x)
#define sf2(x,y) scanf("%lld %lld",&x,&y)
#define sf3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sf4(x,y,z,w) scanf("%lld %lld %lld %lld",&x,&y,&z,&w)
#define pii pair<long long,long long>
#define sq(x) ((x)*(x))
#define MAX 100009
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define PI acos(-1.0)
const double INF = 1e100;
const double EPS = 1e-9;
/*struct debugger
{
    template<typename T> debugger& operator, (const T& v)
    {
        cerr<<v<<" ";
        return *this;
    }
}dbg;
#define deb(args...){dbg, args; cerr<<endl;}*/

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

template< class T > T gcd(const T a, const T b) { return (b ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(const T a, const T b) { return (a / gcd<T>(a, b) * b); }

///Link List
/*
struct node
{
	int roll;
	node *next, *prev;
};
node *root, *tail;
void append(int roll)
{
	if(root==NULL) ///If the list is empty
	{
		root=new node();
		root->roll=roll;
		root->next=NULL;
		tail=root;
	}
	else
	{
		node *newnode=new node();
		newnode->roll=roll;
		newnode->next=NULL;
		tail->next=newnode; ///add the new node after tail node
		tail=tail->next; ///move tail pointer forward
		///by using tail we can add a new element at O(1) comlexity
	}
}

void delete_node(int roll)
{
	node *current_node=root;
	node *previous_node=NULL;
	while(current_node->roll!=roll) ///Searching node
	{
		previous_node=current_node; ///Save the previous node
		current_node=current_node->next;
	}
	if(current_node==root) ///Delete root
	{
		node *temp=root; ///save root in temporary variable
		root=root->next; ///move root forward
		delete(temp); ///free memory
	}
	else ///delete non-root node
	{
		previous_node->next=current_node->next; ///previous node points the current node's next node
		delete(current_node); ///free current node
	}

}
*/

/*int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
int flip(int N,int pos){return N= N ^ (1<<pos);}
int Least_Significant_Bit(int N){return N= N & (-N);}*/
// moves
//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios_base::sync_with_stdio(0); cin.tie(0);
struct node{
    ll x,y;
    node(){}
    node(ll x,ll y):x(x),y(y){}
    bool operator < (const node & p) const
    {
        return x<p.x;
    }
};
node a[1000000];
unordered_map<int,int>mp;
ll ara[1000000];
void update(ll nod,ll b,ll e,ll i,ll val)
{
    if(b==e && b==i){
        a[nod].x++;
        a[nod].y=a[nod].x*val;
        return;
    }
    ll l,mid;
    mid=(b+e)/2;
    l=2*nod;
    if(i<=mid) update(l,b,mid,i,val);
    else update(l+1,mid+1,e,i,val);
    a[nod].y=a[l].y+a[l+1].y;
    a[nod].x=a[l].x+a[l+1].x;
}

node query(ll nod,ll b,ll e,ll i,ll j)
{
    if(i>j) return node(0,0);
    if(b>j || e<i) return node(0,0);
    if(b>=i && e<=j){
        return a[nod];
    }
    ll l,mid;
    mid=(b+e)/2;
    l=2*nod;
    node x=query(l,b,mid,i,j);
    node y=query(l+1,mid+1,e,i,j);
    return node(x.x+y.x,x.y+y.y);
}
vector<ll>v,v1;

int main()
{
    ll i,j,k,x,y,z,t,m,n,l1,l2;
    int l=0;
    sf1(n);
    mem(a,0);
    for(i=1;i<=n;i++){
        sf1(ara[i]);
        x=ara[i]-2;
        y=ara[i]+2;
        v.pb(ara[i]);
        v.pb(x);
        v.pb(y);
    }
    sort(v.begin(),v.end());
    for(i=0;i<v.size();i++){
        if(mp.count((int)v[i])==0){
            x=(int) v[i];
            mp[x]=++l;
        }
    }
    ll sum=0;
    for(i=n;i>=1;i--){
        update(1,1,n,(ll)mp[ara[i]],ara[i]);
        node p,q;
        p=query(1,1,n,1,(ll)mp[ara[i]-2]);
        q=query(1,1,n,(ll)mp[ara[i]+2],(ll)l);
        sum=sum+(p.y+q.y)-((p.x+q.x)*ara[i]);
    }
    deb(sum);

    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<list>
#include<queue>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<math.h>
#include<set>
#include<stack>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<iterator>
#include<unordered_map>
using namespace std;
#define ll long long
#define ld long double
#define llu unsigned long long
#define inf 99194853094755497
#define pf printf
#define sf scanf
#define sf1(x) scanf("%lld",&x)
#define sf2(x,y) scanf("%lld %lld",&x,&y)
#define sf3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sf4(x,y,z,w) scanf("%lld %lld %lld %lld",&x,&y,&z,&w)
#define pii pair<long long,long long>
#define sq(x) ((x)*(x))
#define MAX 100009
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define PI acos(-1.0)
const double INF = 1e100;
const double EPS = 1e-9;
/*struct debugger
{
    template<typename T> debugger& operator, (const T& v)
    {
        cerr<<v<<" ";
        return *this;
    }
}dbg;
#define deb(args...){dbg, args; cerr<<endl;}*/

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

template< class T > T gcd(const T a, const T b) { return (b ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(const T a, const T b) { return (a / gcd<T>(a, b) * b); }

///Link List
/*
struct node
{
	int roll;
	node *next, *prev;
};
node *root, *tail;
void append(int roll)
{
	if(root==NULL) ///If the list is empty
	{
		root=new node();
		root->roll=roll;
		root->next=NULL;
		tail=root;
	}
	else
	{
		node *newnode=new node();
		newnode->roll=roll;
		newnode->next=NULL;
		tail->next=newnode; ///add the new node after tail node
		tail=tail->next; ///move tail pointer forward
		///by using tail we can add a new element at O(1) comlexity
	}
}

void delete_node(int roll)
{
	node *current_node=root;
	node *previous_node=NULL;
	while(current_node->roll!=roll) ///Searching node
	{
		previous_node=current_node; ///Save the previous node
		current_node=current_node->next;
	}
	if(current_node==root) ///Delete root
	{
		node *temp=root; ///save root in temporary variable
		root=root->next; ///move root forward
		delete(temp); ///free memory
	}
	else ///delete non-root node
	{
		previous_node->next=current_node->next; ///previous node points the current node's next node
		delete(current_node); ///free current node
	}

}
*/

/*int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
int flip(int N,int pos){return N= N ^ (1<<pos);}
int Least_Significant_Bit(int N){return N= N & (-N);}*/
// moves
//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios_base::sync_with_stdio(0); cin.tie(0);
struct node{
    ll x,y;
    node(){}
    node(ll x,ll y):x(x),y(y){}
    bool operator < (const node & p) const
    {
        return x<p.x;
    }
};
node a[1000000];
ll ara[1000000];
void update(ll nod,ll b,ll e,ll i,ll val)
{
    if(b==e && b==i){
        a[nod].x++;
        a[nod].y=a[nod].x*val;
        return;
    }
    ll l,mid;
    mid=(b+e)/2;
    l=2*nod;
    if(i<=mid) update(l,b,mid,i,val);
    else update(l+1,mid+1,e,i,val);
    a[nod].y=a[l].y+a[l+1].y;
    a[nod].x=a[l].x+a[l+1].x;
}

node query(ll nod,ll b,ll e,ll i,ll j)
{
    if(i>j) return node(0,0);
    if(b>j || e<i) return node(0,0);
    if(b>=i && e<=j){
        return a[nod];
    }
    ll l,mid;
    mid=(b+e)/2;
    l=2*nod;
    node x=query(l,b,mid,i,j);
    node y=query(l+1,mid+1,e,i,j);
    return node(x.x+y.x,x.y+y.y);
}
vector<ll>v,v1;

int main()
{
    ll i,j,k,x,y,z,t,m,n,l1,l2;
    int l=0;
    sf1(n);
    mem(a,0);
    for(i=1;i<=n;i++){
        sf1(ara[i]);
        x=ara[i]-2;
        y=ara[i]+2;
        v.pb(ara[i]);
        v.pb(x);
        v.pb(y);
    }
    sort(v.begin(),v.end());
    for(i=1;i<v.size();i++){
        if(v[i]!=v[i-1]){
            v1.pb(v[i]);
        }
    }
    v1.pb(v[v.size()-1]);
    v.clear();
    sort(v1.begin(),v1.end());

    ll sum=0;
    for(i=n;i>=1;i--){
        x=upper_bound(v1.begin(),v1.end(),(ara[i]))-v1.begin();
        update(1,1,n,x,ara[i]);
        node p,q;
        x=upper_bound(v1.begin(),v1.end(),(ara[i]-2))-v1.begin();
        p=query(1,1,n,1,x);
        x=upper_bound(v1.begin(),v1.end(),(ara[i]+2))-v1.begin();
        q=query(1,1,n,x,v1.size());
        sum=sum+(p.y+q.y)-((p.x+q.x)*ara[i]);
    }
    deb(sum);

    return 0;
}