#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int main(){ int N; cin >> N; vector A, B; rep(i,N){ ll a; cin >> a; A.push_back(a); } rep(i,N){ ll b; cin >> b; B.push_back(b); } vector> v; rep(i,N){ v.emplace_back(A[i],B[i]); } sort(ALLOF(v)); int lhs = 0, rhs = N-1; while(lhs != rhs){ if(v[lhs].second < v[rhs].second){ v[rhs].second -= v[lhs].second; v[lhs].second -= v[lhs].second; }else{ v[lhs].second -= v[rhs].second; v[rhs].second -= v[rhs].second; } if(v[lhs].second == 0) lhs++; if(lhs == rhs) break; if(v[rhs].second == 0) rhs--; } ll x = v[lhs].first; ll y = 0; rep(i,N){ y += B[i] * abs(x - A[i]); } cout << x << " " << y << endl; return 0; }