//GNC #include #include #include #include #include #include #include #include #include //#define DB() {cout<<"ph"<<__LINE__<<":" << endl;} #define DB() {} using namespace std; struct xy{ int x, y; xy(){} xy(int x, int y):x(x), y(y){} }; int SIZE; xy id(xy in) { return in; } xy rot(xy in) { return xy(in.y, SIZE-1-in.x); } xy rot_inv(xy in) { return xy(SIZE-1-in.y, in.x); } xy sym(xy in) { return xy(SIZE-1-in.x, in.y); } xy bhsym(xy in) { if(in.y < SIZE/2) return xy(in.x, in.y); else return xy(SIZE-1-in.x, in.y); } xy bvsym(xy in) { if(in.y < SIZE/2) return xy(in.x, in.y); else return xy(in.x, SIZE-1 - (in.y-SIZE/2)); } xy div(xy in) { if(in.y % 2) return xy(in.x, SIZE/2 + (in.y-1) / 2); else return xy(in.x, in.y / 2); } xy div_inv(xy in) { if(in.y < SIZE/2) return xy(in.x, in.y*2); else return xy(in.x, (in.y-SIZE/2)*2 + 1); } xy mix(xy in) { if(in.x < SIZE/2) return xy(in.x * 2 + in.y % 2, in.y-in.y%2); else return xy((in.x-SIZE/2) * 2 + in.y % 2, in.y-in.y%2+1); } xy mix_inv(xy in) { if(in.y % 2) return xy(SIZE/2 + in.x/2, in.x%2 + in.y - 1); else return xy(in.x/2, in.x%2 + in.y); } typedef xy(*converter)(xy); xy apply(vector &order, xy in) { for(int i = 0; i < order.size(); ++i){ in = (order[i])(in); } return in; } long long gcd(long long x, long long y) { if(y == 0) return x; return gcd(y, x%y); } long long lcm(long long x, long long y) { return x * y / gcd(x, y); } int main(void) { ifstream cin("pixel.in"); map dic; vector caller; dic["id"] = caller.size(); caller.push_back(id); dic["id-"] = caller.size(); caller.push_back(id); dic["rot"] = caller.size(); caller.push_back(rot); dic["rot-"] = caller.size(); caller.push_back(rot_inv); dic["sym"] = caller.size(); caller.push_back(sym); dic["sym-"] = caller.size(); caller.push_back(sym); dic["bhsym"] = caller.size(); caller.push_back(bhsym); dic["bhsym-"] = caller.size(); caller.push_back(bhsym); dic["bvsym"] = caller.size(); caller.push_back(bvsym); dic["bvsym-"] = caller.size(); caller.push_back(bvsym); dic["div"] = caller.size(); caller.push_back(div); dic["div-"] = caller.size(); caller.push_back(div_inv); dic["mix"] = caller.size(); caller.push_back(mix); dic["mix-"] = caller.size(); caller.push_back(mix_inv); int N; srand(time(NULL)); while(cin >> N && N){ SIZE = N; cin >> ws; string line; getline(cin, line); istringstream is(line); string cmd; vector orders; while(is >> cmd){ orders.push_back(caller[dic[cmd]]); } reverse(orders.begin(), orders.end()); long long term = 1LL; vector cand; cand.push_back(xy(0, 0)); cand.push_back(xy(0, N-1)); cand.push_back(xy(N-1, 0)); cand.push_back(xy(N-1, N-1)); cand.push_back(xy(N/2-1, N/2-1)); cand.push_back(xy(N/2-1, N/2)); cand.push_back(xy(N/2, N/2-1)); cand.push_back(xy(N/2, N/2)); DB(); for(int i = 0; i < 300; ++i){ cand.push_back(xy(rand()%N, rand()%N)); } for(int i = 0; i < cand.size(); ++i){ int step; xy cur = cand[i]; for(step = 1; ; ++step){ cur = apply(orders, cur); // cout << step << endl; // cout << "Position: " << cur.x << " " << cur.y<< endl ; if(cur.x == cand[i].x && cur.y == cand[i].y) break; } DB(); term = lcm(term, step); // cout << "DEBUG " << term; } cout << term << endl; } return 0; }