#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<pair<long long, long long>> ab(n);
    for (int i = 0; i < n; i++) {
        cin >> ab[i].first;
    }
    long long tot = 0;
    for (int i = 0; i < n; i++) {
        cin >> ab[i].second;
        tot += ab[i].second;
    }
    sort(ab.begin(), ab.end());
    long long cur = 0;
    long long x;
    for (int i = 0; i < n; i++) {
        cur += ab[i].second;
        if (cur >= (tot + 1) / 2) {
            x = ab[i].first;
            break;
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += ab[i].second * abs(ab[i].first - x);
    }
    cout << x << " " << ans << endl;
}