#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector > v(n); REP (i, n) cin >> v[i].first; REP (i, n) cin >> v[i].second; sort(v.begin(), v.end()); long long total = 0; REP (i, n) total += v[i].second; int m = -1; long long diff = total + 1; long long pos = total; long long neg = 0; REP (i, n) { pos -= v[i].second; if (abs(pos-neg) < diff) { diff = abs(pos-neg); m = i; } neg += v[i].second; } int x = v[m].first; long long ret = 0; REP (i, n) ret += (long long)v[i].second * abs(v[i].first - x); cout << x << " " << ret << endl; return 0; }