#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
#define MAXN 300001
#define mod 1000000007
ll a[MAXN];
int main() {
    int n;
    cin >> n;
    ll co[60];
    for (int i = 0; i < 60; i++) co[i] = 0;
    for (int i = 1; i <= n; i++) {
        ll a;
        cin >> a;
        int count = 0;
        while (a) {
            co[count]+= a % 2;
            a /= 2;
            count++;
        }
    }
    ll ret = 0;
    int now = 1;
    for (int i = 0; i < 60; i++) {
        ret = (ret + (now * co[i] % mod)  * (n - co[i])) % mod;
        now = now * 2 % mod;
    }
    cout << ret << endl;
    return 0;
}
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N = 5050;
const ll INF = 0x3f3f3f3f;

ll dp[N][N];
int n, w[N], h[N], a[N], ans;

bool cmp(int A,int B){
    return w[A] + h[A] < w[B] + h[B];
}

int main(){
    scanf("%d", &n);
    for(int i = 0;i<n;i++){
        scanf("%d%d", h + i, w + i);a[i] = i;
    }
    sort(a, a + n, cmp);
    for(int i = 0;i<=n;i++){
        dp[0][i] = INF * INF;
        dp[i][0] = 0;
    }
    dp[0][1] = w[a[0]];
    for(int i = 1;i<n;i++){
        for(int j = 1;j<=n;j++){
            dp[i][j] = dp[i - 1][j];
            if(h[a[i]] >= dp[i - 1][j - 1])
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + w[a[i]]);
        }
    }
    ans = n;
    while(dp[n - 1][ans] == INF * INF) ans--;
    printf("%d\n", ans);
}
