This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,a[100005],k[100005],dp[5001][5001],ans,ind,p,anss[5001],maybe=1,mx,in[100005];
vector<ll>v;
pair<ll,ll>x[300];
int main(){
	std::ios::sync_with_stdio(false);
	cin >> n;
	
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(a[i] > 256){
			maybe = 0;
		}
	}
	
	for(int i=1; i<=n; i++){
		cin >> k[i];
	}
	
	if(maybe){
		cout << 1/0;
		
		for(int i=1; i<=n; i++)in[i] = i;
		
		for(int i=1; i<=n; i++){
			mx = 0;
			ind = -1;
			for(int j=0; j<=256; j++){
				if(__builtin_popcount((j&a[i])) == k[i]){
					if(x[j].f > mx){
						mx = x[j].f;
						ind = x[j].s;
					}
				}
			}
			//cout << ind << endl;
			if(!x[a[i]].f)x[a[i]] = {1LL,(ll)i};
			if(ind == -1)continue;
			x[a[i]] = {mx+1LL,i};
			in[i] = ind;
		}
		mx = 0;
		for(int i=0; i<=256; i++){
			if(mx < x[i].f){
				mx = x[i].f;
				p = x[i].s;
			}
		}
		//cout << p << endl;
		cout << mx << endl;
		while(in[p] != p){
			v.pb(p);
			p = in[p];
		}
		
		v.pb(p);
	
		for(int i=(int)v.size()-1; i>=0; i--){
			cout << v[i] << " ";
		}
		
		return 0;
	}
	
	
	
	
	
	
	for(int i=1; i<=n; i++)dp[i][1] = i,anss[i]=1;
	ans = 1;
	ind = 1;
	for(int i=1; i<=n; i++){
		p = -1;
		mx = 0;
		for(int j = i-1; j>=1; j--){
			if(__builtin_popcount((a[j]&a[i])) == k[i]){
				if(mx < anss[j]){
					mx = anss[j];
					p = j;
				}
			}
		}
		if(p==-1)continue;
		for(int j=2; j<=n; j++){
			if(dp[p][j-1])dp[i][j] = p,anss[i] = j;
			if(dp[i][j] && j > ans){
				ans = j;
				ind = i;
			}
		}
	}
	
	cout << ans << endl;
	
	while(dp[ind][ans] != ind){
		v.pb(ind);
		ind = dp[ind][ans];
		ans--;
	}
	v.pb(ind);
	
	for(int i=(int)v.size()-1; i>=0; i--){
		cout << v[i] << " ";
	}
	
	
	
	return 0;
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:26:12: warning: division by zero [-Wdiv-by-zero]
   cout << 1/0;
           ~^~| # | 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... |