# Codeforces Round #499 (Div. 1)部分题解（B,C,D）

### B.Rocket

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=41;
int n,m,now,flag;bool vis[maxn];
int check(int x,int now){
int g;
if(vis[now])g=-g;return g;
}
int main(){
for(rg int i=1;i<=n;i++){
if(now==0)return 0;
else if(now==-1)vis[i]=1;
}
int l=1,r=m;now=1;
while(l<=r){
int mid=(l+r)>>1,f=check(mid,now);
if(!f)return 0;
if(f==-1)l=mid+1;else r=mid-1;
now++;if(now==n+1)now=1;
}
}


### C.Border

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e5+10;
int n,m,a[maxn],now;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int main(){
if(!now)return printf("%d\n%d\n",1,0),0;
printf("%d\n",m/now);
for(rg int i=0;i<m/now;i++)printf("%d ",i*now);
}


### D.Mars rover

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e6+10;
int n,m,f[maxn],ans,a[maxn],l[maxn][3];
char s[maxn][5];
bool vis[maxn];
void dfs(int x){
if(l[x][0]==1){
dfs(l[x][1]);
f[x]=!f[l[x][1]];
}
else if(l[x][0]==2){
dfs(l[x][1]),dfs(l[x][2]);
if(s[x][1]=='A')f[x]=f[l[x][1]]&f[l[x][2]];
if(s[x][1]=='O')f[x]=f[l[x][1]]|f[l[x][2]];
if(s[x][1]=='X')f[x]=f[l[x][1]]^f[l[x][2]];
}
}
void solve(int x,int now){
vis[x]=now;
if(l[x][0]==1)solve(l[x][1],now);
else if(l[x][0]==2){
if(s[x][1]=='A'){
int now1=(!f[l[x][1]])&f[l[x][2]],now2=(!f[l[x][2]])&f[l[x][1]];
if(now1!=f[x])solve(l[x][1],now);
else solve(l[x][1],0);
if(now2!=f[x])solve(l[x][2],now);
else solve(l[x][2],0);
}
if(s[x][1]=='O'){
int now1=(!f[l[x][1]])|f[l[x][2]],now2=(!f[l[x][2]])|f[l[x][1]];
if(now1!=f[x])solve(l[x][1],now);
else solve(l[x][1],0);
if(now2!=f[x])solve(l[x][2],now);
else solve(l[x][2],0);
}
if(s[x][1]=='X'){
int now1=(!f[l[x][1]])^f[l[x][2]],now2=(!f[l[x][2]])^f[l[x][1]];
if(now1!=f[x])solve(l[x][1],now);
else solve(l[x][1],0);
if(now2!=f[x])solve(l[x][2],now);
else solve(l[x][2],0);
}
}
}
int main(){
for(rg int i=1;i<=n;i++){
scanf("%s",s[i]+1);
if(s[i][1]=='A'||s[i][1]=='O'||s[i][1]=='X')