#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
bool IsGood(const int64 alpha, const vector<int>& power,
            const vector<int>& processors) {
  const int n = power.size();
  map<int, vector<int64>> costs;
  for (int i = 0; i < n; ++i) {
    costs[power[i]].push_back(power[i] * 1000LL - processors[i] * alpha);
  }
  vector<int64> prev_ans(n + 1);
  vector<int64> next_ans(n + 1);
  for (auto& entry : costs) {
    vector<int64>& cur_costs = entry.second;
    sort(cur_costs.begin(), cur_costs.end());
    const int cur_elements = cur_costs.size();
    for (int j = 0; j <= n; ++j) {
      int64 cost_add = 0;
      next_ans[j] = 1e18;
      for (int k = 0; k < cur_elements; ++k) {
        if (j >= cur_elements - k) {
          next_ans[j] =
              min(next_ans[j],
                  prev_ans[min(n, j - cur_elements + 2 * k)] + cost_add);
        }
        cost_add += cur_costs[k];
      }
      next_ans[j] =
          min(next_ans[j], prev_ans[min(n, j + cur_elements)] + cost_add);
    }
    swap(next_ans, prev_ans);
  }
  return prev_ans[0] <= 0;
}
void solve() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  int64 low = 0;
  int64 hi = 1e12;
  while (low + 1 < hi) {
    const int64 middle = (low + hi) / 2;
    if (IsGood(middle, a, b)) {
      hi = middle;
    } else {
      low = middle;
    }
  }
  cout << hi << "\n";
}
int main() {
  solve();
  return 0;
}
