#include #include "testlib.h" using namespace std; long long k,n,cyc; bool jud(bitset<1024> a,bitset<1024> b){ if(cyc==1000000007){return false;} for(long long i=k;i<=(10+k)*k;i++){ if((a&b).any()){ a<<=1; a.set(0); } else{a<<=1;} a.reset(k); if(i==n){ if(a[0]){return true;} return false; } } long long cid=((10+k)*k); for(long long i=0;;i++){ if(cid%cyc==k%cyc){ if(a[i]){return true;} return false; } cid--; } } int main(int argc, char* argv[]){ registerValidation(argc, argv); k=inf.readLong(1ll,1000ll);inf.readSpace(); n=inf.readLong(0ll,1000000000000000000ll);inf.readEoln(); vector a=inf.readLongs(k,-1000000000000000000ll,1000000000000000000ll);inf.readEoln(); vector b=inf.readLongs(k,-1000000000000000000ll,1000000000000000000ll);inf.readEoln(); inf.readEof(); if(n ser; for(auto &nx : a){ser.push_back(nx);} for(auto &nx : b){ser.push_back(nx);} sort(ser.begin(),ser.end()); int st=0,fi=ser.size()-1,te; while(st<=fi){ te=(st+fi)/2; bitset<1024> ba,bb; for(int i=0;i=ser[te]){ba.set(i);} } cyc=1000000007; for(int i=0;i=ser[te]){ bb.set(i); cyc=min(i+1ll,cyc); } } if(jud(ba,bb)){st=te+1;}else{fi=te-1;} } cout << ser[fi] << '\n'; return 0; }