const main = (inputs) => {
  var N = inputs[0]-0;
  var arr = inputs[1].split(" ").map(v=>v-0);
  var ans = [];
  for(var i=N;i>0;i--){
    if(i*2<=N){
      if(arr[i-1] == 1){
        if(ans[i*2]%2 == 0){
          ans[i] = ans[i*2]+1;
        }else{
          ans[i] = ans[i*2];
        }
      }else{
        if(ans[i*2]%2 == 1){
          ans[i] = ans[i*2]+1;
        }else{
          ans[i] = ans[i*2];
        }
      }
    }else{
      if(arr[i-1] == 1){
        ans[i] = 1;
      }else{
        ans[i] = 0;
      }
    }
  }
  ans = ans.map((v, i, ar)=>{return ((ar[i*2]===undefined&&ar[i]>0)||ar[i*2]<ar[i])?1:0;}).map((v,i)=>v?i:0).filter(v=>v);
  console.log(ans.length);
  console.log(ans.join(" "));

}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
