#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
  out << v.size() << '\n';
  for (auto e : v) out << e << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
  return prnt(out, v);
}
template <class T>
ostream& operator<<(ostream& out, set<T> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const long double PI = acos(-1);
int n, eq;
long long DP[2][51][51][51 * 101], sum;
pair<int, int> v[51];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i].first;
  for (int i = 1; i <= n; i++) cin >> v[i].second;
  sort(v + 1, v + n + 1,
       [](pair<int, int> a, pair<int, int> b) { return a.first > b.first; });
  memset(DP, 0x3f, sizeof(DP));
  DP[0][0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    memset(DP[(i & 1) ^ 1], 0x3f, sizeof(DP[i % 2]));
    if (v[i].first != v[i + 1].first) {
      for (int j = 0; j <= i / 2; j++) {
        for (int k = 0; k <= eq; k++) {
          for (int s = 0; s <= sum; s++) {
            if (i - 2 * j > 0)
              DP[(i & 1) ^ 1][j + 1][1][s] =
                  min(DP[(i & 1) ^ 1][j + 1][1][s], DP[i & 1][j][k][s]);
            DP[(i & 1) ^ 1][j][0][s + v[i + 1].second] =
                min(DP[(i & 1) ^ 1][j][0][s + v[i + 1].second],
                    DP[i & 1][j][k][s] + v[i + 1].first);
          }
        }
      }
      eq = 1;
    } else {
      eq++;
      for (int j = 0; j <= i / 2; j++) {
        for (int k = 0; k < eq; k++) {
          for (int s = 0; s <= sum; s++) {
            if (i - 2 * j - (eq - k - 1) > 0)
              DP[(i & 1) ^ 1][j + 1][k + 1][s] =
                  min(DP[(i & 1) ^ 1][j + 1][k + 1][s], DP[i & 1][j][k][s]);
            DP[(i & 1) ^ 1][j][k][s + v[i + 1].second] =
                min(DP[(i & 1) ^ 1][j][k][s + v[i + 1].second],
                    DP[i & 1][j][k][s] + v[i + 1].first);
          }
        }
      }
    }
    sum += v[i + 1].second;
  }
  long long ans = 1e18;
  for (int j = 0; j <= n; j++)
    for (int k = 0; k <= n; k++) {
      for (int s = 1; s <= sum; s++) {
        ans = min(ans, min((long long)(1e15), DP[n & 1][j][k][s]) * 1000 / s +
                           (s == 0 ? 0 : DP[n & 1][j][k][s] * 1000 % s != 0));
      }
    }
  cout << ans << '\n';
  return 0;
}
