#include <bits/stdc++.h>
using namespace std;
int n;
pair<int64_t, int64_t> c[55];
bool relax(int64_t& x, int64_t y) { return y < x ? (x = y, true) : false; }
bool solve() {
  vector<int64_t> f(n + 1, -1ull / 2);
  f[0] = 0;
  for (int i = 0, j = 0; i < n; i = j) {
    for (; j < n && c[i].second == c[j].second; ++j)
      ;
    sort(c + i, c + j);
    int64_t s[55];
    const int m = j - i;
    s[0] = 0;
    for (int k = 0, _n(m); k < _n; ++k) s[k + 1] = s[k] + c[i + k].first;
    vector<int64_t> g(n + 1, -1ull / 2);
    for (int k = 0; k <= n; ++k) {
      if (f[k] == -1ull / 2) continue;
      for (int t = 0; t <= k && t <= j - i; ++t) {
        relax(g[k + m - 2 * t], f[k] + s[m - t]);
      }
    }
    swap(f, g);
  }
  return *min_element((f).begin(), (f).end()) < 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int64_t> a(n), b(n);
  for (int i = 0, _n(n); i < _n; ++i) {
    cin >> a[i];
    a[i] *= 1000;
  }
  for (int i = 0, _n(n); i < _n; ++i) cin >> b[i];
  for (int j = 0, _n(n); j < _n; ++j)
    for (int i = 0, _n(j); i < _n; ++i)
      if (a[i] < a[j]) {
        swap(a[i], a[j]);
        swap(b[i], b[j]);
      }
  int64_t lo = -1, hi = 1e12;
  for (; lo + 1 < hi;) {
    int64_t mid = lo + (hi - lo) / 2;
    for (int i = 0, _n(n); i < _n; ++i) c[i] = {a[i] - mid * b[i], a[i]};
    (solve() ? hi : lo) = mid;
  }
  cout << lo << endl;
  return 0;
}
