#include using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector VI; typedef pair PII; typedef double db; const int N = 4747; int n; string s[2]; // m -> 0, c->1; int cnt[2]; bool used[N]; vector ans; int find(string t) { FOR (i, 0, n) { if (!used[i] && s[0][i] == t[0] && s[1][i] == t[1]) return i; } return -1; } void solve() { FOR (i, 0, n) { if (s[0][i] != '-' && s[0][i] != s[1][i]) { int j = s[0][i] == 'M' ? 0 : 1; cnt[j]++; } } char c = '-'; while (cnt[0] + cnt[1] > 0) { if (c == 'M') { int x = find("MC"); if (x == -1) x = find("M-"); assert(x != -1); used[x] = 1; string res = "DRIVE "; res += to_string(x + 1); ans.PB(res); ans.PB("DROPOFF"); cnt[0]--; if (cnt[1] && s[1][x] == 'C') { ans.PB("PICKUP"); c = 'C'; } else c = '-'; } else if(c == 'C') { int x = find("CM"); if (x == -1) x = find("C-"); assert(x != -1); used[x] = 1; string res = "DRIVE "; res += to_string(x + 1); ans.PB(res); ans.PB("DROPOFF"); cnt[1]--; if (cnt[0] && s[1][x] == 'M') { ans.PB("PICKUP"); c = 'M'; } else c = '-'; } else { int x = find("MC"); int y = find("-M"); if (x != -1 && y != -1) { used[y] = 1; string res = "DRIVE "; res += to_string(y + 1); ans.PB(res); ans.PB("PICKUP"); c = 'M'; continue; } x = find("CM"); y = find("-C"); if (x != -1 && y != -1) { used[y] = 1; string res = "DRIVE "; res += to_string(y + 1); ans.PB(res); ans.PB("PICKUP"); c = 'C'; continue; } if (cnt[0]) { x = find("-M"); used[x] = 1; string res = "DRIVE "; res += to_string(x + 1); ans.PB(res); ans.PB("PICKUP"); c = 'M'; continue; } if (cnt[1]) { x = find("-C"); used[x] = 1; string res = "DRIVE "; res += to_string(x + 1); ans.PB(res); ans.PB("PICKUP"); c = 'C'; continue; } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; cin >> s[0] >> s[1]; solve(); cout << SZ(ans) << '\n'; for (auto a : ans) cout << a << '\n'; return 0; }