/**
* author: tuncypasha
* file: b.cpp
* created: 05.02.2026 17:16
**/
#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
constexpr int N = 2e5 + 5, oo = 1e16;
void _() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
cin >> a[i];
vector<int> k(n + 1);
for (int i = 1; i <= n; ++i)
cin >> k[i];
vector<int> dp(n + 1, 1);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (__builtin_popcount(a[i] & a[j]) == k[i])
dp[i] = max(dp[i], dp[j] + 1);
}
}
int j = 0;
for (int i = 1; i <= n; ++i) {
if (dp[i] > dp[j])
j = i;
}
vector<int> ans;
ans.pb(j);
while (dp[j] > 1) {
for (int i = 1; i < j; ++i) {
if (dp[i] + 1 == dp[j]) {
j = i;
break;
}
}
ans.pb(j);
}
cout << ans.size() << '\n';
reverse(all(ans));
for (int &i : ans)
cout << i << ' ';
cout << '\n';
}
signed main() {
pasha
int t = 1;
// cin >> t;
for (int cs = 1; cs <= t; ++cs) {
_();
// cout << '\n';
}
}