#include <bits/stdc++.h>
using namespace std;
static inline uint32_t rotl(uint32_t x,int r){return (x<<r)|(x>>(32-r));}
static inline uint32_t F(uint32_t x){return (rotl(x,1)&rotl(x,8))^rotl(x,2);} 
int main(int argc,char**argv){ if(argc<6){cerr<<"r L R TL TR [start step]\n";return 1;} int r=atoi(argv[1]); uint32_t L=strtoul(argv[2],0,0), R=strtoul(argv[3],0,0), TL=strtoul(argv[4],0,0), TR=strtoul(argv[5],0,0); uint64_t start=argc>6?strtoull(argv[6],0,0):0, step=argc>7?strtoull(argv[7],0,0):1; auto t0=chrono::steady_clock::now(); uint64_t cnt=0; for(uint64_t k=start;k<(1ull<<32);k+=step){uint32_t a=L,b=R,kk=(uint32_t)k; for(int i=0;i<r;i++){uint32_t n=F(a)^b^kk; b=a; a=n;} if(a==TL && b==TR){cout<<hex<<showbase<<kk<<"\n"; return 0;} if((++cnt & ((1u<<24)-1))==0){auto dt=chrono::duration<double>(chrono::steady_clock::now()-t0).count(); if(dt>30){cerr<<"timeout at "<<hex<<k<<dec<<" rate "<<cnt/dt/1e6<<"M/s\n"; return 2;}} } cerr<<"not found\n"; return 3;}
