#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  long long averagePower(vector<int>& power, vector<int>& processor) {
    int n = power.size();
    if (n == 0) {
      return 0;
    }
    vector<int> indices(n);
    iota(indices.begin(), indices.end(), 0);
    auto cmp = [&](int l, int r) { return power[l] > power[r]; };
    sort(indices.begin(), indices.end(), cmp);
    long long l = 1e9;
    long long r = 0;
    for (int i = 0; i < n; ++i) {
      l = min(l, (power[i] * 1000LL + processor[i] - 1) / processor[i]);
      r = max(r, (power[i] * 1000LL + processor[i] - 1) / processor[i]);
    }
    while (l < r) {
      long long m = l + (r - l) / 2;
      vector<long long> vals(n);
      for (int i = 0; i < n; ++i) {
        vals[i] = 1000LL * power[i] - m * processor[i];
      }
      auto cmp2 = [&](int l, int r) {
        return power[l] > power[r] ||
               (power[l] == power[r] && vals[l] > vals[r]);
      };
      sort(indices.begin(), indices.end(), cmp2);
      vector<vector<long long>> dp(n, vector<long long>(n + 1, LLONG_MAX));
      for (int i = 0; i < n; ++i) {
        int l = i;
        int r = l;
        long long sum = vals[indices[i]];
        while (r + 1 < n && power[indices[r]] == power[indices[r + 1]]) {
          ++r;
          sum += vals[indices[r]];
        }
        if (l - 1 < 0) {
          dp[r][r - l + 1] = sum;
        } else {
          for (int k = l; k <= r + 1; ++k) {
            for (int j = 0; j <= l; ++j) {
              if (dp[l - 1][j] == LLONG_MAX) {
                continue;
              }
              if (j - (l - j) >= (k - l)) {
                dp[r][j + (r + 1 - k)] =
                    min(dp[r][j + (r + 1 - k)], dp[l - 1][j] + sum);
              }
            }
            if (k <= r) {
              sum -= vals[indices[k]];
            }
          }
        }
      }
      long long minSum = LLONG_MAX;
      for (auto sum : dp[n - 1]) {
        minSum = min(minSum, sum);
      }
      if (minSum <= 0) {
        r = m;
      } else {
        l = m + 1;
      }
    }
    long long res = l;
    res += l - res > 0 ? 1 : 0;
    return res;
  }

 private:
  struct Task {
    Task(int i, int p, int n) : id(i), power(p), num(n) {}
    int id;
    int power;
    int num;
    bool operator<(const Task& other) const {
      if (1LL * power * other.num > 1LL * other.power * num) {
        return true;
      } else if (1LL * power * other.num == 1LL * other.power * num) {
        if (power < other.power) {
          return true;
        } else if (power == other.power) {
          return id < other.id;
        } else {
          return false;
        }
      } else {
        return false;
      }
    }
  };
};
int main(int argc, char** argv) {
  int n;
  scanf("%d", &n);
  vector<int> power(n);
  vector<int> processor(n);
  for (int i = 0, p = 0; i < n; ++i) {
    scanf("%d", &p);
    power[i] = p;
  }
  for (int i = 0, p = 0; i < n; ++i) {
    scanf("%d", &p);
    processor[i] = p;
  }
  Solution sol;
  printf("%llu\n", sol.averagePower(power, processor));
  return 0;
}
