#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int N = 52, V = N * 100 + 5;
long long dp[2][V][N][N];
int n;
struct O {
  long long a, b;
  bool operator<(const O &o) const { return a > o.a; }
} os[N];
long long f(int i, int j, int k, int s) {
  long long &r = dp[i][j][k][s];
  if (r != -1) return r;
  r = INF;
  int k1 = s + 1, s1 = 0;
  if (i != n - 1 && os[i].a == os[i + 1].a) swap(k1, s1);
  if (k) r = min(r, f(i + 1, j, k - 1, s));
  if (j >= os[i].b) r = min(r, f(i + 1, j - os[i].b, k + k1, s1) + os[i].a);
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int x = 0, qwerty = n; x < qwerty; x++) cin >> os[x].a;
  for (int x = 0, qwerty = n; x < qwerty; x++) cin >> os[x].b;
  sort(os, os + n);
  for (int j = 0, qwerty = V; j < qwerty; j++)
    for (int k = 0, qwerty = n + 1; k < qwerty; k++)
      for (int s = 0, qwerty = n + 1 - k; s < qwerty; s++) {
        dp[n & 1][j][k][s] = j == 0 ? 0 : INF;
      }
  for (int i = n - 1, b = (n - 1) & 1, nb = !b; i >= 0; i--, b ^= 1, nb ^= 1) {
    int k1 = 1, s1 = 0, idx = i;
    if (i != n - 1 && os[i].a == os[i + 1].a) swap(k1, s1);
    while (idx >= 0 && os[idx].a == os[i].a) idx--;
    for (int s = 0, qwerty = i - idx + 1; s < qwerty; s++) {
      int k0 = (s + 1) * k1, s0 = (s + 1) * s1, k2 = s * k1, s2 = s * s1;
      for (int j = 0, qwerty = V; j < qwerty; j++)
        for (int k = 0, qwerty = idx + 2; k < qwerty; k++) {
          long long &r = dp[b][j][k][s];
          r = INF;
          if (k) r = min(r, dp[nb][j][k - 1 + k2][s2]);
          if (j >= os[i].b)
            r = min(r, dp[nb][j - os[i].b][k + k0][s0] + os[i].a);
        }
    }
  }
  long long best = INF;
  for (int x = 1, qwerty = V; x < qwerty; x++) {
    if (dp[0][x][0][0] == INF) continue;
    long long tmp = 1000LL * dp[0][x][0][0];
    tmp = (tmp / (1LL * x)) + ((tmp % (1LL * x)) != 0);
    best = min(best, tmp);
  }
  cout << best << "\n";
}
