#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(long long i = 0; i < n; i++)
#define rep1(i, n) for(long long i = 1; i <= n; i++)
#define rrep(i, n) for(long long i = n; i > 0; i—)
#define rrep1(i, n) for(long long i = n; i >= 0; i—)
//char型　10進数で48が'0'

int main() {
  ll n,sum=0,total=0,ans=0;
  cin >> n;
  vector<ll> v(n);
  rep(i, n){
    ll a,b;
    cin >> a >> b;
    v[i] = a*2 + b;
    total += a;
  }
  sort(v.begin(),v.end());
  for(long long i = n - 1; sum <= total; i--){
    sum += v[i];
    ans += 1;
  }
  cout << ans << endl;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],b[200005];
long long ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]]=a[i];
	}
	for(int i=1;i<=n;i++){
		int j=n-i+1;
		while(b[b[a[i]]]!=b[a[i]]){
			b[a[i]]=b[b[a[i]]];
		}
		while(b[b[a[j]]]!=b[a[j]]){
			b[a[j]]=b[b[a[j]]];
		}
		if(b[a[i]]!=b[a[j]]){
			b[b[a[j]]]=b[a[i]];
			ans++;
		}
	}
	printf("%lld",ans);
	return 0;
} 