#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1
const int N = 2e5 + 7;
const int TN = 4 * N;
const int oo = 1e18;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n, a[N], k[N], p[N], ans[N];
vi v;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> k[i];
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i - 1; j++) {
int s = __builtin_popcount((a[j] & a[i]));
if (s == k[i]) {
if (ans[j] + 1 >= ans[i]) {
p[i] = j;
ans[i] = ans[j] + 1;
}
}
}
}
int mx = 0, id = 0;
for (int i = 1; i <= n; i++) {
if (ans[i] >= mx) {
mx = ans[i];
id = i;
}
}
while (id) {
v.pb(id);
id = p[id];
}
cout << v.size() << '\n';
for (int i = v.size() - 1; i >= 0; i--) {
cout << v[i] << ' ';
}
return 0;
}