#include <bits/stdc++.h>
using namespace std;
long long int p[2][(100 * 51)][51];
int i, j, n, m, sum;
pair<int, int> q[51];
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first > b.first;
}
void make() {
  int now = 0, last = 1, k, r, rr, prefix, suffix;
  long long int temp;
  p[now][0][0] = 1;
  i = 1;
  while (i <= n) {
    last = now;
    now = 1 - now;
    memset(p[now], 0, sizeof(p[now]));
    j = i;
    suffix = prefix = 0;
    while (j <= n && q[i].first == q[j].first) {
      suffix += q[j].second;
      j++;
    }
    for (k = i; k <= j; k++) {
      int a = k - i, b = j - k;
      for (r = 0; r <= sum; r++) {
        for (rr = 0; rr < i; rr++)
          if (rr >= a && p[last][r][rr]) {
            temp = p[last][r][rr] + (long long int)(q[i].first) * b;
            if (p[now][r + suffix - prefix][rr - a + b] == 0 ||
                p[now][r + suffix - prefix][rr - a + b] > temp) {
              p[now][r + suffix - prefix][rr - a + b] = temp;
            }
          }
      }
      prefix += q[k].second;
    }
    i = j;
  }
  long long int ans = 0;
  for (i = 1; i <= sum; i++) {
    for (j = 0; j <= n; j++)
      if (p[now][i][j]) {
        p[now][i][j]--;
        temp = p[now][i][j] * 1000 / i;
        if (p[now][i][j] * 1000 % i > 0) {
          temp++;
        }
        if (ans <= 0 || temp < ans) ans = temp;
      }
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &q[i].first);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &q[i].second);
    sum += q[i].second;
  }
  sort(&q[1], &q[1 + n], cmp);
  make();
  return 0;
}
