#include long long int a[200005], b[200005]; long long int h[200005], l; int comp_h(long long int x, long long int y) { if (a[h[x]] > a[h[y]]) return 1; else return -1; } void swap_h(long long int x, long long int y) { long long int f = h[x]; h[x] = h[y]; h[y] = f; return; } void push(long long int ne) { h[l] = ne; long long int p = l; l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p) > 0) swap_h((p - 1) / 2, p); return; } long long int pop() { l--; swap_h(0, l); long long int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2) > 0) { if (comp_h(p, 2 * p + 2) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } long long int abs(long long int n) { if (n < 0) n *= -1; return n; } int main() { long long int n; scanf("%lld", &n); long long int i, j; for (i = 0; i < n; i++) scanf("%lld", &a[i]); for (i = 0; i < n; i++) scanf("%lld", &b[i]); if (n == 1) { printf("%lld 0\n", a[0]); return 0; } long long int c[200005]; l = 0; for (i = 0; i < n; i++) push(i); for (i = 0; i < n; i++) c[i] = pop(); for (i = 0; i < n; i++) h[i] = a[i]; for (i = 0; i < n; i++) a[i] = h[c[i]]; for (i = 0; i < n; i++) h[i] = b[i]; for (i = 0; i < n; i++) b[i] = b[c[i]]; long long int sum_b[200005]; sum_b[0] = 0; for (i = 0; i < n; i++) sum_b[i + 1] = sum_b[i] + b[i]; long long int v1, v2; v1 = v2 = 0; j = 0; while (sum_b[j] * 2 <= sum_b[n]) j++; j--; for (i = 0; i < n; i++) v1 += b[i] * abs(a[j] - a[i]); j++; for (i = 0; i < n; i++) v2 += b[i] * abs(a[j] - a[i]); if (v1 < v2) printf("%lld %lld\n", a[j - 1], v1); else printf("%lld %lld\n", a[j], v2); return 0; }