#include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") int need[300]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s, t; cin >> s >> t; char have = '-'; int cur_pos = -1; vector sol; stringstream ss; while (true) { if (have == '-') { need['C'] = need['M'] = 0; for (int i = 0; i < n; ++i) { if (s[i] != '-' && s[i] != t[i]) { need[s[i]] = 1; } } if (!need['M'] && !need['C']) break; int where = -1; for (int i = 0; i < n; ++i) { if (s[i] == '-' && need[t[i]]) { where = i; break; } } if (where == -1) { break; } if (where != cur_pos) { cur_pos = where; ss << "DRIVE " << where + 1 << '\n'; } ss << "PICKUP" << '\n'; have = t[where]; t[where] = '-'; continue; } // Find a place to put him down int where = -1; for (int i = 0; i < n; ++i) { if (s[i] != t[i] && s[i] == have) { where = i; if (t[i] != '-') break; } } if (where == -1 && have != '-') { for (int i = 0; i < n; ++i) { if (s[i] == '-' && t[i] == '-') { where = i; } } } if (where != cur_pos) { cur_pos = where; ss << "DRIVE " << where + 1 << '\n'; } ss << "DROPOFF\n"; char aux = t[where]; t[where] = have; bool ok = false; need['C'] = need['M'] = 0; for (int i = 0; i < n; ++i) { if (s[i] != '-' && s[i] != t[i]) { need[s[i]] = 1; } } if (aux != '-' && need[aux]) { ss << "PICKUP\n"; have = aux; } else { have = '-'; } } string a; while (getline(ss, a)) { sol.emplace_back(a); } cout << sol.size() << '\n'; for (auto &x : sol) { cout << x << '\n'; } return 0; }