#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector > v(n); for (int i = 0; i < n; i++) cin >> v[i].first; for (int i = 0; i < n; i++) cin >> v[i].second; sort(v.begin(), v.end()); long long pref = 0; long long suff = 0; long long acc = 0; for (int i = 0; i < n; i++) { acc += abs(v[0].first - v[i].first) * v[i].second; suff += v[i].second; } int x = -1; long long y = -1; for (int i = 0; i < n; i++) { if (i > 0) { long long diff = v[i].first - v[i-1].first; acc += diff * (pref - suff); } if (x == -1 || y > acc) { x = v[i].first; y = acc; } pref += v[i].second; suff -= v[i].second; } cout << x << " " << y << endl; return 0; }