// Created by ...
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i=a; i<b; i++)
#define repe(i,a,b) for(int i=a; i<=b; i++)
#define ll long long
#define ui unsigned int
#define pb push_back
#define deb(x) cout << #x << '=' << x << endl
#define deb2(x,y) cout << #x << '=' << x << << #y << '=' << y << endl
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define endl "\n"
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define hcf(x,y)     __gcd(x,y)
#define lcm(x,y)     (x*y)/(__gcd(x,y))
#define CountOne(x)  __builtin_popcount(x)        
#define parity(x)    __builtin_parity(x)           //Funtion return (true) if number of set bits is odd(odd parity) else false..
#define LeadZero(x)  __builtin_clz(x)             //Counts leading zero in binary representation of x ....   
#define TrailZero(x) __builtin_ctz(x)

#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;
typedef unordered_map<int, int> umap_ii;
typedef unordered_map<int, int> umap_ii;
typedef unordered_map<string, int> umap_si;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
//alt + ctrl + N

//===============================================================================//
ll power(ll x, ll y) {
ll v = 1; while (y > 0) { if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

bool isPowerOfTwo(ll x){
    return x && (!(x & (x-1)));     //check if the number is power of two or not
}
ll ceil(ll a,ll b){ return (a+b-1)/b; }
//===============================================================================//
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
    if(2*a.ff+a.ss == 2*b.ff+b.ss) return (a.ff>b.ff);
    else return (2*a.ff+a.ss > 2*b.ff+b.ss);
}

int main(){
    fastIO;
srand(chrono::high_resolution_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll test = 1;
    //cin >> test;
    while(test--){
        ll n;
        cin >> n;
        vector<pair<ll,ll>>a(n);
        ll voteT = 0,voteA = 0;
        rep(i,0,n){
        	ll x,y;
        	cin >> x >> y;
        	a[i].ff = x;
        	a[i].ss = y;
        	voteA += x;
        }
        sort(all(a),cmp);
        ll ans = 0;
        for(ll i=0;i<n;i++){
        	if(voteT > voteA){
        		break;
        	}
        	voteT += a[i].ff + a[i].ss;
        	voteA -= a[i].ff;
        	ans++;
        }
        cout << ans << endl;
    }
return 0;
}
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 3e15 +7
#define pll pair<ll,ll>
#define ff first
#define ss second
#define PI acos(-1)
#define prm 998244353
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*
ll dx[4]={1,-1,0,0};
ll dy[4]={0,0,-1,1};
cout<<fixed<<setprecision(12)<<;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%prm;
    while(b>0){
        if(b&1){res=(res*a)%prm;b--;}
        a=(a*a)%prm;
        b>>=1;
    }
    return res;
}
ll inv(ll y){return power(y,prm-2);}
ll fact[300060];
ll nCr(ll n, ll r)
{
   if (r==0)
      return 1;
    return (fact[n]* inv(fact[r]) % prm *
            inv(fact[n-r]) % prm) % prm;
}
 
void init(ll n)
{
	fact[0]=1;
	for(ll i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%prm;
}
*/
/*
//cout<<"Case #"<<fff-T<<": ";
/*
ll spf[15000050];
void sieve()
{
	for(ll i=2;i*i<=15000030;i++){
		if(spf[i]==0){
			for(ll j=i+i;j<=15000030;j+=i){
				if(spf[j]==0){
					spf[j]=i;
				}
			}
		}
	}
}*/

int main()
{
    fastio;
	ll T=1;
	//cin>>T;
	//ll fff=T;
	while(T--)
	{
	     ll n;
	     cin>>n;
	     ll a[n+1];
	     for(ll i=1;i<=n;i++)cin>>a[i];
	     if(n==1)
	     {
	         cout<<a[1]<<endl;
	         return 0;
	     }
	     if(n==2)
	     {
	          cout<<(2*a[1])%mod<<endl;
	         return 0;
	     }
	     ll dp[n+3][2];
	     dp[0][0]=1;
	     dp[0][1]=0;
	     dp[1][0]=1;
	     dp[1][1]=0;
	     for(ll i=2;i<=n;i++)
	     {
	         dp[i][0]=(dp[i-1][0] + dp[i-1][1])%mod;
	         dp[i][1]=dp[i-1][0];
	     }
	     //cout<<dp[n][0]<<endl;
	     //cout<<dp[n][1]<<endl;
	     ll ans=0;
	     //ans+=;
	     for(ll i=1;i<=n;i++)
	     {
	        ll v=a[i]*((dp[i-1][0]+dp[i-1][1])%mod);
	        v=v%mod;
	        v=v*((dp[n-i+1][0] + dp[n-i+1][1])%mod);
	        v=v%mod;
	        ans=(ans+v)%mod;
	        if(i==1)continue;
	        ll x=a[i]*((dp[i-2][0]+dp[i-2][1])%mod);
	        x=x%mod;
	        x=x*((dp[n-i][0] + dp[n-i][1])%mod);
	        x=x%mod;
	        
	        ans=(ans-x + mod)%mod;
	         //ans=(ans+(a[i]*((dp[i-1][0]+dp[i-1][1])%mod)*((dp[n-i+1][0] + dp[n-i+1][1])%mod))%mod)%mod;
	         //if(i>1)
	         //ans=(ans+mod-(a[i]*((dp[i-2][0]+dp[i-2][1])%mod)*((dp[n-i][0] + dp[n-i][1])%mod))%mod)%mod;
	       
	       //cout<<ans<<endl;
	         
	     }
	     cout<<ans<<endl;
	}
}
/*
 
*/
