#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; unsigned xor128() { static unsigned x=123456789,y=362436069,z=521288629,w=88675123; unsigned t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } class Data { public: char type; int pos, len; Data(char type, int pos, int len){ this->type = type; this->pos = pos; this->len = (len % 4 + 4) % 4; } }; void rotatePuzzle(vector& puzzle, Data& d) { if(d.type == 'R'){ string s(4, ' '); for(int i=0; i<4; ++i) s[i] = puzzle[i][d.pos]; for(int i=0; i<4; ++i) puzzle[(d.len+i)%4][d.pos] = s[i]; } else{ string& s = puzzle[d.pos]; rotate(s.begin(), s.begin() + 4 - d.len, s.end()); } } void moveCell(vector& puzzle, char c, int y, int x, vector& ans) { int y2, x2; for(int i=0; ; ++i){ y2 = i / 4; x2 = i % 4; if(puzzle[y2][x2] == c) break; } if(y == y2 && x == x2) return; if(x2 == x){ ans.push_back(Data('C', y2, 1)); rotatePuzzle(puzzle, ans.back()); x2 = (x2 + 1) % 4; } ans.push_back(Data('R', x, 3 - y)); rotatePuzzle(puzzle, ans.back()); if(y2 != 3){ ans.push_back(Data('R', x2, 3 - y2)); rotatePuzzle(puzzle, ans.back()); } ans.push_back(Data('C', 3, x - x2)); rotatePuzzle(puzzle, ans.back()); ans.push_back(Data('R', x, y - 3)); rotatePuzzle(puzzle, ans.back()); if(y2 != 3){ ans.push_back(Data('R', x2, y2 - 3)); rotatePuzzle(puzzle, ans.back()); } } bool solve(vector puzzle, vector& ans) { ans.clear(); for(int i=0; i<20; ++i){ int type = xor128() % 2 == 0 ? 'R' : 'C'; int pos = xor128() % 4; int len = xor128() % 4; ans.push_back(Data(type, pos, len)); rotatePuzzle(puzzle, ans.back()); } for(int i=0; i<12; ++i){ int y = i / 4; int x = i % 4; char c = 'A' + i; moveCell(puzzle, c, y, x, ans); } return puzzle[3] == "MNOP"; } int main() { vector puzzle(4); for(int i=0; i<4; ++i) cin >> puzzle[i]; vector ans; while(!solve(puzzle, ans)); cout << ans.size() << endl; for(const Data& d : ans) cout << d.type << ' ' << d.pos << ' ' << d.len << endl; return 0; }