#include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string course, prof; cin >> course >> prof; vector > operations; vector solved(n); for (int i = 0; i < n; i++) solved[i] = (course[i] == prof[i]); string t = "CM"; int have_type = -1; while (true) { // try to dropoff somewhere, preferably with another prof if (have_type != -1) { int course_no_prof = -1, course_prof = -1; for (int i = 0; i < n; i++) { if (!solved[i] && course[i] == t[have_type]) { if (prof[i] != '-') course_prof = i; else course_no_prof = i; } } if (course_prof != -1) { operations.push_back({ "DRIVE", course_prof }); operations.push_back({ "DROPOFF", -1 }); operations.push_back({ "PICKUP", -1 }); solved[course_prof] = 1; have_type = 1 - have_type; continue; } if (course_no_prof != -1) { operations.push_back({ "DRIVE", course_no_prof }); operations.push_back({ "DROPOFF", -1 }); solved[course_no_prof] = 1; have_type = -1; continue; } } // don't have anyone, of who we have is useless. // we have to pickup some random prof and try to do something with him bool done_something = false; for (int i = 0; i < n; i++) { if (!solved[i] && course[i] == '-' && prof[i] != '-') { operations.push_back({ "DRIVE", i }); if (have_type != -1) { operations.push_back({ "DROPOFF", -1 }); have_type = -1; } operations.push_back({ "PICKUP", -1 }); have_type = (prof[i] == 'M'); solved[i] = 1; done_something = true; break; } } if (!done_something) break; } cout << operations.size() << '\n'; for (auto [s, nr] : operations) { cout << s; if (nr != -1) cout << " " << nr + 1; cout << '\n'; } }