#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+1e4;
ll n,a[N],b[N],ans,maxn;
signed main()
{
cin>>n;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
b[a[i]]++;
maxn=max(maxn,a[i]);
}
for(ll i=0;i<=maxn;i++)
{
ans+=(b[i]*b[i+1]);//若值为i的数有b[i]个,值为i+1的数有b[i+1],则ans+=(b[i]*b[i+1])(组合)
}
cout<<ans;
}