#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii; 
#define ll long long
#define ar array
const ll mxN=2e5;
const int mod=1e9+7;
const ll INF=1e18;
#define what_is(x) cerr << #x << " is " << x << endl;
ll a,b,n,k,q,m,x,y,h,l,r,t;

void solve(){
	cin>>n;
	ll A[n],B[n],aoki=0,delta;
	vector<ll> benifit(n);
	for(int i=0;i<n;i++){
		cin>>A[i]>>B[i];
		aoki+=A[i];
		benifit[i]=2*A[i]+B[i];
	}
	delta=-aoki;
	sort(benifit.rbegin() , benifit.rend());
	int i=0;
	while(i<n && delta<=0){
		delta+=benifit[i];
		i++;
		
	}
	cout<<i<<endl;
}	


signed main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    cout<<setprecision(12)<<fixed;
    // cin>>t;
    // while(t--)
    	solve();
	return 0;
   
}
 
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 110;
int N;
int dp[MAX_N][2];
V<string> S;

int dfs(int i, int j) {
    if(i >= N + 1) {
        return j;
    }

    int& ret = dp[i][j];
    if(~ret) { return ret; }
    ret = 0;

    if(i == 0) {
        ret += dfs(i + 1, 1);
        ret += dfs(i + 1, 0);
        return ret;
    }

    // ここを 1 にする
    int nj;
    if(S[i] == "AND") {
        nj = j & 1;
        ret += dfs(i + 1, nj);
    }
    else {
        nj = j | 1;
        ret += dfs(i + 1, nj);
    }

    // ここを 0 にする
    if(S[i] == "AND") {
        nj = j & 0;
        ret += dfs(i + 1, nj);
    }
    else {
        nj = j | 0;
        ret += dfs(i + 1, nj);
    }
    return ret;
}

signed main() {
    IOS;
    cin >> N;
    S.resize(N + 1);
    REP(i, N) { cin >> S[i + 1]; }
    MINUS(dp);
    int ans = dfs(0, 0);
    print(ans);

    return 0;
}
