#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define pii pair<int,int>
#define float double
#define pb push_back 
#define lp(i,j,n) for( i=j;i<n;i++) 
#define lop(j,k,n)for( j=k;j<n;j++)
#define m_p make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define minheap priority_queue<int,vector<int>,greater<int>>
#define maxheap priority_queue<int>
#define kickstart  cout<<"Case #"<<cc<<": "
#define pair_pq priority_queue<pii,vector<pii>>
#define ff first
#define ss second
#define pff pair<float,float>
#define piii pair<int,pii>
#define all(x)x.begin(),x.end()
const int MAX = 5e2+5 ,N = 2e3 + 5;
const int MOD=1e9 + 7 ,mod=1e9 + 7;
const string digits = "0123456789";
map<string , int>mp;
void solve(){
  int i=0 , j = 0, n , m , x = 0 , y = 0 ,r,k,f   ,p;
  cin >> n ;
  int a = 0 , b = 0 ,tt=0;
  vector<pii>v;
  lp(i , 0 ,n){
    cin >> x >> y ;
    v.pb({2*x + y , i});
    a+=x;
  }
  sort(all(v));
 reverse(all(v));
  int ans = 0 ;
  for(int i = 0 ; i < n ;i++){
    b+=(v[i].ff);
    ++ans;
    int rem = tt - b ;
    if(b > a)break;
  }
  cout << ans <<endl;
}
signed main()
{
  
 fastio
 #ifndef ONLINE_JUDGE 
      freopen("input.txt", "r", stdin); 
      freopen("output.txt", "w", stdout); 
 #endif
      int T = 1 ;
     //cin >> T;
      while( T-- )
      solve();
  return 0;
 }
 

 
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<vector>
using namespace std;
int read()
{
	int kkk=0,x=1;
	char c=getchar();
	while((c<'0' || c>'9') && c!='-') c=getchar();
	if(c=='-') c=getchar(),x=-1;
	while(c>='0' && c<='9') kkk=kkk*10+(c-'0'),c=getchar();
	return kkk*x;
}
int n;
vector<int> a1,a2,a3,a4;
int main()
{
	n=read();
	for(int i=1;i<=10000;++i)
	{
		if(i%2==0 && i%3==0 && i%5) a1.push_back(i);
		if(i%2==0 && i%3 && i%5==0) a2.push_back(i);
		if(i%2 && i%3==0 && i%5==0) a3.push_back(i);
		if(i%2==0 && i%3==0 && i%5==0) a4.push_back(i);
	}
	//cout<<a1.size()+a2.size()+a3.size()+a4.size()<<endl;
	printf("%d %d %d",a1[0],a2[0],a3[0]);
	int N=3;
	for(int i=1;i<a1.size();++i) if(N<n) printf(" %d",a1[i]),++N;
	for(int i=1;i<a2.size();++i) if(N<n) printf(" %d",a2[i]),++N;
	for(int i=1;i<a3.size();++i) if(N<n) printf(" %d",a3[i]),++N;
	for(int i=0;i<a4.size();++i) if(N<n) printf(" %d",a4[i]),++N;
	return 0;
}