// Saarland University: <(OvO)> #include #define sz(a) ((int)(a).size()) #define divceil(a, b) ((a) + (b) - 1) / (b) using namespace std; #ifdef ONPC string to_string(const char* s) { return s; } template string to_string(const T& cont) { string ans = ""; for (bool fst = true; const auto& val: cont) { if (!fst) { ans += ", "; } ans += to_string(val); fst = false; } return ans + "}"; } void debug_print_collection() { cerr << endl; } template void debug_print_collection(First val, Args... args) { cerr << " " << to_string(val); debug_print_collection(args...); } #define debug(...) { cerr << "@@@ [" << #__VA_ARGS__ << "] ="; debug_print_collection(__VA_ARGS__);} #else #define debug(...) ; #define NDEBUG #endif mt19937 rnd(123); typedef long long ll; typedef long double ld; int solve() { int n; if (!(cin >> n)) { return 1; } vector>> a(3, vector>(3)); string A, B; cin >> A >> B; auto get_val = [&](char c) { if (c == '-') { return 0; } else if (c == 'M') { return 1; } else { return 2; } }; vector> tp(n); for (int i = 0; i < n; i++) { if (A[i] == B[i]) { continue; } a[get_val(A[i])][get_val(B[i])].push_back(i); tp[i] = make_pair(get_val(A[i]), get_val(B[i])); } vector > ans; for(int k = 1; k <= 2; k ++) { while(a[0][k].size()) { int cur = a[0][k].back(); a[0][k].pop_back(); int c = k; if(a[c][3-c].empty() && a[c][0].empty()) { continue; } ans.push_back({cur, 0, 1}); while(a[c][3 - c].size()) { int next = a[c][3-c].back(); a[c][3-c].pop_back(); int ispickup = 1; if(a[3-c][c].empty() && a[3-c][0].empty()) ispickup = 0; ans.push_back({next, 1, ispickup}); c = 3 - c; } if(a[c][0].size()) { int next = a[c][0].back(); a[c][0].pop_back(); ans.push_back({next, 1, 0}); } } } cout << ans.size() << '\n'; for(auto x : ans) { cout << "DRIVE " << x[0]+1 << '\n'; if(x[1]) cout << "DROPOFF\n"; if(x[2]) cout << "PICKUP\n"; } return 0; } int32_t main() { #ifdef ONPC assert(freopen("G.txt", "r", stdin)); #endif int TET = 1e9; // cin >> TET; for (int i = 1; i <= TET; i ++) { if (solve()) { break; } #ifdef ONPC cout << "__________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif } /* g++ -std=c++20 -Wall -Wextra -Wshadow -D_GLIBCXX_DEBUG -DONPC -O2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -o ex template.cpp && ./ex */