#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; pll ab[200005]; ll cum[200005]; int main(){ int n; cin >> n; rep(i,n) cin >> ab[i].first; rep(i,n) cin >> ab[i].second; sort(ab,ab+n); cum[0] = 0; rep(i,n) cum[i+1] = cum[i] + ab[i].second; ll sum = cum[n]; int l = -1, r = n+1; while(r - l > 1){ int m = (l + r)/2; if(sum <= 2*cum[m]) r = m; else l = m; } ll x = ab[r].first; ll ans = 0; rep(i,n){ ans += ab[i].second * abs(ab[i].first - x); } cout << x << " " << ans << endl; return 0; }