#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long double pi = 3.141592653589793238462643383279;
const long double log23 = 1.58496250072115618145373894394781;
const long double eps = 1e-8;
const long long INF = 1e18 + 239;
const long long prost = 239;
const int two = 2;
const int th = 3;
const long long MOD = 1e9 + 7;
const long long MOD2 = MOD * MOD;
const int BIG = 2 * 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
template <typename T>
inline T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
long long power(long long a, int k) {
  if (k == 0) return 1;
  long long t = power(a, k >> 1);
  t = (t * t) % MOD;
  if (k & 1) t = (t * a) % MOD;
  return t;
}
mt19937 rnd(239);
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 60;
int n;
long long a[X], b[X], w[X];
bool used[X];
long long dp[X][X];
bool check() {
  vector<pair<long long, long long> > v;
  for (int i = 0; i < n; i++) v.push_back(make_pair(a[i], w[i]));
  sort(v.begin(), v.end());
  vector<vector<long long> > gr;
  vector<long long> now;
  now.push_back(v[0].second);
  for (int i = 1; i < n; i++) {
    if (v[i].first == v[i - 1].first) {
      now.push_back(v[i].second);
      continue;
    }
    gr.push_back(now);
    now.clear();
    now.push_back(v[i].second);
  }
  gr.push_back(now);
  int k = gr.size();
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = -INF;
  dp[k][0] = 0;
  for (int i = k - 1; i >= 0; i--) {
    for (int x = 0; x <= n; x++) {
      if (dp[i + 1][x] == -INF) continue;
      long long sum = 0;
      for (int l = 0; l < (int)gr[i].size(); l++) sum += gr[i][l];
      for (int l = 0; l <= min(x, (int)gr[i].size()); l++) {
        dp[i][x - l + (int)gr[i].size() - l] =
            max(dp[i][x - l + (int)gr[i].size() - l], dp[i + 1][x] + sum);
        if (l < gr[i].size()) sum -= gr[i][l];
      }
    }
  }
  long long ans = -INF;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[0][i]);
  return (ans >= 0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long h = 1160;
  for (int i = 0; i < n; i++) w[i] = h * b[i] - 1000LL * a[i];
  long long l = 0;
  long long r = (long long)(1e11) + 1;
  while (r - l > 1) {
    long long h = (l + r) >> 1;
    for (int i = 0; i < n; i++) w[i] = h * b[i] - 1000LL * a[i];
    if (check())
      r = h;
    else
      l = h;
  }
  cout << r;
  return 0;
}
