#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, a[100005], b[100005], l, r, req;
pll dp[1025][1025][10];
pll c[100005], cma;
vector<ll> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
iloop(0, n) cin >> a[i];
iloop(0, n) cin >> b[i];
memset(dp, -1, sizeof(dp));
iloop(0, n) {
c[i] = {1, -1};
l = a[i]&((1<<10)-1), r = a[i]>>10;
jloop(0, (1<<10)-1) {
req = b[i] - __builtin_popcount(l&j);
if (req < 0 || req >= 10) continue;
c[i] = max(c[i], {dp[j][r][req].first + 1, dp[j][r][req].second});
}
jloop(0, (1<<10)-1) {
req = __builtin_popcount(r&j);
dp[l][j][req] = max(dp[l][j][req], {c[i].first, i});
}
cma = max(cma, {c[i].first, i});
}
cout << cma.first << "\n";
v.push_back(cma.second);
while (c[cma.second].second != -1) {
cma.second = c[cma.second].second;
v.push_back(cma.second);
}
while (v.size()) {cout << v.back() + 1 << " "; v.pop_back();}
}