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

#define INF (int)1e9
#define EPS (int)1e-9
#define ll long long
#define ld long double
#define FOR(i,m,n) for(int i=m; i<n; i++)
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
//#define endl "\n"


void solve(){
    ld n;
    cin >> n;
    vt<pair<ld,ld>> a(n);
    vt<pair<ld,ld>> sums(n);
    ld asum = 0, tsum = 0, ans = 0, ct = n-1;
    FOR(i,0,n){
        cin >> a[i].first >> a[i].second;
        asum += a[i].first;
        sums[i].first = a[i].first*2 + a[i].second;
        sums[i].second = i;
    }
    sort(all(sums));
    while(tsum<=asum){
        tsum += sums[ct].first;
        ans ++;
        ct --;
    }
    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int tt;
    //cin >> tt;
    tt=1;
    cout << setprecision(0) << fixed;
    while (tt--){
        solve();
    }
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

struct person {
    ll id;
    ll a;
    ll b;
};

ll check(ll N, ll start, ll end, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix) {
    if (end > 2 * N) {
        return 0;
    }
    if (start_fix[start] >= 0) {
        return 2;
    }
    if (end_fix[end] >= 0) {
        return 2;
    }
    if (start_end[start * 1000 + end] >= 0) {
        return 2;
    }
    return 1;
}

bool recursive1(ll N, ll start, ll cnt, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix, ll anypt, vector<ll>& memo) {
    if (cnt == N) {
        return true;
    }
    if (start >= 2 * N) {
        return false;
    }
    if (memo[start] >= anypt) {
        return false;
    }
    memo[start] = anypt;

    for (ll end = min(start + N, 2 * N); end >= start + 1; end--) {
        bool success = true;
        ll anyy = anypt;
        for (ll ss = start; ss <= end - 1; ss++) {
            ll ee = end - start + ss;
            ll result = check(N, ss, ee, start_end, start_fix, end_fix);
            if (result == 0) {
                success = false;
                break;
            } else if (result == 1) {
                anyy--;
                if (anyy < 0) {
                    success = false;
                    break;
                }
            } else {
                ;
            }
        }
        if (success) {
            bool ok = recursive1(N, end + end - start, cnt + (end - start), start_end, start_fix, end_fix, anyy, memo);
            if (ok) {
                return true;
            }
        }
    }
    return false;
}

bool solve(ll N, vector<person>& persons) {
    vector<ll> start_end(300000, -1);
    vector<ll> start_fix(300, -1);
    vector<ll> end_fix(300, -1);
    ll anypt = 0;
    for (auto p : persons) {
        if (p.a == -1 && p.b == -1) {
            anypt++;
        }
        if (p.a >= 0 && p.b == -1) {
            start_fix[p.a] = p.id;
        }
        if (p.a == -1 && p.b >= 0) {
            end_fix[p.b] = p.id;
        }
        if (p.a >= 0 && p.b >= 0) {
            start_end[p.a * 1000 + p.b] = p.id;
        }
    }
    vector<ll> memo(2 * N + 2, -1);
    return recursive1(N, 1, 0, start_end, start_fix, end_fix, anypt, memo);
}

int main() {
    ll N;
    cin >> N;

    vector<person> persons(N);
    for (ll i = 0; i < N; i++) {
        person p;
        cin >> p.a >> p.b;
        p.id = i;
        persons[i] = p;
    }
    if (solve(N, persons)) {
        print("Yes");
    } else {
        print("No");
    }
}
