This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 10;
int n, a[N], k[N], go[N];
struct State{
  int end = 0, len = 0;
  State(){}
  State(int e, int l){end = e, len = l;}
};
State dp[1<<K][1<<K][K+2]; 
void solve(){
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i];
  for(int i = 1; i <= n; ++i) cin >> k[i];
  int last = 1, bst = 1;
  for(int i = 1; i <= n; ++i) go[i] = 0;
  for(int i = 1; i <= n; ++i){
    int l = a[i] >> 10, r = a[i] % 1024, lst = 0, best = 1;
    for(int j = 0; j < 1024; ++j){
      int x = k[i] - __builtin_popcount(l&j);
      if(x<0||x>10) continue;
      if(dp[j][r][x].len + 1 > best){
        best = dp[j][r][x].len + 1;
        lst = dp[j][r][x].end;
      }
    }
    go[i] = lst;
    if(bst < best)
      bst = best, last = i;
    for(int j = 0; j < 1024; ++j){
      int x = __builtin_popcount(r&j);
      if(dp[l][j][x].len < best){
        dp[l][j][x] = {i, best};
      }
    }
  }
  vector<int> ans;
  while(last != 0){
    ans.pb(last);
    last = go[last];
  }
  reverse(all(ans));
  cout << ans.size() << '\n';
  for(int v: ans) cout << v << ' ';
}
int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:60:14: warning: unused variable 'aa' [-Wunused-variable]
   60 |   int T = 1, aa;
      |              ^~| # | 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... |