#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, a[N], b[N];
vector<pair<int, int>> v;
long long dp[N][N][N * 100];
int tg[N][N][N * 100];
queue<tuple<int, int, int>> Q[N];
void upd(long long& ap, long long& aq, long long bp, long long bq) {
  if (bp * aq < ap * bq) ap = bp, aq = bq;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 0; i < n; i++) v.push_back({a[i], b[i]});
  sort(v.begin(), v.end(), [&](pair<int, int>& p1, pair<int, int>& p2) {
    if (p1.first != p2.first) return p1.first > p2.first;
    return p1.first * p2.second < p2.first * p1.second;
  });
  long long ans = 1e12, ap = 1;
  Q[0].push(make_tuple(0, 0, 0));
  int ptr = 0;
  for (int l = 0, r = 0; l < (int)v.size(); l = r) {
    while (r < (int)v.size() and v[l].first == v[r].first) r++;
    ++ptr;
    while (Q[ptr - 1].size()) {
      int ii, res, used;
      tie(ii, res, used) = Q[ptr - 1].front();
      Q[ptr - 1].pop();
      int nused = used;
      long long val = dp[ii][res][used];
      for (int i = l - 1; i < r; i++) {
        if (i >= l) {
          nused += v[i].second;
          val += v[i].first;
        }
        if (res >= r - i - 1) {
          int nres = res - (r - i - 1) + (i - l + 1);
          if (tg[ptr][nres][nused] != ptr) {
            tg[ptr][nres][nused] = ptr;
            dp[ptr][nres][nused] = 1e12;
            Q[ptr].push(make_tuple(ptr, nres, nused));
          }
          dp[ptr][nres][nused] = min(dp[ptr][nres][nused], val);
        }
      }
    }
  }
  while (Q[ptr].size()) {
    int ii, res, used;
    tie(ii, res, used) = Q[ptr].front();
    Q[ptr].pop();
    upd(ans, ap, dp[ii][res][used], used);
  }
  ans = (ans * 1000 + ap / 2) / ap;
  printf("%lld\n", ans);
}
