#include using namespace std; void print_ans(vector res, vector have, vector need) { int n = res.size(); for (int i = 0; i < n; ++i) { cout << "DRIVE " << res[i] + 1 << "\n"; if (need[res[i]]) { cout << "DROPOFF\n"; } if (have[res[i]]) { cout << "PICKUP\n"; } } } int main() { cin.tie(nullptr); cout.tie(nullptr); iostream::sync_with_stdio(false); int cnt[3][3]; // 0 n 1 m 2 c for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cnt[i][j] = 0; vector inds[3][3]; int n; cin >> n; string t; cin >> t; string s; cin >> s; vector have(n); vector need(n); for (int i = 0; i < n; ++i) { int id1; if (s[i] == '-') id1 = 0; if (s[i] == 'M') id1 = 1; if (s[i] == 'C') id1 = 2; have[i] = id1; int id2; if (t[i] == '-') id2 = 0; if (t[i] == 'M') id2 = 1; if (t[i] == 'C') id2 = 2; need[i] = id2; cnt[id1][id2]++; inds[id1][id2].push_back(i); } vector res; // -1 dropoff -2 pickup pair start = {0, 0}; while (cnt[2][1] + cnt[1][2] + cnt[0][1] + cnt[0][2] > 0) { bool dropoff = false; if (start == make_pair(2, 0)) { start = {2, 2}; res.push_back(-2); cnt[2][0]--; } else if (start == make_pair(1, 0)) { start = {1, 1}; res.push_back(-2); cnt[1][0]--; } else if (start == make_pair(2, 1)) { start = {2, 2}; res.push_back(-1); res.push_back(-2); cnt[2][1]--; } else if (start == make_pair(1, 2)) { start = {1, 1}; res.push_back(-1); res.push_back(-2); cnt[1][2]--; } else if (start == make_pair(0, 1)) { start = {0, 0}; res.push_back(-1); cnt[0][1]--; } else if (start == make_pair(0, 2)) { start = {0, 0}; res.push_back(-1); cnt[0][2]--; } else if (start == make_pair(1, 1)) { if (cnt[2][1]) start = {2, 1}; else if (cnt[0][1]) start = {0, 1}; else if (cnt[2][0]) start = {2, 0}, dropoff=true; else { assert(false); } } else if (start == make_pair(2, 2)) { if (cnt[1][2]) start = {1, 2}; else if (cnt[0][2]) start = {0, 2}; else if (cnt[1][0]) start = {1, 0}, dropoff=true; else { assert(false); } } else if (start == make_pair(0, 0)) { if (cnt[1][0]) { start = {1, 0}; } else if (cnt[2][0]) { start = { 2, 0 }; } else { assert(false); } } if (start.first != start.second) { res.push_back(inds[start.first][start.second].back()); inds[start.first][start.second].pop_back(); } if (dropoff) { res.push_back(-1); } } cout << res.size() << "\n"; for (int x: res) { if (x == -2) { cout << "PICKUP\n"; } else if (x == -1) { cout << "DROPOFF\n"; } else { cout << "DRIVE " << x + 1 << "\n"; } } }