#include using namespace std; using ll=long long; //#define int ll #define rep(i,a,b) for(int i=a;i<(b);i++) #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) using pii=pair; using vi=vector; #define fi first #define se second #define pb push_back int id(char c) { if(c == '-') return 0; if(c == 'C') return 1; if(c == 'M') return 2; assert(0); } signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n; cin >> n; string S, P; // if(local) { //// for(auto i : S) // } else { cin >> S >> P; // } array, 3> cnt; vector>> edges(3, vector>(3)); int s = -1; int wantM = count(all(S), 'M'); int wantC = count(all(S), 'C'); for(auto &i : P) { if(i == 'M') { if(wantM) wantM--; else i = '-'; } if(i == 'C') { if(wantC) wantC--; else i = '-'; } } for(auto &i : cnt) i.fill(0); for(int i = 0; i < n; i++) { int from = id(S[i]), to = id(P[i]); if(from != to) { cnt[from][to]++; edges[from][to].push_back(i); s = from; } } if(s == -1) { cout << "0\n"; return 0; } // array deg; deg.fill(0); // for(int i = 0; i < 3; i++) { // for(int j = 0; j < 3; j++) { // deg[i] += cnt[i][j]; // deg[i] -= cnt[j][i]; // } // } // int s = 0, t = 0; // for(int i = 0; i < 3; i++) { // if(deg[i] == 1) s = i; // if(deg[i] == -1) t = i; // } // for(int i = 0; i < 3; i++) { // if(i == s || i == t) continue; // if(deg[i]) { // //wtf // assert(0); // } // } // if(s != 0) { // //wtf // assert(0); // } vector> ops; auto get = [&](int u, int v) { cnt[u][v]--; int t = edges[u][v].back(); edges[u][v].pop_back(); return t; }; auto do_edge = [&](int x, int y) -> void { while(cnt[x][y] > 1 && cnt[y][x]) { ops.push_back({"DRIVE", get(x, y)}); if(x) ops.push_back({"DROPOFF", 0}); if(y) ops.push_back({"PICKUP", 0}); swap(x, y); ops.push_back({"DRIVE", get(x, y)}); if(x) ops.push_back({"DROPOFF", 0}); if(y) ops.push_back({"PICKUP", 0}); swap(x, y); } ops.push_back({"DRIVE", get(x, y)}); if(x) ops.push_back({"DROPOFF", 0}); if(y) ops.push_back({"PICKUP", 0}); }; auto cycle = [&](int a, int dir) -> bool { int x = a; int y = (x + dir + 3) % 3; int z = (y + dir + 3) % 3; if(cnt[x][y] && cnt[y][z] && cnt[z][x]) { do_edge(x, y); do_edge(y, z); do_edge(z, x); return true; } return false; }; while(cycle(s, 1)); while(cycle(s, 2)); for(int it = 0; it < 3; it++) { for(int i = 0; i < 3; i++) { if(cnt[s][i]) { do_edge(s, i); s = i; break; } } } for(auto &i : cnt) for(auto &j : i) assert(!j); cout << ops.size() << '\n'; for(auto [s, t] : ops) { cout << s; if(s == "DRIVE") { cout << " " << 1+t << '\n'; } else cout << '\n'; } }