#include #include #include #include using namespace std; #define dec(c) {x=(c)%p;y=(c)/p;} #define enc(x,y) ((y)*p+(x)) int p; int id(int t){ return t; } int idi(int t){ return t; } int rot(int t){ int x,y;dec(t); return enc(y,p-1-x); } int roti(int t){ int x,y;dec(t); return enc(p-1-y,x); } int sym(int t){ int x,y;dec(t); return enc(p-1-x,y); } int symi(int t){ int x,y;dec(t); return enc(p-1-x,y); } int bhsym(int t){ int x,y;dec(t); return (y

>p,p!=0;){ cin.ignore(1024,'\n'); string str; getline(cin,str); //cout<<"*** "< fs; istringstream iss(str); for (string key;iss>>key;){ int inv=0; int tt=0; for(int i=key.length()-1;i>=0;i--){ if (key[i]=='-'){ inv^=1; } else{ tt=i; break; } } key=key.substr(0,tt+1); int fc=0; if (key=="rot") fc=0; else if (key=="sym") fc=1; else if (key=="bhsym") fc=2; else if (key=="bvsym") fc=3; else if (key=="div") fc=4; else if (key=="mix") fc=5; else if (key=="id") fc=6; else abort(); fc=fc*2+inv; fs.push_back(fc); } vector _map(p*p); for (int i=0;i=0;j--){ switch(fs[j]){ case 0: t=rot(t);break; case 1: t=roti(t);break; case 2: t=sym(t);break; case 3: t=symi(t);break; case 4: t=bhsym(t);break; case 5: t=bhsymi(t);break; case 6: t=bvsym(t);break; case 7: t=bvsymi(t);break; case 8: t=div(t);break; case 9: t=divi(t);break; case 10: t=mix(t);break; case 11: t=mixi(t);break; case 12: t=id(t);break; case 13: t=idi(t);break; } } assert(t pass(p*p,false); for (int i=0;i