#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
ll pre[2000005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
//cin>>t;
while(t--)
{
ll n;
cin>>n;
ll a[n],b[n],i;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cin>>b[i];
}
for(i=0;i<2000000;i++)
{
pre[i]=__builtin_popcount(i);
}
ll dp[n],prev[n];
fill(dp,dp+n,1);
fill(prev,prev+n,-1);
for(i=1;i<n;i++)
{
ll j;
for(j=0;j<i;j++)
{
if(pre[a[i]&a[j]]==b[i]&&dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
prev[i]=j;
}
}
}
ll val=*max_element(dp,dp+n);
for(i=0;i<n;i++)
{
if(dp[i]==val)
{
break;
}
}
vector<ll>ans;
while(i!=-1)
{
ans.push_back(i+1);
i=prev[i];
}
reverse(ans.begin(),ans.end());
cout<<ans.size()<<endl;
for(i=0;i<ans.size();i++)
{
cout<<ans[i]<<" ";
}
cout<<endl;
}
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
// Author: tryharderforioi100
# | 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... |