#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
pair<long long, long long> a[55];
long long b[55];
int n;
const long long inf = 1e18;
long long ans = 0;
bool check(long long mid) {
  ans = 0;
  for (register int i = (1); i <= int(n); ++i)
    b[i] = a[i].first - a[i].second * mid, ans += b[i];
  multiset<pair<long long, bool> > s;
  for (int i = 1, j; i <= n; i = j) {
    for (j = i; a[j].first == a[i].first && j <= n; ++j)
      ;
    multiset<pair<long long, bool> > now;
    int l = i, r = j - 1;
    while (l <= r && s.size() && (s.begin()->first == -inf)) {
      now.insert({b[l], 0});
      s.erase(s.begin());
      l++;
    }
    while (r - l + 1 >= 2 && s.size()) {
      auto y = *s.begin();
      if (y.first >= b[l] + b[l + 1]) break;
      s.erase(s.begin());
      if (y.second) {
        now.insert({b[l], 0});
        now.insert({b[l + 1], 0});
      } else {
        now.insert({b[l] + b[l + 1] - y.first, 1});
        now.insert({y.first, 0});
      }
      l += 2;
    }
    while (l <= r && s.size() && (s.begin()->first < b[l])) {
      s.erase(s.begin());
      now.insert({b[l], 0});
      now.insert({-inf, 0});
      l++;
    }
    while (l <= r) {
      now.insert({-inf, 0});
      l++;
    }
    while (now.size()) {
      s.insert(*now.begin());
      now.erase(now.begin());
    }
  }
  for (auto it = s.begin(); it != s.end(); it++)
    if (it->first != -inf) ans -= it->first;
  if (ans <= 0)
    return true;
  else
    return false;
}
int main() {
  n = read();
  for (register int i = (1); i <= int(n); ++i) a[i].first = read() * 1000;
  for (register int i = (1); i <= int(n); ++i) a[i].second = read();
  sort(a + 1, a + 1 + n, greater<pair<long long, long long> >());
  check(78);
  long long l = 1, r = 1e13, ans;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  writeln(ans);
  return 0;
}
