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

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define p push
#define pp pop

#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define Si size()
#define C count()
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define mp make_pair()
typedef long long ll;
#define V(type) vector<type>
#define PQ(type) priority_queue<type>
#define pll pair<ll, ll>
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)

#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n;i>0;i--)


#define mod 1000000007
#define INF 9223372036854775807
const double delta = 0.0000000001;
const double pi = 3.1415926535;

void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
ll fact(ll n)
{
	if(n<2)return 1;
	else return n*fact(n-1);
}
ll xi(ll x,ll y,ll p){            //gives (x^y)%p 
	ll r=1;
	x=x%p;
	while(y>0){
		if(y%2==0){
			x*=x;
			x=x%p;
			y/=2;
		}
	else {
		r=((r%p)*(x%p))%p;
		y--;
	}
	
	}
	return r;
}
ll countBits(ll n) {
	ll count = 0;
	while (n) {
		count++;
		n >>= 1;
	}
	return count;
}

ll isP(ll n) {               //returns 1 if prime
	if (n == 0 || n == 1) return 0;
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) return 0;
	}
	return 1;
}

int main()
{
ll n;
cin>>n;
V(ll) arr(n);
rep(i,n)
{cin>>arr[i];}
ll ans=0;
sort(arr.B,arr.E);
for(ll i=n-1;i>=0;i--)
{
	ans+=((arr[i]*i)-(arr[i]*(n-i-1)));
}
cout<<ans;
return 0;
}
/*
	Auth: Loxilante
	Date: 2021-02-13 20:18:37
	Prog: B.cpp
*/

#define F_C
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int k, m, ans = 0;
	cin>>k>>m;
	if (!m) return cout<<1<<endl, 0;
	if (m == 1) return cout<<1+(k != 0)<<endl, 0;
	if (m == 2) return cout<<2+(k != 0)<<endl, 0;
	if (k > 0)
	{
		int minn = -k-(m-1)/2;
		int maxx = k+(m-2)/2;
		int pmin = max(0LL, k-m/2);
		int pmax = min(-1LL, -k+(m-1)/2);
		D(minn, maxx, pmin, pmax, pmax);
		ans = -k-minn+1+maxx-pmin+1+pmax+k;
	}
	else if (!k) ans = m;
	else
	{
		int minn = k-m/2;
		int maxx = -(k-(m-1)/2);
		int pmin = max(0LL, -k-(m-1)/2);
		int pmin2 = min(-1LL, k+(m-2)/2);
		ans = k-minn+1+maxx-pmin+1+pmin2-k;
	}
	cout<<ans<<endl;

	return 0;
}
/*
 */