#include <bits/stdc++.h>
#define Y8o "subsequence"
#define maxn (int) 1e5 + 5
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
//#define f first
//#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n;
int a[maxn], b[maxn];
int dp[maxn], pre[maxn];
vector<int> cur;
void solve() {
    cin >> n ;
    fi(i, 1, n) cin >> a[i];
    fi(i, 1, n) cin >> b[i];
    assert(n <= 5000);
    fi(i, 1, n) {
        dp[i] = 1, pre[i] = i;
        fi(j, 1, i - 1) if( __builtin_popcount(a[i] & a[j]) == b[i] ) {
            if(dp[i] < dp[j] + 1) {
                dp[i] = dp[j] + 1;
                pre[i] = j;
            }
        }
    }
    int vt = max_element(dp + 1, dp + n + 1) - dp;
    while(1) {
        cur.push_back(vt);
        if(vt == pre[vt]) break;
        vt = pre[vt];
    }
    reverse(all(cur));
    cout << cur.size() << '\n';
    for(int x : cur) cout << x << ' ';
}
int main() {
    iof();
    int nTest = 1;
//    cin >> nTest;
    while(nTest --) {
        solve();
    }
    ctime();
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'void iof()':
subsequence.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |