#include using namespace std; int main(){ int n; cin >> n; vector cls(n); for (int i = 0; i < n; ++i) cin >> cls[i]; vector prf(n); for (int i = 0; i < n; ++i) cin >> prf[i]; int bad_cs_class = 0; int bad_math_class = 0; for (int i = 0; i < n; ++i){ if (cls[i] == 'M' && prf[i] != 'M') bad_math_class += 1; if (cls[i] == 'C' && prf[i] != 'C') bad_cs_class += 1; } //prof in a building with no class vector no_class; for (int i = 0; i < n; ++i){ if (prf[i] != '-' && cls[i] == '-') no_class.push_back(i); } //building with rev prof math /cs vector rev_math_prof, rev_cs_prof; for (int i = 0; i < n; ++i){ if (prf[i] == 'M' && cls[i] == 'C') rev_math_prof.push_back(i); if (prf[i] == 'C' && cls[i] == 'M') rev_cs_prof.push_back(i); } //building with no prof math / cs vector no_prof_math, no_prof_cs; for (int i = 0; i < n; ++i){ if (prf[i] != '-') continue; if (cls[i] == 'M') no_prof_math.push_back(i); if (cls[i] == 'C') no_prof_cs.push_back(i); } int ans = 0; for (int prof_ind : no_class){ int cont = prof_ind; //only if we need to take it. if (prf[cont] == 'C' && bad_cs_class == 0) continue; if (prf[cont] == 'M' && bad_math_class == 0) continue; ans++; while (cont != -1){ if (prf[cont] == 'C' && bad_cs_class == 0) break; if (prf[cont] == 'M' && bad_math_class == 0) break; ans++; if (prf[cont] == 'M'){ if (rev_cs_prof.size() != 0){ int nxt = rev_cs_prof[rev_cs_prof.size() - 1]; rev_cs_prof.pop_back(); ans += 2; bad_math_class--; cont = nxt; } else{ int nxt = no_prof_math[no_prof_math.size() - 1]; no_prof_math.pop_back(); ans += 2; bad_math_class--; cont = -1; } } else if (prf[cont] == 'C'){ if (rev_math_prof.size() != 0){ int nxt = rev_math_prof[rev_math_prof.size() - 1]; rev_math_prof.pop_back(); bad_cs_class--; ans += 2; cont = nxt; } else { int nxt = no_prof_cs[no_prof_cs.size() - 1]; no_prof_cs.pop_back(); bad_cs_class--; ans += 2; cont = -1; } } } } cout << ans << '\n'; //--------------------- bad_cs_class = 0; bad_math_class = 0; for (int i = 0; i < n; ++i){ if (cls[i] == 'M' && prf[i] != 'M') bad_math_class += 1; if (cls[i] == 'C' && prf[i] != 'C') bad_cs_class += 1; } //prof in a building with no class no_class.clear(); for (int i = 0; i < n; ++i){ if (prf[i] != '-' && cls[i] == '-') no_class.push_back(i); } //building with rev prof math /cs rev_math_prof.clear(), rev_cs_prof.clear(); for (int i = 0; i < n; ++i){ if (prf[i] == 'M' && cls[i] == 'C') rev_math_prof.push_back(i); if (prf[i] == 'C' && cls[i] == 'M') rev_cs_prof.push_back(i); } //building with no prof math / cs no_prof_math.clear(), no_prof_cs.clear(); for (int i = 0; i < n; ++i){ if (prf[i] != '-') continue; if (cls[i] == 'M') no_prof_math.push_back(i); if (cls[i] == 'C') no_prof_cs.push_back(i); } //---------------------- for (int prof_ind : no_class){ int cont = prof_ind; //only if we need to take it. if (prf[cont] == 'C' && bad_cs_class == 0) continue; if (prf[cont] == 'M' && bad_math_class == 0) continue; cout << "DRIVE " << prof_ind + 1 << "\n"; while (cont != -1){ if (prf[cont] == 'C' && bad_cs_class == 0) break; if (prf[cont] == 'M' && bad_math_class == 0) break; cout << "PICKUP" << "\n"; if (prf[cont] == 'M'){ if (rev_cs_prof.size() != 0){ int nxt = rev_cs_prof[rev_cs_prof.size() - 1]; rev_cs_prof.pop_back(); bad_math_class--; cout << "DRIVE " << nxt + 1 << "\n"; cout << "DROPOFF " << "\n"; cont = nxt; } else{ int nxt = no_prof_math[no_prof_math.size() - 1]; no_prof_math.pop_back(); bad_math_class--; cout << "DRIVE " << nxt + 1 << "\n"; cout << "DROPOFF " << "\n"; cont = -1; } } else if (prf[cont] == 'C'){ if (rev_math_prof.size() != 0){ int nxt = rev_math_prof[rev_math_prof.size() - 1]; rev_math_prof.pop_back(); cout << "DRIVE " << nxt + 1 << "\n"; cout << "DROPOFF " << "\n"; bad_cs_class--; cont = nxt; } else { int nxt = no_prof_cs[no_prof_cs.size() - 1]; no_prof_cs.pop_back(); cout << "DRIVE " << nxt + 1 << "\n"; cout << "DROPOFF " << "\n"; bad_cs_class--; cont = -1; } } } } }