#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > li;
long long dp[5001][51][50];
long long inf = 100000000000000000LL;
vector<pair<long long, long long> > groups[50];
long long go1(int remProcessors, int cover, int group) {
  if (remProcessors < 0 || cover < 0) {
    return inf;
  }
  if (group == -1) {
    if (remProcessors == 0) {
      return 0LL;
    }
    return inf;
  }
  if (dp[remProcessors][cover][group] != -1LL) {
    return dp[remProcessors][cover][group];
  }
  long long ret = inf;
  int tot = 0;
  int sz = groups[group].size();
  if (sz <= cover) {
    ret = min(ret, go1(remProcessors, cover - sz, group - 1));
  }
  for (int i = 0; i < sz; i++) {
    tot += (int)groups[group][i].first;
    if (cover - (sz - i - 1) < 0) {
      continue;
    }
    ret = min(
        ret, go1(remProcessors - tot, cover - (sz - i - 1) + i + 1, group - 1) +
                 (long long)(i + 1) * groups[group][i].second);
  }
  dp[remProcessors][cover][group] = ret;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long a1[n];
  long long b1[n];
  for (int i = 0; i < n; i++) {
    cin >> a1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b1[i];
  }
  for (int i = 0; i < n; i++) {
    long long a = a1[i];
    long long b = b1[i];
    a *= 1000LL;
    li.push_back(make_pair(a, b));
  }
  sort(li.begin(), li.end());
  int point = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0 && li[i].first == li[i - 1].first) {
      continue;
    }
    vector<pair<long long, long long> > now;
    for (int j = i; j < n && li[j].first == li[i].first; j++) {
      now.push_back(make_pair(-li[j].second, li[j].first));
    }
    sort(now.begin(), now.end());
    for (int j = 0; j < now.size(); j++) {
      now[j].first = -now[j].first;
    }
    groups[point++] = now;
  }
  long long ans = inf;
  for (int a = 0; a <= 5000; a++) {
    for (int b = 0; b <= 50; b++) {
      for (int c = 0; c < 50; c++) {
        dp[a][b][c] = -1LL;
      }
    }
  }
  for (int i = 1; i <= 5000; i++) {
    long long ret = go1(i, 0, point - 1);
    long long now = ret / (long long)i;
    if (ret % (long long)i != 0LL) {
      now++;
    }
    ans = min(ans, now);
  }
  cout << ans << endl;
}
