#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];
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];
  }
  k *= 1000;
  auto Ok = [&](ll x) -> bool {
    vector<pair<ll, int>> kto;
    multiset<int> poczmam;
    vector<int> zdejmij;
    auto MiesciSie = [&]() -> bool {
      auto mam = poczmam;
      for (int z : zdejmij) {
        auto it = mam.upper_bound(z);
        if (it == mam.end()) {
          return false;
        }
        mam.erase(it);
      }
      return true;
    };
    ll suma = 0;
    for (int i = 0; i < n; i++) {
      const ll wart = a[i] * 1000 - x * b[i];
      if (wart <= 0) {
        poczmam.insert(a[i]);
        suma += wart;
      } else {
        kto.emplace_back(-wart, a[i]);
      }
    }
    sort(kto.begin(), kto.end());
    for (auto& it : kto) {
      debug() << " ["
                 "suma"
                 ": "
              << (suma)
              << "] "
                 " ["
                 "it"
                 ": "
              << (it)
              << "] "
                 " ["
                 "poczmam"
                 ": "
              << (poczmam)
              << "] "
                 " ["
                 "zdejmij"
                 ": "
              << (zdejmij) << "] ";
      zdejmij.push_back(it.second);
      if (MiesciSie()) {
      } else {
        zdejmij.pop_back();
        suma -= it.first;
        poczmam.insert(it.second);
      }
    }
    debug() << " ["
               "suma"
               ": "
            << (suma) << "] ";
    return suma <= 0;
  };
  while (p < k) {
    const ll x = (p + k) / 2;
    const bool ok = Ok(x);
    if (ok) {
      k = x;
    } else {
      p = x + 1;
    }
  }
  assert(Ok(k));
  assert(!Ok(k - 1));
  cout << k << endl;
  return 0;
}
