#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 998244353
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x)  //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=1000005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
            prime.pb(i);
        }
    }
    return;
}


 
int32_t main()
{
    
    IOS;
    //fill(isprime, true);
    //pre();
    int qu=1;
    //cin>>qu;
    while(qu--)
    {
       int n;
       cin>>n;
       int a[n];
       rep(i,0,n) cin>>a[i];
       sort(a,a+n);
       int pr1[n],pr2[n],sum=0;
       pr1[0]=0;
       pr2[0]=0;
       int pr3[n];
       rep(i,1,n)
       {
           pr1[i]=a[i]-a[i-1];
           pr2[i]=pr2[i-1]+pr1[i];
           sum+=pr2[i];
       }
      // rep(i,0,n)cout<<pr2[i]<<" ";
       //cout<<"\n";
       int ans=sum;
       pr3[0]=sum;
       rep(i,1,n) pr3[i]=pr3[i-1]-pr2[i],ans+=pr3[i];
       //cout<<"\n";
       //cout<<sum<<" ";
       rep(i,0,n)
       {
           ans-=(n-i-1)*pr2[i];
       }
       cout<<ans;
       
    }
    
}
 
 
 
#include<bits/stdc++.h>
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll mod=1e9+7,INF = 0x3f3f3f3f;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll exgcd(ll a, ll b, ll &x, ll &y) {if(!b) {x = 1; y = 0; return a;}ll r = exgcd(b, a % b, x, y);ll tmp = x; x = y, y = tmp - a / b * y;return r;}
ll qpow(ll a,ll n){ll r=1%mod;for (a%=mod; n; a=a*a%mod,n>>=1)if(n&1)r=r*a%mod;return r;}
ll qpow(ll a,ll n,ll P){ll r=1%P;for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll EX_BSGS(ll a,ll b,ll p){if(b == 1) return 0;map<ll,ll> pw;ll cnt = 0, t = 1, s, x, m;for(ll d = gcd(a, p); d != 1; d = gcd(a, p)){if(b % d) return -1;++cnt, b /= d, p /= d, t = 1LL * t * a / d % p;
if(b == t) return cnt;}s = b, m = sqrt(p) + 1;for(ll i = 0; i < m; ++i){pw[s] = i;s = 1LL * s * a % p;}x = qpow(a, m, p), s = t;for(ll i = 1; i <= m; ++i){s = 1LL * s * x % p;if(pw.count(s)) return i * m - pw[s] + cnt;
}return -1;} //拔山盖世！
/*const  int maxn=3e5+10;
ll _next[maxn*2],head[maxn],tot,to[maxn*2],w[2*maxn];
void add(ll x,ll y,ll z)
{
_next[++tot]=head[x],head[x]=tot,to[tot]=y,w[tot]=z;
//_next[++tot]=head[y],head[y]=tot,to[tot]=x;
}*/
const int maxn=2e5+10;
ll a[maxn],b[maxn];
int id[maxn];
bool cmp(int x,int y)
{
  return 2*a[x]+b[x]>2*a[y]+b[y];
}
int main()
{
        
   int n;
   cin>>n;
   ll sum=0;
   for(int i=1;i<=n;i++)
   {
     cin>>a[i]>>b[i];
     id[i]=i;
     sum+=a[i];
   }
   ll ans=0;
   sort(id+1,id+1+n,cmp);
   for(int i=1;i<=n;i++)
   {
      int now=id[i];
      ans+=b[now]+a[now];
      sum-=a[now];
      if(ans>sum)
      {
        cout<<i<<endl;
        break;
      }
   }

}
