// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const long long MOD = 1000000007;
const int INF{ 2100000000 };	// MAX:2147483647
typedef long long ll;
using namespace std;

// ------------- ここからコード -------------


int main(void) {

	int N;
	cin >> N;
	
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	sort(A.begin(), A.end(), greater<int>());
	ll ans = 0;
	for (int cnt = 0; cnt < N; cnt++) {
		ll num = A[cnt];

		ans += (-num * cnt) + (num * (N - 1 - cnt));
	}

	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
//#define ll long long int
#define endl "\n"
using ll = int64_t;




int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   ll a;
   cin>>a;
   unordered_set<ll> s;
   for(ll i=2;i*i<=a;i++){
	   ll x=i*i;
	   while(x<=a){
		   s.insert(x);
		   x=x*i;
	   }
   }
   cout<<a-s.size();
}