#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, tot, sumb;
int a[50], b[50], h[50];
double d[50];
bool bz[50];
long long suma, ans;
void swap2(double &a, double &b) {
  double t = a;
  a = b, b = t;
}
void qsort(int l, int r) {
  int i = l, j = r, mid = a[(l + r) >> 1];
  while (i <= j) {
    while (a[i] > mid) i++;
    while (a[j] < mid) j--;
    if (i <= j) {
      swap(a[i], a[j]), swap(b[i], b[j]);
      i++, j--;
    }
  }
  if (l < j) qsort(l, j);
  if (i < r) qsort(i, r);
}
void put(double p, int x) {
  tot++, h[tot] = x, d[tot] = p;
  x = tot;
  int y = x >> 1;
  while (x > 1 && d[x] > d[y]) {
    swap2(d[x], d[y]), swap(h[x], h[y]);
    x = y, y = x >> 1;
  }
}
void get() {
  h[1] = h[tot], d[1] = d[tot], tot--;
  int x = 1, y = x * 2;
  while ((y <= tot && d[x] < d[y]) || (y < tot && d[x] < d[y + 1])) {
    if (y < tot && d[y] < d[y + 1]) y++;
    swap2(d[x], d[y]), swap(h[x], h[y]);
    x = y, y = x * 2;
  }
}
void put2(double p, int x) {
  tot++, h[tot] = x, d[tot] = p;
  x = tot;
  int y = x >> 1;
  while (x > 1 && d[x] < d[y]) {
    swap2(d[x], d[y]), swap(h[x], h[y]);
    x = y, y = x >> 1;
  }
}
void get2() {
  h[1] = h[tot], d[1] = d[tot], tot--;
  int x = 1, y = x * 2;
  while ((y <= tot && d[x] > d[y]) || (y < tot && d[x] > d[y + 1])) {
    if (y < tot && d[y] > d[y + 1]) y++;
    swap2(d[x], d[y]), swap(h[x], h[y]);
    x = y, y = x * 2;
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  qsort(1, n);
  for (i = 1; i <= n; i++) put(double(a[i]) / b[i], i);
  for (i = 1; i <= n; i++) {
    if (bz[i]) continue;
    suma += a[i], sumb += b[i];
    bz[h[1]] = 1, get();
    while (h[1] <= i) get();
  }
  tot = 0;
  for (i = 1; i <= n; i++)
    if (bz[i]) put2(double(a[i]) / b[i], i);
  while (tot) {
    if (d[1] < double(suma) / sumb) {
      suma += a[h[1]], sumb += b[h[1]], get2();
    } else
      break;
  }
  ans = round(double(suma) / sumb * 1000);
  printf("%I64d", ans);
}
