#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N], b[N];
int n, m;
int mid;
int ans = 0;
long long T;
long long dp[51][51];
long long solve(int at, int open) {
  if (open < 0) return 112345678912345LL;
  if (at == n) return 0;
  if (dp[at][open] != -1) return dp[at][open];
  int r;
  for (r = at; r < n and a[at] == a[r]; r++)
    ;
  int qtd = (r - at);
  long long ret = solve(r, open - qtd);
  long long s1 = 0, s2 = 0, cnt = 0;
  for (int j = at; j < r; j++) {
    s1 += a[j];
    s2 += b[j];
    cnt++;
    qtd--;
    if (open - qtd >= 0)
      ret = min(ret, solve(r, open - qtd + cnt) + s1 * 1000 - T * s2);
  }
  return dp[at][open] = ret;
}
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n == 1) {
    cout << (a[0] * 1000LL + b[0] - 1) / b[0] << endl;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if ((a[i] < a[j]) or (a[i] == a[j] and b[i] < b[j])) {
        swap(a[i], a[j]);
        swap(b[i], b[j]);
      }
  long long lo = 0, hi = 1123456789123, ans = -1;
  cout << hi << endl;
  while (lo <= hi) {
    memset(dp, -1, sizeof dp);
    long long mid = (lo + hi) / 2;
    T = mid;
    if (solve(0, 0) <= 0) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
