bool cmp(pair<int, int> &a, pair<int, int> &b) {
if (a.first == b.first)
return a.second > b.second;
else
return a.first > b.first;
}
void helper(vector<pair<int, int>> x, int max_weight, int height, int &res, int idx, int max_l) {
res = max(res, height);
if (idx == x.size())
return;
if (x[idx].first < max_l && x[idx].second <= max_weight) {
if (max_weight - x[idx].second < x[idx].second * 7)
helper(x, max_weight - x[idx].second, height + 1, res, idx + 1, x[idx].first);
else
helper(x, x[idx].second * 7, height + 1, res, idx + 1, x[idx].first);
}
helper(x, max_weight, height, res, idx + 1, max_l);
}
int main() {
int n;
cin >> n;
vector<int> L(n), W(n);
for (int i = 0; i < n; i++)
cin >> L[i];
for (int i = 0; i < n; i++)
cin >> W[i];
vector<pair<int, int>> x;
for (int i = 0; i < n; i++)
x.push_back(make_pair(L[i], W[i]));
sort(x.begin(), x.end(), cmp);
int res = 0;
helper(x, INT_MAX, 0, res, 0, INT_MAX);
cout << res << endl;
system("pause");
return 0;
}