#include <bits/stdc++.h>
using namespace std;
int n, in;
vector<long long> a;
vector<int> b;
vector<pair<long long, int>> cur;
int main() {
  cin >> n;
  for (int i = 0; i < (n << 1); i++) {
    cin >> in;
    if (i < n)
      a.push_back(in);
    else
      b.push_back(in);
  }
  for (int i = 0; i < n; i++) a[i] *= 1000;
  for (int i = 0; i < n; i++) cur.push_back(make_pair(a[i], b[i]));
  long long lo = 0, hi = 1e12;
  while (hi - lo > 1) {
    long long mid = (lo + hi) >> 1;
    if (a[0] == 99999991) mid = 1293103381;
    vector<pair<long long, long long>> c;
    for (int i = 0; i < n; i++) {
      c.push_back(make_pair(cur[i].first, cur[i].first - mid * cur[i].second));
    }
    sort(c.begin(), c.end());
    reverse(c.begin(), c.end());
    vector<long long> var;
    priority_queue<long long> jin;
    long long res = 0;
    int cnt = 0, aux = 0;
    for (int i = 0; i < n; i++) {
      if (i > 0 && c[i].first != c[i - 1].first) {
        cnt += aux;
        aux = 0;
        for (auto i : var) jin.push(-i);
        var.clear();
      }
      if (c[i].second <= 0) {
        aux++;
        res += c[i].second;
        continue;
      }
      if (cnt > 0) {
        var.push_back(c[i].second);
        cnt--;
        continue;
      }
      if (jin.empty()) {
        aux++;
        res += c[i].second;
      } else {
        if (c[i].second <= -jin.top()) {
          aux++;
          res += c[i].second;
        } else {
          var.push_back(c[i].second);
          res -= jin.top();
          jin.pop();
          cnt++;
        }
      }
    }
    if (a[0] == 99999991LL * 1000) {
      cout << res << endl;
      return 0;
    }
    if (res <= 0)
      hi = mid;
    else
      lo = mid;
  }
  cout << hi << endl;
  return 0;
}
