#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int N = 51, D = 101;
int n, b[N];
long long a[N], dp[N * D][2][N][N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<pair<int, int>> ve;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
  }
  for (int i = (0); i < (n); i++) {
    cin >> b[i];
    ve.emplace_back(a[i], b[i]);
  }
  sort((ve).begin(), (ve).end());
  for (int i = (0); i < (n); i++) {
    tie(a[i], b[i]) = ve[i];
  }
  double ans = LLONG_MAX;
  for (int i = (0); i < (n); i++) {
    bool p = i % 2;
    for (int sum = (0); sum < (N * D); sum++) {
      for (int j = (0); j < (n - i); j++) {
        for (int k = (0); k < (n - i - j); k++) {
          if (i == 0) {
            if (sum == 0 && k > 0) {
              dp[sum][p][j][k] = 0;
            } else if (sum == b[i]) {
              dp[sum][p][j][k] = a[i];
            } else {
              dp[sum][p][j][k] = LLONG_MAX;
            }
          } else if (a[i - 1] == a[i]) {
            dp[sum][p][j][k] = (k > 0 ? dp[sum][!p][j][k - 1] : LLONG_MAX);
            if (b[i] <= sum) {
              long long x = dp[sum - b[i]][!p][j + 1][k];
              if (x != LLONG_MAX && a[i] + x < dp[sum][p][j][k]) {
                dp[sum][p][j][k] = a[i] + x;
              }
            }
          } else {
            dp[sum][p][j][k] = (k > 0 ? dp[sum][!p][0][j + k - 1] : LLONG_MAX);
            if (b[i] <= sum) {
              long long x = dp[sum - b[i]][!p][0][j + k + 1];
              if (x != LLONG_MAX && a[i] + x < dp[sum][p][j][k]) {
                dp[sum][p][j][k] = a[i] + x;
              }
            }
          }
        }
      }
      if (sum > 0 && i == n - 1) {
        long long x = dp[sum][p][0][0];
        if (x != LLONG_MAX) {
          ans = min(ans, 1.0 * x / sum);
        }
      }
    }
  }
  cout << (long long)ceil(ans * 1000) << '\n';
}
