#include <bits/stdc++.h>
using namespace std;
const int N = 51;
long long dp[N][N][N * 100];
pair<int, int> a[N];
void update(long long &first, long long second) {
  if (first == -1)
    first = second;
  else
    first = min(first, second);
}
long long sum[N], c[N];
bool cmp(pair<int, int> a, pair<int, int> b) {
  return 1LL * a.first * b.second < 1LL * a.second * b.first;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].first);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].second);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  int i = 1;
  int tot = 0;
  while (i <= n) {
    int j = i;
    while (j <= n && a[j].first == a[i].first) j++;
    sort(a + i, a + j, cmp);
    sum[i - 1] = c[i - 1] = 0;
    for (int k = i; k < j; k++) {
      sum[k] = sum[k - 1] + a[k].first;
      c[k] = c[k - 1] + a[k].second;
    }
    for (int k = 0; k < i; k++) {
      for (int r = 0; r <= tot; r++) {
        if (-1 == dp[i - 1][k][r]) continue;
        for (int p = 0; p <= min(k, j - i); p++) {
          int first = k - p + (j - i) - p;
          update(dp[j - 1][first][r + c[j - 1 - p]],
                 dp[i - 1][k][r] + sum[j - 1 - p]);
        }
      }
    }
    i = j;
    tot += c[j - 1];
  }
  long long a = -1, b = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= tot; j++)
      if (dp[n][i][j] == -1)
        continue;
      else {
        if (a == -1)
          a = dp[n][i][j], b = j;
        else if (a * j > b * dp[n][i][j])
          a = dp[n][i][j], b = j;
      }
  a *= 1000;
  if (a % b)
    cout << (a + b - 1) / b << endl;
  else
    cout << a / b << endl;
  return 0;
}
