#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6;
int a[MAX_N];
int b[MAX_N];
bool dp[MAX_N];
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("CHIAQUA.inp", "r", stdin);
    freopen("CHIAQUA.out", "w", stdout);
    int N;
    cin >> N;
    int bac = 0, giang = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
        if (b[i] == 1) {
            bac += a[i];
        } else {
            giang += a[i];
        }
    }

    int ans1 = abs(bac - giang);
    cout << ans1 << endl;

    int ts = bac + giang;
    int p = ts / 2;
    memset(dp, 0, sizeof(dp));
    dp[0] = true;
    
    for (int i = 0; i < N; ++i) {
        for (int j = p; j >= a[i]; --j) {
            dp[j] = dp[j] || dp[j - a[i]];
        }
    }

    int best = 0;
    for (int i = p; i >= 0; --i) {
        if (dp[i]) {
            best = i;
            break;
        }
    }

    int ans = abs(ts - 2 * best);
    cout << ans << endl;

    return 0;
}