#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return {i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
constexpr int mod = 1000 * 1000 * 1000 + 7;
void DodajDo(int& a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int Dodaj(int a, int b) {
  DodajDo(a, b);
  return a;
}
int Mnoz(int a, int b) { return (ll)a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
constexpr int nax = 55;
int n;
int a[nax];
int b[nax];
ll dp[nax][nax][nax];
bool Ok(ll x) {
  constexpr ll inf = numeric_limits<ll>::max();
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < nax; j++) {
      for (int k = 0; k < nax; k++) {
        dp[i][j][k] = inf;
      }
    }
  }
  dp[n][0][0] = 0;
  for (int i = n - 1; i >= 0; i--) {
    const ll wart = a[i] * 1000ll - x * b[i];
    for (int j = 0; j < nax; j++) {
      for (int k = 0; k < nax; k++) {
        if (dp[i + 1][j][k] < inf) {
          if (j > 0) dp[i][j - 1][k] = min(dp[i][j - 1][k], dp[i + 1][j][k]);
          if (k + 1 < nax)
            dp[i][j][k + 1] = min(dp[i][j][k + 1], dp[i + 1][j][k] + wart);
        }
      }
    }
    if (i == 0 or a[i] > a[i - 1]) {
      for (int j = 0; j < nax; j++) {
        for (int k = 0; k < nax; k++) {
          if (dp[i][j][k] < inf) {
            dp[i][j + k][0] = min(dp[i][j + k][0], dp[i][j][k]);
          }
        }
      }
    }
  }
  for (int i = 0; i < nax; i++) {
    if (dp[0][i][0] <= 0) {
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll p = 1, k = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    k += a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<pair<int, int>> sor;
  for (int i = 0; i < n; i++) {
    sor.emplace_back(a[i], b[i]);
  }
  sort(sor.begin(), sor.end());
  for (int i = 0; i < n; i++) {
    a[i] = sor[i].first;
    b[i] = sor[i].second;
    debug() << " ["
               "a[i]"
               ": "
            << (a[i])
            << "] "
               " ["
               "b[i]"
               ": "
            << (b[i]) << "] ";
  }
  k *= 1000;
  while (p < k) {
    const ll x = (p + k) / 2;
    const bool ok = Ok(x);
    if (ok) {
      k = x;
    } else {
      p = x + 1;
    }
  }
  cout << k << endl;
  assert(Ok(k));
  assert(!Ok(k - 1));
  return 0;
}
