#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    ll n, num = 0, hyp = 1;
    cin >> n;
    while (1)
    {
        string hikaku = to_string(hyp) + to_string(hyp);
        if (stoll(hikaku) <= n)
        {
            num++;
            hyp++;
        }
        else
        {
            break;
        }
    }
    cout << num << endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
 
using namespace std;
using ll = long long;

ll a,b,c,i,j,k,n,m,l,x,y,z,result,chk,tmp,sum;


int main() {

  cin >> n;
  ll a[n];
  rep(i,n){
    cin >> a[i];
  }
  sort(a,a+n);

  for(i=n-1;i>=0;i--){
    sum += a[i]*((n-1)-2*(n-i-1));
  }

  cout << sum << endl;


  
  return 0;
}